Python 3 OpenCV Tkinter Script to Render Flickering Video in Window Using FFMPEG Library GUI Desktop App
from tkinter import *from PIL import Image, ImageTkimport cv2import threading cap = cv2.VideoCapture(0) root = Tk()def videoLoop(): global root global cap vidLabel = Label(root, anchor=NW) vidLabel.pack(expand=YES, fill=BOTH) while True: ret, frame = cap.read() frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) frame = Image.fromarray(frame) frame = ImageTk.PhotoImage(frame) vidLabel.configure(image=frame) vidLabel.image = frame videoThread = threading.Thread(target=videoLoop, args=())videoThread.start()root.mainloop()
from tkinter import *from PIL import Image, ImageTkimport cv2import threading cap = cv2.VideoCapture(0) root = Tk()def videoLoop(): global root global cap vidLabel = Label(root, anchor=NW) vidLabel.pack(expand=YES, fill=BOTH) while True: ret, frame = cap.read() frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) frame = Image.fromarray(frame) vidLabel.image = ImageTk.PhotoImage(frame) vidLabel.configure(image=vidLabel.image) videoThread = threading.Thread(target=videoLoop, args=())videoThread.start()root.mainloop()