import cv2
ram_frames=30
cam = cv2.VideoCapture(0)
def get_image():
cap = cam.read()
return cap
for i in xrange(ramp_frames):
temp = get_image()
image = get_image()
cv2.imwrite('bin/color.jpg',image)
The error i'm getting is :
File "C:\modules\imlib.py", line 1035, in __init__
self.imin = self.WinWebCam()
File "C:\modules\imlib.py", line 1125, in WinWebCam
cv2.imwrite('bin/color.jpg',image)
TypeError: img is not a numerical tuple
I have done everything right i didn't change anything the code which when executed in a seperate program it's not showing any error but when run inside my code it's showing error. The code i copied is from this link
You have changed the code while copying. Obviously, cam.read()
returns a tuple. From the documentation:
Python: cv2.VideoCapture.read([image]) → retval, image
You are returning the whole tuple of retval
and image
, while the example only returns the second part of it (the image). So your image
variable in line 9 contains the complete tuple that is returned by read()
while the example only returns the second part of it. imwrite
then fails because it does not expect a tuple as argument.
Try changing your code like this:
def get_image():
_, cap = cam.read()
return cap
or, even better,
def get_image():
return cam.read()[1]
Additionally, you have misspelled the variable ramp_frames
as ram_frames
in line 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With