我已尝试过很多在线帖子来安装opencv,但他们不适用于Ubuntu 16.04。请问有谁可以给我安装openCV 2.4.13的步骤吗?
答案 0 :(得分:19)
有一个我曾经做过的脚本,用于安装最新版本的OpenCV(3.2,截至本答复的最新更新) 这是它的链接
https://github.com/rsnk96/Ubuntu-Setup-Scripts/blob/master/opencvDirectInstall.sh
注意:对于Ubuntu 16.10+,您必须进行一些次要的依赖项更改。看看相同的评论。
由于您不想安装opencv contrib,并且您特别想要opencv 2.4.13,因此我修改了下面的脚本。我建议你在执行之前仔细阅读脚本并了解发生的事情
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install build-essential -y
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev -y
sudo apt-get install python3-numpy python3-pip python3-scipy python3-matplotlib python-dev python-matplotlib python-numpy python-scipy -y
sudo apt-get install python-pip python-tk libqt4-dev libqt4-opengl-dev libeigen3-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev default-jdk ant -y
echo "GUI and openGL extensions"
sudo apt-get install qt4-default libqt4-opengl-dev libvtk5-qt4-dev libgtk2.0-dev libgtkglext1 libgtkglext1-dev -y
echo "image manipulation libraries"
sudo apt-get install libpng3 pngtools libpng12-dev libpng12-0 libpng++-dev -y
sudo apt-get install libjpeg-dev libjpeg9 libjpeg9-dbg libjpeg-progs libtiff5-dev libtiff5 libtiffxx5 libtiff-tools libjasper-dev libjasper1 libjasper-runtime zlib1g zlib1g-dbg zlib1g-dev -y
echo "video manipulation libraries"
sudo apt-get install libavformat-dev libavutil-ffmpeg54 libavutil-dev libxine2-dev libxine2 libswscale-dev libswscale-ffmpeg3 libdc1394-22 libdc1394-22-dev libdc1394-utils -y
echo "codecs"
sudo apt-get install libavcodec-dev -y
sudo apt-get install libfaac-dev libmp3lame-dev -y
sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev -y
sudo apt-get install libtheora-dev libvorbis-dev libxvidcore-dev -y
sudo apt-get install ffmpeg x264 libx264-dev -y
sudo apt-get install libv4l-0 libv4l v4l-utils -y
echo "multiproccessing library"
sudo apt-get install libtbb-dev -y
echo "finally download and install opencv"
mkdir opencv
cd opencv
wget "https://github.com/Itseez/opencv/archive/2.4.13.zip"
unzip opencv-2.4.13.zip
cd opencv
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DINSTALL_C_EXAMPLES=ON \
-DINSTALL_PYTHON_EXAMPLES=ON \
-DBUILD_EXAMPLES=ON \
-DBUILD_opencv_cvv=OFF \
-DBUILD_NEW_PYTHON_SUPPORT=ON \
-DWITH_TBB=ON \
-DWITH_V4L=ON \
-DWITH_QT=ON \
-DWITH_OPENGL=ON \
-DWITH_VTK=ON ..
echo "making and installing"
make -j8
sudo make install
echo "finishing off installation"
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
echo "Congratulations! You have just installed OpenCV. And that's all, folks! :P"
P.S。创建一个脚本文件,然后只执行脚本文件,而不是将其逐行复制粘贴到终端中。您可以通过复制所有内容,将其放在扩展名为.sh
的文件中,然后使用$ ./filename.sh
答案 1 :(得分:15)
根据this source,来自Ubuntu 16.04,你现在可以这样做来为Python2.7安装OpenCV:
pip install opencv-python
或用于python3:
pip3 install opencv-python
有关详细信息,请参阅here。
我在我的机器上测试了这个,它很有用,很棒的东西:)。
这比我到目前为止遇到的所有其他方法容易得多。
答案 2 :(得分:1)
sudo apt-get install build-essential cmake git pkg-config sudo apt-get install libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev sudo apt-get install libgtk2.0-dev sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev sudo apt-get install libatlas-base-dev gfortran sudo apt-get install python2.7-dev sudo pip install numpy sudo apt-get install python-opencv
然后你可以尝试一下:
$ python Python 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import cv >>> import cv2
答案 3 :(得分:0)
如果您的计算机上安装了多个opencv,现在我告诉您在python中选择opencv版本的最直接,最有效,最简单的方法。
您可以键入以下命令以检查python中当前的opencv版本
import cv2
cv2.__version__
python中的
opencv路径是在系统变量PYTHONPATH
中设置的,您可以使用echo $PYTHONPATH
回显此变量。
如果我想在python中使用opencv3.x,然后使用vi或gedit在主文件夹中打开.bashrc
,请将此内容添加到最后
export PYTHONPATH=/home/ismart/ipa2/devel/lib/python2.7/dist-packages:/home/ismart/catkin_ws/install_isolated/lib/python2.7/dist-packages:/usr/local/opencv3.x/lib/python2.7/dist-packages
用您的路径替换