OpenCV卸载:首先要找到当初安装opencv的build目录,进入该build目录执行卸载操作
sudo make uninstall
cd ..
rm -r build
查询OpenCV版本:$ pkg-config --modversion opencv
pkg-config --cflags opencv
pkg-config --libs opencv
OpenCV安装:cd opencv-3.2.0/ -> mkdir build -> cd build -> cmake -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3.2.0 .. -> make -j8 ->sudo make install -j8
OpenCV多版本共存:sudo gedit ~/.bashrc 在文件末尾加上:
export PKG_CONFIG_PATH=/usr/local/opencv/3.1.0/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/opencv/3.1.0/lib
保存,source ~/.bashrc
如果只有一个版本的OpenCV,在CMakeList.txt中使用以下语句即可。
FIND_PACKAGE(OpenCV REQUIRED)
在OpenCV编译好后,所在目录中会生成OpenCVConfig.cmake文件,这个文件中指定了CMake要去哪里找OpenCV,其.h文件在哪里等。 存在多版本OpenCV时,需要找到所需版本对应的OpenCVConfig.cmake文件,并将其路径添加到工程的CMakeLists.txt中。示例如下:
set(OpenCV_DIR "/usr/local/opencv3.2.0/share/OpenCV")
find_package(OpenCV REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )