Ali Ali - 1 year ago 94
Python Question

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 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
Answer Source

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

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.