ubuntu---记录. opencv3.4.7
一、下载
https://github.com/opencv/opencv/archive/3.4.7.zip
wget -c https://github.com/opencv/opencv/archive/3.4.7.zip
wget -c https://github.com/opencv/opencv_contrib/archive/3.4.7.zip
*************************************
(3.1)创建build文件夹
mkdir build
cd build
(3.2)cmake一下
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3.4.7 -D OPENCV_EXTRA_MODULES_PATH=/home/u/opencv-3.4.7/opencv_contrib-3.4.7/modules -D WITH_GTK=OFF -D WITH_GTK_2_X=OFF ..
过程可能会...非常漫长.....注意:如果已经在新的文件夹中编译,但是还会出现之前的报错,把cmakecache.txt删了再编译就可不报错,继续。。。
****************完事,提示如下 *****************************
--
-- Install to: /usr/local/opencv3.4.7
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/u/opencv-3.4.7/wp-build
u@u160406:~/opencv-3.4.7/wp-build$
(3.3)make一下
sudo make
sudo make install #执行完毕后OpenCV编译过程就结束
编译过程非常漫长,特别是在最后97%的时候,'Built target opencv_perf_stitching'大约会停止15分钟,头一次我编译的时候以为中间出错了,一看cpu占用99%,于是就ctrl+c了,提示:一定要耐心,BE PATIENT!
-----------------完事,提示如下 --------------------------------
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
u@u160406:~/opencv-3.4.7/wp-build$ sudo make install
完事,提示如下:
-- Set runtime path of "/usr/local/opencv3.4.7/bin/opencv_visualisation" to "/usr/local/opencv3.4.7/lib"
-- Installing: /usr/local/opencv3.4.7/bin/opencv_interactive-calibration
-- Set runtime path of "/usr/local/opencv3.4.7/bin/opencv_interactive-calibration" to "/usr/local/opencv3.4.7/lib"
-- Installing: /usr/local/opencv3.4.7/bin/opencv_version
-- Set runtime path of "/usr/local/opencv3.4.7/bin/opencv_version" to "/usr/local/opencv3.4.7/lib"
(3.4)配置一些OpenCV的编译环境
第一步:系统环境
1.首先将OpenCV的库添加到路径,从而可以让系统找到:
sudo gedit /etc/ld.so.conf.d/opencv.conf
2.只需要在文件末尾添加:
/usr/local/lib
3.使得刚才的配置路径生效:
sudo ldconfig
第二步:配置bash
1.打开bash.bashrc
sudo gedit /etc/bash.bashrc # sudo gedit ~/.bashrc
2.在最末尾添加
#@多版本OpenCV切换 https://blog.csdn.net/learning_tortosie/article/details/80594399
#export PKG_CONFIG_PATH=/usr/local/opencv3.4.2/lib/pkgconfig
#export LD_LIBRARY_PATH=/usr/local/opencv3.4.2/lib
export PKG_CONFIG_PATH=/usr/local/opencv3.4.7/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/opencv3.4.7/lib
3.使配置生效
source /etc/bash.bashrc # source ~/.bashrc
(3.5)查询OpenCV版本
pkg-config --modversion opencv # 如果输出3.4.2,就表明配置成功。 如果前面没报错,输出不是3.4.2,可能是配置没生效,重启电脑
pkg-config opencv --modversion
-------------------------
卸载OpenCV
u@u160406:~/opencv-3.4.2/build$ sudo make uninstall
cd ..
sudo rm -r build
u@u160406:/usr/local$ sudo rm -r opencv3.4.2
《配置opencv3.4.2》 (3.1)创建build文件夹 mkdir build cd build (3.2)cmake一下 #cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. #cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=~/opencv-3.4.1/build/installed -DWITH_CUDA=OFF .. (建立opencv-3.4.1/build/installed这几个文件夹) cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3.4.2 .. cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3 \ -D INSTALL_C_EXAMPLES=OFF \ -D WITH_TBB=ON \ -D WITH_V4L=ON \ -D WITH_QT=ON \ -D WITH_GTK=ON \ -D WITH_OPENGL=ON \ -D BUILD_EXAMPLES=OFF .. I think it can be related with gtk, try whith: -D WITH_GTK=OFF -D WITH_GTK_2_X=OFF -D \ -D WITH_QT=ON \ -D OPENCV_EXTRA_MODULES_PATH=/home/u/opencv-3.4.2/opencv_contrib-3.4.2/modules #20191010 cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3.4.2 -D OPENCV_EXTRA_MODULES_PATH=/home/u/opencv-3.4.2/opencv_contrib-3.4.2/modules -D WITH_GTK=OFF -D WITH_GTK_2_X=OFF .. #20191011 cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3.4.2 -D OPENCV_EXTRA_MODULES_PATH=/home/u/opencv-3.4.2/opencv_contrib-3.4.2/modules -D WITH_GTK=ON -D WITH_GTK_2_X=ON .. 注意:如果已经在新的文件夹中编译,但是还会出现之前的报错,把cmakecache.txt删了再编译就可 不报错,继续。。。 (3.3)make一下 sudo make sudo make install #执行完毕后OpenCV编译过程就结束 编译过程非常漫长,特别是在最后97%的时候,'Built target opencv_perf_stitching'大约会停止15分钟,头一次我编译的时候以为中间出错了,一看cpu占用99%,于是就ctrl+c了,提示:一定要耐心,BE PATIENT! (3.4)配置一些OpenCV的编译环境 第一步:系统环境 1.首先将OpenCV的库添加到路径,从而可以让系统找到: sudo gedit /etc/ld.so.conf.d/opencv.conf 2.只需要在文件末尾添加: /usr/local/lib 3.使得刚才的配置路径生效: sudo ldconfig 第二步:配置bash 1.打开bash.bashrc sudo gedit /etc/bash.bashrc # sudo gedit ~/.bashrc 2.在最末尾添加 #@多版本OpenCV切换 https://blog.csdn.net/learning_tortosie/article/details/80594399 #export PKG_CONFIG_PATH=~/opencv-3.4.1/build/installed/lib/pkgconfig #export LD_LIBRARY_PATH=~/opencv-3.4.1/build/installed/lib export PKG_CONFIG_PATH=/usr/local/opencv3.4.2/lib/pkgconfig export LD_LIBRARY_PATH=/usr/local/opencv3.4.2/lib **************************** #opencv 3.x export PKG_CONFIG_PATH=/usr/local/opencv3.4.2/lib/pkgconfig export LD_LIBRARY_PATH=/usr/local/opencv3.4.2/lib #export PKG_CONFIG_PATH=/usr/local/opencv3.4.7/lib/pkgconfig #export LD_LIBRARY_PATH=/usr/local/opencv3.4.7/lib #opencv 4.x #export PKG_CONFIG_PATH=/usr/local/opencv4.1.1/lib/pkgconfig #export LD_LIBRARY_PATH=/usr/local/opencv4.1.1/lib ******************************** 3.使配置生效 source /etc/bash.bashrc # source ~/.bashrc (3.5)查询OpenCV版本 pkg-config --modversion opencv # 如果输出3.4.2,就表明配置成功。 如果前面没报错,输出不是3.4.2,可能是配置没生效,重启电脑 pkg-config opencv --modversion ------------------------- 卸载OpenCV u@u160406:~/opencv-3.4.2/build$ sudo make uninstall cd .. sudo rm -r build sudo rm -r /usr/local/opencv3.4.2/include/opencv2 /usr/local/opencv3.4.2/include/opencv /usr/local/opencv3.4.2/share/OpenCV /usr/local/opencv3.4.2/bin/opencv* /usr/local/opencv3.4.2/lib/libopencv* /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* u@u160406:/usr/local$ sudo rm -r opencv3.4.2