I have done real time face detection system, but I need to add gui for the program. Instead of using the solution from here. I does not want to read frame in a recursion way.
def show_frame():
_,frame = cap.read()
... #skip
lmain.after(10,show_frame)
It require a lot of refactoring in my previous code. So, I prefer read frame in a while loop way. But it does not work. Thanks for help.
import numpy as np
import cv2
import tkinter as tk
from PIL import Image, ImageTk
window = tk.Tk()
window.wm_title("Test")
imageFrame = tk.Frame(window, width=600, height=500)
imageFrame.grid(row=0, column=0, padx=10, pady=2)
#Capture video frames
lmain = tk.Label(imageFrame)
lmain.grid(row=0, column=0)
cap = cv2.VideoCapture(0)
def show_frame(frame):
frame = cv2.flip(frame, 1)
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(10, show_frame)
while True:
_,frame = cap.read()
show_frame(frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
window.mainloop()