cv2_imread can not load JPEG

1,422 views
Skip to first unread message

Zhicheng Cui

unread,
Apr 28, 2016, 3:20:28 AM4/28/16
to OpenCV with Python Blueprints
When I use cv2.imread() function to read a jpeg file, it always return None value.
However, it can read .png file correctly.
So what should I do to let cv2.imread support jpg format.

Thanks.

Michael Beyeler

unread,
Apr 28, 2016, 11:54:40 AM4/28/16
to OpenCV with Python Blueprints
Hi Zhicheng,

You are correct:

>>> myJpg = cv2.imread('myfile.jpg')

is the right way to read a JPG file in OpenCV 2:

However, the link above says that on some Unix platforms, you need to have the correct libraries installed (such as libjpeg-dev). Is it possible that you're on Linux?
Check this guide for help (Step 4):

The line you want is:
$ sudo apt-get install libjpeg-dev libjpeg libjpeg-dbg libjpeg-progs

Best,
Michael
Reply all
Reply to author
Forward
0 new messages