I'm trying display openCV image in Tkinter label. When I load image from file like:
img = ImageTk.PhotoImage("asd.png")
everythink works fine. But when I change it, I get only empty, black image, anythink else. This is example code:
import tkinter as tk
from tkinter import *
import cv2
from skimage import io
from PIL import Image, ImageTk
from skimage.color import rgb2gray
def make_label(master, x, y, w, h, img, *args, **kwargs):
f = Frame(master, height = h, width = w)
f.pack_propagate(0)
f.place(x = x, y = y)
label = Label(f, image = img, *args, **kwargs)
label.pack(fill = BOTH, expand = 1)
return label
if __name__ == '__main__':
root = tk.Tk()
frame = tk.Frame(root, width=400, height=600, background='white')
frame.pack_propagate(0)
frame.pack()
image = rgb2gray(io.imread("asd.png"))
image2 = Image.fromarray(image)
img = ImageTk.PhotoImage(image2)
make_label(root, 0, 0, 100, 100, img)
root.mainloop()
Please, help