I am trying to feed live video to the Tkinter window. I am using imutils.video for the Videostream. When I tried to run the code I am getting below-mentioned error. runfile('C:/Users/Ravi/Face_Detector/opencv_tkinter.py', wdir='C:/Users/Ravi/Face_Detector')
Traceback (most recent call last):
File "C:\Users\Ravi\opencv_tkinter.py", line 37, in <module>
show_frame() #Displayq
File "C:\Users\Ravi\opencv_tkinter.py", line 23, in show_frame
_, frame = cap.read()
ValueError: too many values to unpack (expected 2)
When I am using cap = cv2.VideoCapture(0), then everything works fine. What can be the difference between cap = cv2.VideoCapture(0) and cap = VideoStream(src=0).start()? In my other applications I am using cap = VideoStream(src=0).start(), that is why I need to stick with this. Can not afford to use cv2.VideoCapture. Any help is appriciated!
code:
import numpy as np
import cv2
import tkinter as tk
from PIL import Image, ImageTk
from imutils.video import VideoStream
import time
#Set up GUI
window = tk.Tk() #Makes main window
window.title("Test_1")
window.config(background="#FFFFFF")
#Graphics window
imageFrame = tk.Frame(window, width=600, height=600)
imageFrame.grid(row=2, column=0, padx=2, pady=2)
#Capture video frames
cap = VideoStream(src=0).start()
time.sleep(2.0)
def show_frame():
_, frame = cap.read()
frame = cv2.flip(frame, 1)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
frame = Image.fromarray(frame)
frame = ImageTk.PhotoImage(image=frame)
display.img = frame #Shows frame for display 1
display.configure(image=frame)
window.after(10, show_frame)
myLable1 = tk.Label(imageFrame, text = "Title_1", bg='blue', fg="white", font=("Helvetica", 16))
myLable1.grid(row= 1, column= 0)
display = tk.Label(imageFrame)
display.grid(row=2, column=0, padx=10, pady=2) #Display 1
show_frame() #Displayq
window.mainloop() #Starts GUI
I have tried with frame = cap.read() and it worked