Video preview by using python tkinter.
Python code:
from tkinter import *
from PIL import ImageTk, Image
import cv2
root2=Tk()
root2.title('Video preview')
#Layout of display
topFrame =Frame(root2,width=100,height=100)
topFrame.grid(rowspan=2)
#topFrame
lmain = Label(topFrame,width=600,height=500)
lmain.grid()
cap=cv2.VideoCapture(0)
def 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()
root2.mainloop()