Search code examples
pythonpython-3.xvideo-captureopencv

I'm trying to work on QR code scanner and I get this error: pixels, width, height = image TypeError: cannot unpack non-iterable NoneType object


I tried the same code few weeks ago and it worked perfectly but now I'm getting this error

pixels, width, height = image TypeError: cannot unpack non-iterable NoneType object

Screenshot of the error image

Edit: The issue has been resolved. The code was fine, problem was my in-built webcam. When I attached a new webcam, it worked fine.

Thank you so much for your help. This was my first question in stack


Solution

  • It most likely seems like your read() failed. You have to check if your read succeeded first and then proceed to iterate:

    while True:
        success, image = capture.read()
        if success:
             for eachcode in decode(image):
              ...
        else:
            print('Capture failed')
    

    If you still get the same error, you could as well check if decode() did not return None:

    while True:
        success, image = capture.read()
        decoded_image = decode(image)
        if success and decoded_image is not None:
             for eachcode in decoded_image:
              ...
        else:
            print('Capture failed')