cmakelist opencv
时间: 2023-08-01 19:13:59 浏览: 183
在CMakeList文件中使用find_package命令来查找OpenCV库时,需要根据不同的情况进行配置。如果需要使用opencv3,可以在CMakeList文件中添加以下配置内容:\[1\]
```
set(OpenCV_DIR /usr/local/share/OpenCV) # 设置opencv3的OpenCVConfig.cmake文件
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
message(STATUS "Opencv_include_Path: " ${OpenCV_INCLUDE_DIRS})
message(STATUS "Opencv_Library_Path: " ${Opencv_LIBRARIES})
```
如果需要使用ROS自带的OpenCV库,可以使用以下配置内容:\[2\]
```
set(OpenCV_DIR /usr/share/OpenCV) # 设置ROS自带的OpenCV路径
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
message(STATUS "Opencv_include_Path: " ${OpenCV_INCLUDE_DIRS})
message(STATUS "Opencv_Library_Path: " ${Opencv_LIBRARIES})
```
另外,在Ubuntu系统中可能会同时安装opencv3和opencv4的版本。如果需要使用opencv4,可以在CMakeList文件中添加以下配置内容:\[3\]
```
set(OpenCV_DIR /usr/lib/cmake/opencv4) # 设置opencv4的OpenCVConfig.cmake文件
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
message(STATUS "Opencv_include_Path: " ${OpenCV_INCLUDE_DIRS})
message(STATUS "Opencv_Library_Path: " ${Opencv_LIBRARIES})
```
以上配置内容可以根据实际情况进行调整,确保CMake能够正确找到并链接OpenCV库。
#### 引用[.reference_title]
- *1* *3* [CMakeLists中配置不同opencv版本的记录](https://blog.csdn.net/chrisspf/article/details/128640740)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [OpenCV3.4.10安装与CMakeLists编写](https://blog.csdn.net/boyhoodme/article/details/108472576)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文