去官网下载opencv,版本选择opencv3.4.3,其他版本同理。
官网地址:链接: opencv官网.
下载选择Source就可以,没有必要选github下载,太慢了。
unzip opencv-3.4.3.zip
cd opencv-3.4.3
这一步真的会缺少非常多库,最好都提前安装好
sudo apt-get install cmake
sudo apt-get install build-essential
sudo apt-get install 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
mkdir build
cd build
cmake ..
cmake 过程会出现非常多的错误
问题1:
Unable to locate package libjasper-dev
解决方法:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
成功的解决了问题,其中libjasper1是libjasper-dev的依赖包
问题2:
No package ‘libavresample’ found
解决方法:
sudo apt-get install libavresample-dev
问题3:
IPPICV: Download failed: “Couldn’t connect to server”
即ippicv的 ippicv_2017u3_lnx_intel64_general_20180518.tgz 下载不下来
原因:由于有qiang,无法进入外网下载
解决方法:
打开opencv 3.4.3/build/CMakeDownloadLog.txt
找到ippicv_2017u3_lnx_intel64_general_20180518.tgz 所对应的下载链接,将这个链接保存下来。
选择一种你们懂得的方式,将这个文件下载下来。(没有这种方式的话,只能找别人的百度云了)
接着打开 /opencv-3.4.3/3rdparty/ippicv/ippicv.cmake 这个文件
将47行的
"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/"
改为
"file:home/xxx/xxx/"
这里的地址为下载下来的ippicv_2017u3_lnx_intel64_general_20180518.tgz的文件夹地址
特别需要注意的是file: 后面不要加/
特别需要注意的是file: 后面不要加/
特别需要注意的是file: 后面不要加/
问题4:
Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
– Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
– Could NOT find Atlas (missing: Atlas_CBLAS_INCLUDE_DIR Atlas_CLAPACK_INCLUDE_DIR Atlas_CBLAS_LIBRARY Atlas_BLAS_LIBRARY Atlas_LAPACK_LIBRARY)
– A library with BLAS API not found. Please specify library location.
– LAPACK requires BLAS
– A library with LAPACK API not found. Please specify library location.
– Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
– Could NOT find Matlab (missing: MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIRS MATLAB_ROOT_DIR MATLAB_LIBRARIES MATLAB_LIBRARY_DIRS MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN)
– VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
解决方法:
sudo apt-get install libopenblas-dev
问题5:
No package ‘gstreamer-base-1.0’ found
解决方法:
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
cmake ..
sudo make // 时间比较漫长
sudo make install
首先将OpenCV的库添加到路径,可以让系统找到
sudo gedit /etc/ld.so.conf.d/opencv.conf
在文件末尾添加
/usr/local/lib
执行如下命令使得刚才的配置路径生效:
sudo ldconfig
打开bashrc
sudo gedit /etc/bash.bashrc
在末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
保存后,重新运行配置
source /etc/bash.bashrc
更新
sudo updatedb
到此,所有配置结束。
找到 opencv-3.4.3/samples/cpp/example_cmake 目录下,官方已经给出了一个cmake的example,拿来测试。按顺序执行:
cmake .
make
./opencv_example
可看到打开了摄像头,在左上角有一个hello opencv ,即表示配置成功。