I am working on Yolo3-4-PY to implement it with tkinter.
I\'ve looked up everywhere but not able to resolve the issue.
When I run the program the canvas is d
when you place the image variable in the label , you must initiate the image variable to "image".
Eg: (CORRECT APPROACH)
photo = PhotoImage(file = "C://Users//Carl//Downloads//download.png")
label1 = Label(image = photo)
label1.pack()
Eg : (WRONG APPROACH)
photo = PhotoImage(file = "C://Users//Carl//Downloads//download.png")
label1 = Label(photo)
label1.pack()
in my case , correct with just simply add this line
root = tkinter.Tk()
complete code :
root = tkinter.Tk()
image = PIL.Image.open(r"C:\Users\Hamid\Desktop\asdasd\2.jpeg")
img = ImageTk.PhotoImage(image)
l = Label(image=img)
l.pack()
In the line imgtk = ImageTk.PhotoImage(image=cv2image)
, you are passing a numpy array (cv2image) as input to ImageTk.PhotoImage. But the source code of PIL.ImageTk mentions that it requires a PIL image.
This is what source code of PIL.ImageTk mentions for init() of PhotoImage.
class PhotoImage(object):
.....
:param image: Either a PIL image, or a mode string. If a mode string is
used, a size must also be given.
So basically, you will have to convert the numpy array to a PIL Image and then pass it to ImageTk.PhotoImage().
So, can you replace the line imgtk = ImageTk.PhotoImage(image=cv2image)
with imgtk = ImageTk.PhotoImage(image=PIL.Image.fromarray(cv2image))
?
This would convert the numpy array to a PIL Image and it would be passed into the method.
I extracted the code for converting a numpy array to PIL Image from this source.