下载opencv3.4.2和opencv_contrib3.4.2(下载tar.gz或是zip包):
地址:https://github.com/opencv/opencv/releases/tag
或者:使用git clone
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
#解压,到同一个文件中,比如opnecv/
unzip opencv-3.4.2.zip
unzip opencv_contrib-3.4.2.zip
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install ros-kinetic-geodesy
cd opencv-3.4.0
mkdir build
cd build
cmake
-D CMAKE_BUILD_TYPE=Release\
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH= ..
## 里面的 改成你自己解压的opencv_contrib的目录
make
sudo make install
######其他的一些参数#######
'''
-D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D WITH_CUDA=OFF
-D WITH_OPENMP=ON
-D WITH_QT=ON
'''
########解释##########
'''
CMAKE_INSTALL_PREFIX:
安装的python目录前缀,其实就是指定了python模块的安装路径。如下命令的输出即是该路径:
python -c "import sys; print(sys.prefix)"
PYTHON_EXCUTABLE:指定python的执行文件路径。如下命令的输出即是该路径
which python
'''
在cmake时,出现下载ippicv时间长,或是下载失败,
####
安装过程中下载 ippicv_2017u3_lnx_intel64_general_20170822.tgz 的时间很长,甚至下载失败。ippicv 是一个并行计算库,事实上可以不安装。如果想不安装只需在下面第四步骤中配置cmake时增加如下选项,关闭掉即可:
在cmake后面加上:
-D WITH_IPP=OFF \
此处,为防后续需要使用,仍选择安装。在csdn上搜索,有网友提供了下载文件。下载后,在文件ippicv_2017u3_lnx_intel64_general_20170822.tgz 所在目录创建一个脚本文件,内容如下,其中路径,需要根据你的实际情况修改。在 opencv-3.3.1/3rdparty/ippicv/下创建downloads文件夹。然后执行该脚本。
#!/bin/bash
ipp_file=./ippicv_2017u3_lnx_intel64_general_20170822.tgz &&
ipp_hash=$(md5sum $ipp_file | cut -d" " -f1) &&
ipp_dir=/home/XXX/Downloads/opencv-3.3.1/3rdparty/ippicv/downloads/linux-$ipp_hash && mkdir -p $ipp_dir &&
cp $ipp_file $ipp_dir
执行上述脚本,在opencv-3.3.1/3rdparty/ippicv/downloads/ 下将生成一个类似名称为 linux-4e0352ce96473837b1d671ce87f17359 的文件夹,其中的数字可能各不相同,不影响。该文件夹下是已经拷贝过来的ippicv_2017u3_lnx_intel64_general_20170822.tgz 文件
sudo ldconfig
sudo make uninstall
cd ..
sudo rm -r build
sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*
1、python -c "import cv2; print (cv2.__version__)"
输出:3.3.1
2、python
import cv2
一些问题:
在下面网站下载对应名称的ippicv文件
https://github.com/opencv/opencv_3rdparty/tree/ippicv/master_20170822/ippicv
保存路径随意,一般是自动放在默认的下载路径/home/user/下载
修改opencv里相关配置文件
打开终端,输入
gedit /home/user/opencv_source/opencv/3rdparty/ippicv/ippicv.cmake #记得user换成自己的用户名
将47行的
"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/"
改为从网站中下载下来的文件的本地路径:
"file:///home/user/下载/" #(根据自己的路径填写)
sudo apt-get install libproj-dev
以及下列问题
The imported target "vtkRenderingPythonTkWidgets" references the file
"/usr/lib/x86_64-linux-gnu/libvtkRenderingPythonTkWidgets.so"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/cmake/vtk-6.2/VTKTargets.cmake"
but not all the files it references.
-- The imported target "vtk" references the file
"/usr/bin/vtk"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/cmake/vtk-6.2/VTKTargets.cmake"
but not all the files it references.
解决办法:
sudo apt install python-vtk
解决办法:
cmake -DBLAS=open …
或者直接不管,比如下列问题,因为不需要用上java和matlab,所以就先不管它们
cmake could not find jin(missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH)
cmake could not find matlab
又比如在下载tiny-dnn的时候卡住,用不上神经网络的话可以不装,让它卡一会,等等就可以configure done了
再比如还有以下错误提示
file cannot create directory: /usr/local/include/opencv2. Maybe need
administrative privileges.
Makefile:148: recipe for target 'install' failed
make: *** [install] Error 1
解决办法:
千万要用sudo ,而不能只用make install,不然就报错
sudo make install
另外可能
modules/viz/CMakeFiles/opencv_test_viz.dir/build.make:233: recipe for target 'bin/opencv_test_viz' failed
make[2]: *** [bin/opencv_test_viz] Error 1
CMakeFiles/Makefile2:5627: recipe for target 'modules/viz/CMakeFiles/opencv_test_viz.dir/all' failed
make[1]: *** [modules/viz/CMakeFiles/opencv_test_viz.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs...
解决办法:
sudo apt-get autoremove libtiff5-dev
sudo apt-get install libtiff5-dev
更改文件夹和子文件夹权限
打开终端进入你需要修改的目录
然后执行下面这条命令
chmod 777 * -R