While executing the below code i'm getting this 'TypeError: img is not a numerical tuple'

前端 未结 2 1411
隐瞒了意图╮
隐瞒了意图╮ 2020-12-11 09:30
    import cv2
    ram_frames=30
    cam = cv2.VideoCapture(0)
    def get_image():
          cap = cam.read()
          return cap
    for i in xrange(ramp_frames):         


        
相关标签:
2条回答
  • 2020-12-11 10:01

    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

    0 讨论(0)
  • 2020-12-11 10:07

    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.

    0 讨论(0)
提交回复
热议问题