Python, Opencv, Imutils: ValueError: too many values to unpack (expected 2)
Python, Opencv, Imutils: ValueError: too many values to unpack (expected 2)
我正在尝试将实时视频提供给 Tkinter window。我正在为视频流使用 imutils.video。当我尝试 运行 代码时,我遇到了下面提到的错误。
运行文件('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)
当我使用 cap = cv2.VideoCapture(0) 时,一切正常。有什么区别
cap = cv2.VideoCapture(0) 和 cap = VideoStream(src=0).start()?在我的其他应用程序中,我使用 cap = VideoStream(src=0).start(),这就是为什么我需要坚持这一点。用不起cv2.VideoCapture。任何帮助都适用!
代码:
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
我试过 frame = cap.read() 并且有效
我正在尝试将实时视频提供给 Tkinter window。我正在为视频流使用 imutils.video。当我尝试 运行 代码时,我遇到了下面提到的错误。 运行文件('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)
当我使用 cap = cv2.VideoCapture(0) 时,一切正常。有什么区别 cap = cv2.VideoCapture(0) 和 cap = VideoStream(src=0).start()?在我的其他应用程序中,我使用 cap = VideoStream(src=0).start(),这就是为什么我需要坚持这一点。用不起cv2.VideoCapture。任何帮助都适用!
代码:
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
我试过 frame = cap.read() 并且有效