I am trying to make a game where the user submits and image and then that image gets compared to a hard coded template. If the images are close enough then the user wins. I coded this segment about 3 months ago, and at that time it ran perfectly, however now it just refuses to run. I keep getting these two warnings:
Cannot find reference 'imread' in '__init__.py'
and
Cannot find reference 'TM_CCOEFF_NORMED' in '__init__.py'
here is my code:
from tkinter import *
from mainwin import level
import tkinter as tk
from PIL import Image, ImageTk
import cv2
from tkinter import filedialog
import numpy as np
template = "D:\Imagechecks\c12.png"
# ^ hardcoded in ^
root = tk.Tk()
# makes a window for the file selection
root.title("Image Selector")
# Open file dialog to select image
file_path = filedialog.askopenfilename()
# Open image using Pillow
image = Image.open(file_path)
# Start Tkinter event loop
img = cv2.imread(image)
# ^^the problem is pointing here
temp = cv2.imread(template)
# ^^here
resolution = cv2.matchTemplate(img, temp, cv2.TM_CCOEFF_NORMED)
# ^^ and here.
threshold = .6
loc = np.where(resolution >= threshold)
print(resolution)
if len(loc[0]) == 0:
labl_results = Label(root, text="LEVEL FAILED YOU LOOSER!").grid(row=12, column=0, columnspan=2)
print("fail")
labl_results = Label(root, text="CONGRANTS. YOU DONE IT! ").grid(row=12, column=0, columnspan=2)
print("pass")
root.mainloop()
when I tried to fix it, the code gave me a different error: TypeError: Can't convert object to 'str' for 'filename'
any help would be greately appreciated
I have tried:
- reinstalling pycharm
- reinstalling python 3.10.1
- making a new file and copy pasting the code
- re-installing all of the packages
- usign the black and white version of cv2
- running it on a friend's computer. none of these worked, and they all just gave the same answer: problem with imread and TM_CCOEFF...