I am getting error when printing the pixel value of the read image in python-opencv, TypeError: 'NoneType' object has no attribute '__getitem__'
Question: I have freshly installed opencv, and checked that its properly installed by
typing: pkg-config --modversion opencv at the command terminal.

I started using pything-opencv for reading and displaying an image, but when I
run my code, it throws an error: TypeError: 'NoneType' object has no attribute
'**getitem** '

My code is very minimal, but not getting where is there error.

The code which I am running is: import cv2 import numpy as np from matplotlib
import pyplot as plt import argparse

img = cv2.imread('messi5.jpg') print img  
print "end of file"

It gives the output: None end of file

When I write two more lines as this: px = img[100,100] print px

then it throws error: Traceback (most recent call last): File
"testing_opencv_python.py", line 23, in px = img[100,100] TypeError:
'NoneType' object has no attribute '**getitem** '

The same code runs perfectly on other systems.

I would be thankful if you can point out the mistake.

I basically want to install caffe, but when i did that i was getting error,
and seems like it depends on opencv, thats whey I have installed opencv.

Thanks and regards.


Answer: The returned image is `None` (you can see it when you print it), which is
causing the other error down the line.

This is most likely due to specifying the wrong image path ('messi5.jpg'). In
the the documentation
[here](http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_image_display/py_image_display.html),
it states:

> Warning Even if the image path is wrong, it won’t throw any error, but print
> img will give you None

Either provide a correct path to 'messi5.jpg', or copy the image into your
current directory (where you execute the python script).

