20200909更新
因为装了ros Kinetic,因此有opencv 3 以上的版本。直接locate
locate opencv3
即可看到
/opt/ros/kinetic/share/opencv3
/opt/ros/kinetic/share/opencv3/package.xml
/usr/share/doc/ros-kinetic-opencv3
/usr/share/doc/ros-kinetic-opencv3/changelog.Debian.gz
/var/lib/dpkg/info/ros-kinetic-opencv3.list
/var/lib/dpkg/info/ros-kinetic-opencv3.md5sums
/var/lib/dpkg/info/ros-kinetic-opencv3.shlibs
/var/lib/dpkg/info/ros-kinetic-opencv3.triggers
但是直接把这些目录放在CMakeLists.txt中,还是不行。
set (Opencv_DIR /opt/ros/kinetic/share/opencv3)
find_package( OpenCV 3.1 REQUIRED )
因为cmake需要找到文件OpenCVConfig.cmake。再locate一次
locate OpenCVConfig.cmake
有
/opt/ros/kinetic/share/OpenCV-3.3.1-dev/OpenCVConfig.cmake
/usr/share/OpenCV/OpenCVConfig.cmake
可以准确知道目录为
set (OpenCV_DIR /opt/ros/kinetic/share/OpenCV-3.3.1-dev)
find_package( OpenCV 3.1 REQUIRED )
Solve multi-version conflict
prepare: make sure you know which version is in your machine:
pkg-config --modversion opencv
Note: If it don't work, try 'tab' before you type 'Enter'.
- Install OpenCV 2.4.9 by typing command line:
sudo apt-get install libopencv-dev
- Set path in your CMakeLists.txt before 'find_package(OpenCV 2.4.9 REQUIRED)'
set(OpenCV_DIR /usr/include/opencv2)
Note: According to your OpenCV location to modify it. If you don't know where it is, run the following commands in terminal. What was installed by command "apt-get install" usually is located in /usr/include/ .
sudo updatedb
locate OpenCVConfig.cmake