opencv
一,安装opencv(pc)
1.去官网下载opencv
本教程选用的是opencv3.4.3。
下载链接http://opencv.org/releases.html,选择sources版本
2.将压缩包移动到你想安装的地方
开始解压
终端进入压缩包位置:
unzip opencv-3.4.3.zip
3.进入到解压后的文件包中
cd opencv-3.4.3
4.安装cmake工具:
sudo apt-get install cmake
sudo apt-get update
5.安装依赖库:
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev
6.创建编译目录(release)并进入:
mkdir release && cd release
7.cmake配置编译:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=OFF -D WITH_OPENGL=ON ..
问题:
1.Qt5Core编译错误
Qt5Core-CMake did not find one
解决方式:
sudo apt-get install qt5-default
注意: 还会出现很多缺少库,看打印的log ,自己去安装相应的库即可。
下面这些库可参考:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON …
sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip --fix-missing
sudo apt-get -y install libgstreamer-plugins-base1.0-dev
sudo apt-get -y install libgstreamer1.0-dev
sudo apt-get -y install libavresample-dev
sudo apt-get -y install libgphoto2-dev
8.make编译:
make -j4
这里可能遇到错误:
CMake Error: cmake_symlink_library: System Error: Read-only file system
CMake Error: cmake_symlink_library: System Error: Read-only file system
modules/core/CMakeFiles/opencv_core.dir/build.make:2337: recipe for target ‘lib/libopencv_core.so.3.4.3’ failed
make[2]: *** [lib/libopencv_core.so.3.4.3] Error 1
make[2]: *** Deleting file ‘lib/libopencv_core.so.3.4.3’
CMakeFiles/Makefile2:1785: recipe for target ‘modules/core/CMakeFiles/opencv_core.dir/all’ failed
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
Makefile:162: recipe for target ‘all’ failed
make: *** [all] Error 2
是因为你编译的时候在共享文件下编译的,删除release下文件,将文件放到ubuntu下(非共享),重新步骤7 再编译就不会报错了。
编译完成后出现:
[100%] Building CXX object apps/interactive-calibration/CMakeFiles/opencv_interactive-calibration.dir/parametersController.cpp.o
[100%] Building CXX object apps/interactive-calibration/CMakeFiles/opencv_interactive-calibration.dir/rotationConverters.cpp.o
[100%] Linking CXX executable …/…/bin/opencv_interactive-calibration
[100%] Built target opencv_interactive-calibration
Scanning dependencies of target opencv_version
[100%] Building CXX object apps/version/CMakeFiles/opencv_version.dir/opencv_version.cpp.o
[100%] Linking CXX executable …/…/bin/opencv_version
[100%] Built target opencv_version
9.安装:
sudo make install
…
– Installing: /usr/local/share/OpenCV/lbpcascades/lbpcascade_profileface.xml
– Installing: /usr/local/share/OpenCV/lbpcascades/lbpcascade_silverware.xml
– Installing: /usr/local/bin/opencv_traincascade
– Set runtime path of “/usr/local/bin/opencv_traincascade” to “/usr/local/lib”
– Installing: /usr/local/bin/opencv_createsamples
– Set runtime path of “/usr/local/bin/opencv_createsamples” to “/usr/local/lib”
– Installing: /usr/local/bin/opencv_annotation
– Set runtime path of “/usr/local/bin/opencv_annotation” to “/usr/local/lib”
– Installing: /usr/local/bin/opencv_visualisation
– Set runtime path of “/usr/local/bin/opencv_visualisation” to “/usr/local/lib”
– Installing: /usr/local/bin/opencv_interactive-calibration
– Set runtime path of “/usr/local/bin/opencv_interactive-calibration” to “/usr/local/lib”
– Installing: /usr/local/bin/opencv_version
– Set runtime path of “/usr/local/bin/opencv_version” to “/usr/local/lib”
…
10.环境配置添加库路径:
sudo /bin/bash -c ‘echo “/usr/local/lib” > /etc/ld.so.conf.d/opencv.conf’
11.更新系统库:
sudo ldconfig
12.配置bash:
sudo gedit /etc/bash.bashrc
13 在最末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
14 保存,执行如下命令使得配置生效
source /etc/bash.bashrc
15 更新
sudo updatedb
参考 https://blog.csdn.net/m0_46789476
查看是否安装成功:
1,
$ python3
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import cv2
>>> cv2.version
‘3.4.3’
>>>
2,
$ pkg-config --modversion opencv
$pkg-config opencv --libs
3,
$ pkg-config opencv --modversion
下一篇:介绍移植在IMX6 或Imx8 板子上