红联Linux门户
Linux帮助

ubuntu同时使用OpenCV2.4.X和3.X终极解决办法

发布时间:2017-05-16 15:57:40来源:linux网站作者:heroacool
环境: ubuntu14.04
 
需求:在同一台电脑上,有的工程需要使用OpenCV2.4.X,有的工程需要使用OpenCV3.x.
 
解决办法:
1,下载OpenCV2.4.9,make install 路径为”~/Downloads/opencv2.4.9”
 
2,下载OpenCV3.0,make install 路径为”/usr/local”
 
3,需要使用OpenCV2.4.9的工程中,CMakeLists.txt如下:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(opencv-test)
#find_package(PkgConfig REQUIRED)
#pkg_check_modules(OpenCV REQUIRED opencv)
set(CMAKE_PREFIX_PATH "/home/fangli/Downloads/opencv2.4.9/")
find_package(OpenCV 2.4.9 EXACT REQUIRED)
#INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
#message(${OpenCV_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} main.cpp )
target_link_libraries(${PROJECT_NAME}  ${OpenCV_LIBS})
其中,请务必注意”set(CMAKE_PREFIX_PATH “/home/fangli/Downloads/opencv2.4.9/”)”.
 
4,使用OpenCV3.x时,因为OpenCV3.x安装到了系统目录/usr/local中,则默认找到package即为OpenCV3.0,CMakeLists.txt如下
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(opencv-test)
find_package(OpenCV REQUIRED)
add_executable(${PROJECT_NAME} main.cpp )
target_link_libraries(${PROJECT_NAME}  ${OpenCV_LIBS})
 
此方法非常好用,拿走不谢!
 
本文永久更新地址:http://www.linuxdiyf.com/linux/30823.html