-1

我正在尝试将实时视频提供给 Tkinter 窗口。我正在将 imutils.video 用于视频流。当我尝试运行代码时,我收到了下面提到的错误。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)

当我使用 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
4

1 回答 1

0

我已经尝试使用 frame = cap.read() 并且它有效

于 2020-06-02T09:01:30.470 回答