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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With