VideoCapture not working in Anaconda

I am using ubuntu 14.04 and installed anaconda python. I used conda install opencv and conda install cv2 to install opencv. However, I canโ€™t use VideoCapture at all (I need to process the frames of the video frame by frame). I need to use anaconda for the rest of the project.

Here is my code:

import cv2 import os capture = cv2.VideoCapture('/home/Downloads/data/zfH2XdRcH14.mp4') while not capture.isOpened(): print 'noob' while True: ret, frame = capture.read() cv2.imwrite('~/Downloads/data/pic.png',frame) cv2.imshow('Video', frame) count += 1 print count 

The code stores the noob print. I checked the location several times and that is correct. I have no idea what the problem is, and I'm stuck with this for hours.

+6
source share
6 answers
+4
source

I ran into the same problem. VideoCapture does not work with the default OpenCV version for Conda because ffmpeg is not enabled. For VideoCapture to work, you must enable ffmpeg in the Cmake GUI and compile. You can also install my version of OpenCV with ffmpeg enabled:

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

+3
source

ffmpeg is not in the standard cond channel.

You need to download opencv from the conda-forge channel, which contains the latest and additional packages and dependencies for video processing. Try the following:

 conda install -c conda-forge ffmpeg conda install -c conda-forge opencv 

Here, -c tells the channel to use as 'conda-forge'.

+2
source

I believe that I had the same problem. I installed it by adding the lib folder to PATH . For instance,

 export PATH="/home/iori/anaconda3/bin:$PATH" export PATH="/home/iori/anaconda3/lib:$PATH" 

My .bachrc now has a second line. The first line was added by the anaconda command, and the source activate command switches this bin folder, but I think it does not care about the lib folder, which I found annoying, because it means that opencv cannot find lib_opencv_*.so files there and course cv2.VideoCapture does not work.

The above example will fix the problem for conda env by default. For other envs, I still need to manually add the lib folder to PATH . So, I want to know how to configure the source activate command to do this automatically for me ...

0
source

I had the same problem, and after browsing the internet, I found a solution that worked. At a command prompt with administrator access:

 conda install conda-build conda install cmake conda config --add channels menpo 

Edit the following file:

C: \ Program Files \ Anaconda2 \ pkgs \ cmake-3.6.3-vc9_0 \ info \ recipe \ buil.sh

add the following flag:

-DWITH_FFMPEG = 1

For example, in my case:

 #!/bin/bash LDFLAGS=$LDFLAGS" -Wl,-rpath,$PREFIX/lib" \ ./bootstrap \ --verbose \ --prefix="${PREFIX}" \ --system-libs \ --no-qt-gui \ --no-system-libarchive \ --no-system-jsoncpp \ -- \ -DWITH_FFMPEG = 1 \ -DCMAKE_BUILD_TYPE:STRING=Release \ -DCMAKE_FIND_ROOT_PATH="${PREFIX}" make make install 

Finally:

 conda build /conda 

It worked with me.

On the other hand, I previously copied the opencv_ffmpegxyz.dll file from \ opencv \ build \ bin to \ Program Files \ Anaconda2 ; in my case opencv_ffmpe320_64.dll (64-bit), and I added a new environment variable called ffmpeg, indicating the path where the opencv_ffmpeg.dll files are located.

Sincerely.

0
source

Use conda-recipes to install ffmpeg.

git clone https://github.com/conda/conda-recipes.git

cd conda-recipes

conda build x264

conda build ffmpeg

See also here .

0
source

Source: https://habr.com/ru/post/984226/


All Articles