to show video streaming inside frame in tkinter to show video streaming inside frame in tkinter tkinter tkinter

to show video streaming inside frame in tkinter


To show video streaming inside frame in tkinter, I feel the easiest way is using PIL library....

from Tkinter import *from PIL import ImageTk, Imageimport cv2root = Tk()# Create a frameapp = Frame(root, bg="white")app.grid()# Create a label in the framelmain = Label(app)lmain.grid()# Capture from cameracap = cv2.VideoCapture(0)# function for video streamingdef video_stream():    _, frame = cap.read()    cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)    img = Image.fromarray(cv2image)    imgtk = ImageTk.PhotoImage(image=img)    lmain.imgtk = imgtk    lmain.configure(image=imgtk)    lmain.after(1, video_stream) video_stream()root.mainloop()

You can install PIL using pip -

pip install Pillow