Reputation: 545
I am relatively new to python and to openCV, I am trying to create a program that grabs input from my Macs' webcam and displays it in a window, and ultimately can process and edit these frames. Here is my code:
import cv2
import numpy as nmp
capture=cv2.VideoCapture(0)
while True:
frame = capture.read()
cv2.imshow("Webcam", frame)
if (cv2.waitKey(0)):
break
cv2.release()
cv2.destroyAllWindows()
my light near my webcam turns on but then the program stops with the following error
Traceback (most recent call last):
File "/Users/spinder/Desktop/WebCam.py", line 7, in <module>
cv2.imshow("Webcam", frame)
TypeError: mat is not a numerical tuple
there are similar questions in here but they do not fix my problem, any advice, fix or workaround would be greatly appreciated.
Upvotes: 0
Views: 2894
Reputation: 243947
According to the docs:
Python: cv2.VideoCapture.read([image]) → retval, image
This returns 2 values, the first indicates if the frame is obtained correctly and the second is the frame. So in your case the code should be as follows:
import cv2
import numpy as nmp
capture=cv2.VideoCapture(0)
while True:
res, frame = capture.read()
if res:
cv2.imshow("Webcam", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
capture.release()
cv2.destroyAllWindows()
Upvotes: 1