Necromancer
Necromancer

Reputation: 919

Can't import OpenCV in python3.4.3

I searched how to predict my own digit image using Google TensorFlow.

I used 64bit Red Hat Linux.

I installed Python3.4.3, other related development environments and TensorFlow version 0.6.0.

Then, I tried to write code for digit prediction. Firstly, I need to read images in my python program. So, I searched how to read images in python then I found OpenCV (http://opencv.org/)

I installed OpenCV(version:3.1.0) using cmake. After installing OpenCV, I tried to import cv2(OpenCV function) in order to read image. But I cannot import cv2 and ImportError occured as the following.

ImportError: No module named 'cv2'

I tried to solve this problem by changing default PYTHONPATH.

For example:

export PYTHONPATH=/usr/local/python/lib/python3.4/site-packages:$PYTHONPATH

I tried to add some code in my python program.

import sys
sys.path.append('/usr/local/python/lib/python3.4')

But the above two steps cannot solve the problem ImportError: No module named 'cv2'. So, I search how to solve this problem and I tried to solve with many other ways. But no success.

How can I import cv2 in my python program?

OpenCV Installation steps are as follow:

>>> yum install cmake
** Download OpenCV latest version from it's official site **
>>> cd /directory of OpenCV/
>>> mkdir release
>>> cd release
>>> cmake -D CMAKE_BUILD_TYPE=RELEASE   -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
>>> make && make install
>>> echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf
>>> ldconfig  
>>> echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig" >> /etc/bash.bashrc
>>> echo "export PKG_CONFIG_PATH" >> /etc/bash.bashrc

Upvotes: 0

Views: 433

Answers (1)

mrry
mrry

Reputation: 126184

This doesn't directly answer your question—perhaps an OpenCV expert can help with that—but TensorFlow includes reasonably comprehensive support for manipulating images. If your images are in JPEG format you can use tf.image.decode_jpeg() to convert them to tensors; likewise tf.image.decode_png() supports PNG images.

Upvotes: 2

Related Questions