检查opencv版本:
pkg-config --modversion opencv
前两天卸载了opencv3.0,想重装2.4版本。安装是没有问题,但现在查不到opencv版本,程序也编译不通过。
卸载过程:
找到当初安装 opencv3.0.0 的 build 目录,进入 build 目录 cd /home/***/opencv/build sudo make uninstall cd .. sudo rm -r build
然后清理 /usr 中所有 opencv 相关项 :
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* cd /usr find . -name "*opencv*" | xargs sudo rm -rf cd /home/*** chmod a+x /home/***/opencv rm -r /home/***/opencv
解决办法:
1. 在/usr/local/lib/pkgconfig下新建一个 opencv.pc 文件,内容如下:
prefix=/usr exec_prefix=${prefix} includedir=${prefix}/include libdir=${exec_prefix}/lib Name: opencv Description: The opencv library Version: 2.x.x Cflags: -I${includedir}/opencv -I${includedir}/opencv2 Libs: -L${libdir} -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -lopencv_core -lopencv_ml -lopencv_features2d -lopencv_objdetect -lopencv_flann -lopencv_video -lopencv_highgui
2. 打开.bashrc 文件
sudo geidit ~/.bashrc
在最后插入以下内容:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
最后更新一下:
source ~/.bashrc
现在可以检查一下opencv版本了。
另外,有的网友说可以定位到opencv.pc文件的位置,将此文件的位置添加到环境变量结果也是一样的,
定位opencv.pc:
locate opencv.pc
(由于本人未查到此文件位置,不给出后面的步骤)。
参考其他网友结果:
查看:locate opencv.pc /opt/opencv-3.0.0/build/lib/pkgconfig/opencv.pc /opt/opencv-3.0.0/unix-install/opencv.pc /usr/lib64/pkgconfig/opencv.pc 复制: sudo cp -f /opt/opencv-3.0.0/build/lib/pkgconfig/opencv.pc /usr/lib/pkgconfig/ --------------------- 作者:张大鹏的博客 来源:CSDN 原文:https://blog.csdn.net/philosophyatmath/article/details/46474211 版权声明:本文为博主原创文章,转载请附上博文链接!