Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV NoneType object has no attribute shape

Hello I'm working on Raspberry Pi with OpenCV. I want to try a tutorial which is ball tracking in link http://www.pyimagesearch.com/2015/09/14/ball-tracking-with-opencv/

But when I compile it, i get an error: 'NoneType' object has no attribute 'shape'.

What should I do?

like image 936
user3748265 Avatar asked Oct 03 '16 14:10

user3748265


People also ask

How do I fix AttributeError NoneType object has no attribute shape?

The Python "AttributeError: 'NoneType' object has no attribute 'shape'" occurs when we access the shape attribute on a None value, e.g. after passing an incorrect path to cv2. imread() . To solve the error, make sure to specify the correct path.

Why does cv2 imread returns None?

imread. If you are receiving a NoneType error and your code is calling cv2. imread , then the likely cause of the error is an invalid file path supplied to cv2.


2 Answers

It means that somewhere a function which should return a image just returned None and therefore has no shape attribute. Try "print img" to check if your image is None or an actual numpy object.

like image 68
asc11 Avatar answered Oct 18 '22 02:10

asc11


I faced the same problem today, please check for the path of the image as mentioned by cybseccrypt. After imread, try printing the image and see. If you get a value, it means the file is open.

Code:

img_src = cv2.imread('/home/deepak/python-workout/box2.jpg',0)
print img_src

Hope this helps!

like image 36
Deepak V Avatar answered Oct 18 '22 03:10

Deepak V