Ali Sharifi B.
Ali Sharifi B.

Reputation: 595

Is there any possible reason to have some difficulties with jpg files in opencv while using imread function to read them?

Recently, I use opencv in python.

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

sys.path.append('/path/to/cv.so')

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

import sys
import numpy as np
import os
sys.path.append("/usr/local/lib1/python2.7/site-packages")
import cv2
im1=cv2.imread('pic1.png')
print im1.shape
#output: (512, 512, 3)
im2=cv2.imread('pic1.jpg')
print im2.shape
#output:
-------------------------------------------------------------------------
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/libz.so (ver 1.2.8)
JPEG:                        /lib64/libjpeg.so (ver 80)
WEBP:                        /lib64/libwebp.so (ver encoder: 0x0202)
PNG:                         /lib64/libpng.so (ver 1.6.17)
TIFF:                        /lib64/libtiff.so (ver 42 - 4.0.2)
JPEG 2000:                   /lib64/libjasper.so (ver 1.900.1)

Any idea?

Upvotes: 2

Views: 370

Answers (1)

Ali Sharifi B.
Ali Sharifi B.

Reputation: 595

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

PYTHONPATH=""
export PYTHONPATH
PATH=/usr/bin:/usr/local/bin
export PATH

at the end of /home/.bashrc file (to make them permanent), before running python or ipython notebook from terminal.

Note: use only opencv-python.x86_64 (based on your machine architecture) from yum (dnf) repository (for fedora users of course!) and python 2.7.

DO NOT download opencv from its website. That makes some dependency troubles, I guess.

Upvotes: 1

Related Questions