OpenCV---安装完后,环境配置的几种方法
OpenCV安装完后,环境配置的几种方法,系统是怎么优先顺序调用,还没太弄明白。
一、添加库路径(创建opencv.conf文件) 输入命令:sudo gedit /etc/ld.so.conf.d/opencv.conf 输入: /usr/local/lib (或者按安装OpenCV时路径设置,/usr/local/opencv3.4.2/lib) 并保存退出
二、添加环境变量 输入命令:sudo gedit /etc/profile 在末尾加入: export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH # pkgconfig 下的 opencv.pc文件所在的路径 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib #export PKG_CONFIG_PATH=/usr/local/opencv3.4.2/lib/pkgconfig #export LD_LIBRARY_PATH=/usr/local/opencv3.4.2/lib 更新环境变量:source /etc/profile
三、其它方式的设置1 输入命令:sudo gedit /etc/bash.bashrc 在末尾加入: export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig # pkgconfig 下的 opencv.pc文件所在的路径 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib #export PKG_CONFIG_PATH=/usr/local/opencv3.4.2/lib/pkgconfig #export LD_LIBRARY_PATH=/usr/local/opencv3.4.2/lib 更新环境变量:source /etc/bash.bashrc
四、其它方式的设置2
sudo gedit ~/.bashrc export PKG_CONFIG_PATH=/usr/local/opencv3.4.2/lib/pkgconfig:$PKG_CONFIG_PATH export LD_LIBRARY_PATH=/usr/local/opencv3.4.2/lib:$LD_LIBRARY_PATH
#opencv3.4.7 @20200117 export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opencv3.4.2/lib/pkgconfig # opencv 装在了 /usr/local/opencv3.4.2 路径下 #export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/opencv3.4.2/lib #export PKG_CONFIG_PATH=/usr/local/opencv3.4.2/lib/pkgconfig:$PKG_CONFIG_PATH #export LD_LIBRARY_PATH=/usr/local/opencv3.4.2/lib:$LD_LIBRARY_PATH source ~/.bashrc 五、更新系统库缓存 输入命令:sudo ldconfig
六、查看opencv是否安装成功 输入命令:pkg-config --cflags opencv pkg-config --libs opencv
( 看一下pkg-config设置的目录是否正确, 指令: pkg-config --cflags --libs opencv )
假定opencv的目录是/usr/loacal/include 和 /usr/local/lib, 则上条指令应该打印出:
-I/usr/local/Cellar/opencv3/3.1.0_1/include/opencv -I/usr/local/Cellar/opencv3/3.1.0_1/include -L/usr/local/Cellar/opencv3/3.1.0_1/lib -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core
如果发现不正确,可以修改/usr/local/lib/pkgconfig/opencv.pc文件,这个文件就是opencv的目录配置。
查看linux下的opencv安装版本:pkg-config opencv --modversion
七、测试
假设有个opencv_test.cpp文件实现显示图像功能, 输入命令:
g++ opencv_test.cpp `pkg-config --cflags --libs opencv` -o opencv_test
@ https://blog.csdn.net/zhe_csdn/article/details/95632827 ubuntu16.04 安装opencv3.4.0/3.4.6