VideoCapture Does Not Work in Anaconda

后端 未结 7 883
谎友^
谎友^ 2020-12-09 12:58

I am using ubuntu 14.04, and have anaconda python installed. I used conda install opencv and conda install cv2 to install opencv. However I am unable to use the VideoCapture

相关标签:
7条回答
  • 2020-12-09 13:19

    The solution is to compile ffmpeg with opencv. For opencv3, refer to https://github.com/menpo/conda-opencv3

    For opencv2, refer to http://dhaneshr.net/2016/06/03/installing-opencv-2-4-x-with-ffmpeg-python-on-anaconda/

    0 讨论(0)
  • 2020-12-09 13:22

    I had the same problem and after look on the internet I found a solution that worked. In the command line 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

    addign the following flag:

    -DWITH_FFMPEG = 1

    For instance, 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 to me.

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

    Regards.

    0 讨论(0)
  • 2020-12-09 13:27

    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 讨论(0)
  • 2020-12-09 13:28

    ffmpeg is not present in default conda channel.

    You need to download opencv from conda-forge channel which contains 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 which channel to use. In our case we need 'conda-forge'.

    0 讨论(0)
  • 2020-12-09 13:38

    I ran into the same problem. VideoCapture doesn't work with Conda's default version of OpenCV because ffmpeg is not enabled. In order for VideoCapture to work, you have to enable ffmpeg in the Cmake GUI and compile. You can also install my version of OpenCV which has ffmpeg enabled:

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

    0 讨论(0)
  • 2020-12-09 13:40

    I believe I had the same problem. I fixed it by adding lib folder to the PATH. For example,

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

    My .bachrc now has this 2nd line. The first line is added by anaconda and source activate command switches this bin folder but I think it does not take care of lib folder which I found annoying because that means opencv cannot find the lib_opencv_*.so files in there and of course cv2.VideoCapture fails.

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

    0 讨论(0)
提交回复
热议问题