0

I'm trying to run my code using python 2.7, and OpenCV 3.3, but I`m running into the following error:

Traceback (most recent call last): File "CameraTest.py", line 52, in height = np.size(Frame,0) File "/usr/lib/python2.7/dist-packages/numpy/core/fromnumeric.py", line 2700, in size return asarray(a).shape[axis] IndexError: tuple index out of range

These are some of the code lines:

47 for i in range(0,20):
48    (grabbed, Frame) = camera.read(), 0
49
50 while True:
51  (grabbed, Frame) = camera.read(), 0
52  height = np.size(Frame,0)
53  width = np.size(Frame,1)
54  if not grabbed:
55      break
56
57  frame = camera.read()
58  frame = imutils.resize(frame, width=400)

Also read what the fromnumeric.py file had to say, and have no clue to what is my problem, I'm really lost in my Python here, been struggling with this error for some days now, and I couldn't find the answer by myself or searching. Can anyone help? Thanks in advance.

4
  • try print(Frame)? It seem you're assigning int 0 to Frame. Commented Feb 1, 2019 at 18:04
  • 1
    I may have got that very wrong, but I assingned 0 to frame because for i in range(0,20): (grabbed, Frame) = camera.read() without the 0 was giving too many values to unpack error, expected 2 Commented Feb 1, 2019 at 18:39
  • 1
    And the for loop is irrelevant to this error, in your first for loop you tried to assign whatever camera.read() is and 0 to grabbed and Framed for 20 times. Note that only the final time counts. And then in the while loop you're doing this again, except it fails after the first time since 0 does not have a shape. The for loops did not accomplish anything as you overwrote grabbed, Frame first thing in your while loop. Commented Feb 1, 2019 at 18:43
  • 2
    I'll look out for that Rocky, I need some more python experience, thanks for the advice. Commented Feb 1, 2019 at 18:56

1 Answer 1

0

You are always setting Frame to 0

(grabbed, Frame) = camera.read(), 0

grabbed gets output of camera.read() and Frame gets 0. For and int, np.size returns 1.

Sign up to request clarification or add additional context in comments.

9 Comments

Tried that right now, it gives out : height = np.size(Frame)[0] TypeError: 'int' object has no attribute 'getitem'
What does type(Frame) return? It sounds like it is an int and not np.array. Therefore, np.size returns 1.
Here is the full code, I suspect I made some many mistakes around it... pastebin.com/GuPHVnSq
You are always setting Frame to 0
Thing is, if I remove the 0 in (grabbed, Frame) = camera.read(), I get ValueError: too many values to unpack
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.