Ali Ali - 5 months ago 6x
Python Question

Is there any possible reason to have some difficulties with jpg files in opencv?

Recently, I use opencv in python.

As I noticed, when I want to import cv2 module in python, I need to add file path manually to the system paths using:


Howewer, when I want to read jpg files in the ipython notebooks, it fails:

import sys
import numpy as np
import os
import cv2
print im1.shape
#output: (512, 512, 3)
print im2.shape
AttributeError Traceback (most recent call last)
<ipython-input-8-2d36ac00eca0> in <module>()
----> 1 print im2.shape
AttributeError: 'NoneType' object has no attribute 'shape'

Based on my previous question, I rebuilt opencv several times.

I read somewhere that it might be the result of some dependency problems. But I have the both packages (libjpeg and libjaspe) on my system:

print cv2.getBuildInformation()

Media I/O:
ZLib: /lib64/ (ver 1.2.8)
JPEG: /lib64/ (ver 80)
WEBP: /lib64/ (ver encoder: 0x0202)
PNG: /lib64/ (ver 1.6.17)
TIFF: /lib64/ (ver 42 - 4.0.2)
JPEG 2000: /lib64/ (ver 1.900.1)

Any idea?

Ali Ali

After lots of efforts, I realized that the solution is to do:

export PATH

before running python or ipython notebook.

Note: use opencv 2.4 and python 2.7.

Now, I am going to enjoy the rest of the day. :-)