import cv2
ram_frames=30
cam = cv2.VideoCapture(0)
def get_image():
cap = cam.read()
return cap
for i in xrange(ramp_frames):
if np.any( initial == None): #your code It will definitely work for you. The error in this code because initial is treated as a numpy array.
I initialized initial with None in my program
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.