简体   繁体   English

在ubuntu上用anaconda安装openCV

[英]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. 我正在尝试使用带有anaconda(Python)的openCV库,我能够导入cv2包,但到目前为止还没有任何东西能够访问.mp4文件。 It's an issue with the ffmpeg thing which i have no idea about. 这是ffmpeg的问题,我不知道。 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 但是,如果有人能给我一个Linux脚本或教程,可以帮助我在python上使用openCV,以便能够用h264编码分析mp4视频,这将是伟大的

I believe I am well on my way to a solution, so I'm posting this to help others along. 我相信我正在寻找解决方案,所以我发布这个以帮助其他人。

Download conda-recipes . 下载conda-recipes Sitting in that directory, run conda build x264 and then conda build ffmpeg . 坐在该目录中,运行conda build x264 ,然后运行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. 因为我的系统是32位,所以我必须在conda-recipes/x264/build.shconda-recipes/ffmpeg/build.sh更改一行,然后才能成功运行conda build 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; 但是,opencv似乎没有使用FFmpeg; I still cannot open video files as I can outside of conda. 我仍然无法打开视频文件,因为我可以在conda之外。 I'll update if I ever get this working. 我会更新,如果我得到这个工作。

The default OpenCV package in conda does not have ffmpeg enabled. conda中的默认OpenCV包没有启用ffmpeg。 To solve this problem, I compiled OpenCV for Linux-64 with ffmpeg activated in CMake. 为了解决这个问题,我在Linux-64中编译了OpenCV,并在CMake中激活了ffmpeg。 I uploaded the package to my binstar channel, and you can install it using the following command: 我将包上传到我的binstar频道,您可以使用以下命令安装它:

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 . 我想我刚刚在https://github.com/menpo/conda-opencv3上使用menpo-opencv3在LinuxMint17(基本上是Ubuntu 14)上为python 3.5构建了opencv3.1.0。 This menpo package comes with opencv-contrib modules as well. 这个menpo包也附带opencv-contrib模块。 Amazing... 惊人...

First, make sure to source deactivate as building conda package needs to be done in the main conda env. 首先,确保source deactivate因为构建conda包需要在主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. 如说明所示,在默认设置中,FFMPEG被禁用。 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/ . 所以,我不得不编辑build.sh位于文件conda-opencv3/conda ,使-DWITH_FFMPEG=0-DWITH_FFMPEG=1前做conda build conda/

If conda build conda/ is successful, you will see something like this at the end. 如果conda build conda/成功,你会在最后看到这样的东西。

If you want to upload this package to anaconda.org later, type: 如果您想稍后将此包上传到anaconda.org,请键入:

$ anaconda upload /home/username/anaconda3/conda-bld/linux-64/opencv3-3.1.0-py35_0.tar.bz2 $ anaconda上传/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). 这是我们刚刚构建的conda包的路径(我认为)。

So, now we can activate the conda env we want to install this package (ex. cv2-env) 所以,现在我们可以激活我们要安装此软件包的conda env(例如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. 安装此软件包后,我可以使用cv2.VideoCapture来加载我在Windows 7中记录的一些avi文件。

(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.) (menpo甚至还有opencv v2.4 https://github.com/menpo/conda-opencv ,但我没试过。请注意2和3不能共存。)

+ 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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