简体   繁体   中英

Installing openCV with anaconda on ubuntu

I'm trying to use the openCV library with anaconda (Python) , i am able to import the cv2 package but nothing has been able to access a .mp4 file so far. It's an issue with the ffmpeg thing which i have no idea about. I cannot post code right now since I'm using my phone. But if anyone can give me a Linux script or a tutorial that can help me work with openCV on python to be able to analyze mp4 videos with h264 encoding , that would be great

I believe I am well on my way to a solution, so I'm posting this to help others along.

Download conda-recipes . Sitting in that directory, run conda build x264 and then conda build ffmpeg .

Because my system is 32-bit, I had to change one line each in conda-recipes/x264/build.sh and conda-recipes/ffmpeg/build.sh before I could run conda build successfully. I changed

export CFLAGS="-Wall -g -m64 -pipe -O2 -march=x86-64 -fPIC"

to

export CFLAGS="-Wall -g -m32 -pipe -O2 -march=x86-64 -fPIC"

I don't really understand what I'm doing, but I guessed that that would help, and now both builds run without errors.

However, opencv does not seem to be using FFmpeg; I still cannot open video files as I can outside of conda. I'll update if I ever get this working.

The default OpenCV package in conda does not have ffmpeg enabled. To solve this problem, I compiled OpenCV for Linux-64 with ffmpeg activated in CMake. I uploaded the package to my binstar channel, and you can install it using the following command:

conda install -c https://conda.binstar.org/jaimeivancervantes opencv

I think I just managed to build opencv3.1.0 for python 3.5 on LinuxMint17 (basically Ubuntu 14) using menpo-opencv3 at https://github.com/menpo/conda-opencv3 . This menpo package comes with opencv-contrib modules as well. Amazing...

First, make sure to source deactivate as building conda package needs to be done in the main conda env.

conda install conda-build
git clone https://github.com/menpo/conda-opencv3
cd conda-opencv3
conda config --add channels menpo
conda build conda/
conda install /PATH/TO/OPENCV3/PACKAGE.tar.gz

As the instructions says, in the default setting, FFMPEG is disabled. So, I had to edit build.sh file located in conda-opencv3/conda to make -DWITH_FFMPEG=0 to -DWITH_FFMPEG=1 before doing conda build conda/ .

If conda build conda/ is successful, you will see something like this at the end.

If you want to upload this package to anaconda.org later, type:

$ anaconda upload /home/username/anaconda3/conda-bld/linux-64/opencv3-3.1.0-py35_0.tar.bz2

This is the path to the conda package we just built (I think).

So, now we can activate the conda env we want to install this package (ex. cv2-env)

source activate cv2-env

then

conda install /home/username/anaconda3/conda-bld/linux-64/opencv3-3.1.0-py35_0.tar.bz2

With this package installed, I could use cv2.VideoCapture to load some avi file I recorded in Windows 7.

(menpo even has opencv v2.4 https://github.com/menpo/conda-opencv as well but I had not tried. And note that 2 and 3 cannot co-exist.)

+ curl -L https://raw.githubusercontent.com/Itseez/opencv_3rdparty/81a676001ca8075ada498583e4166079e5744668/ippicv/ippicv_linux_20151201.tgz -o /home/vasu/anaconda2/conda-bld/work/opencv-3.1.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/ippicv_linux_20151201.tgz
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current  Dload  Upload   Total   Spent    Left  Speed
0     0    0     0    0     0      0      0 --:--:--  0:00:05 --:--:--  0curl: (77) error setting certificate verify locations:
 CAfile: /etc/pki/tls/certs/ca-bundle.crt
 CApath: none
 Command failed: /bin/bash -x -e /home/vasu/anaconda2/conda-bld/work/opencv-3.1.0/conda_build.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM