opencv4兼容opencv3
时间: 2023-12-12 22:34:25 浏览: 128
opencv4.0.0 opencv4.5.5 opencv3.4.0
OpenCV4和OpenCV3是可以共存的,但需要注意一些细节。以下是一些注意事项:
1.安装OpenCV4之前,需要先安装OpenCV3。
2.安装OpenCV4时,需要指定不同的安装路径,以避免覆盖OpenCV3。
3.在使用OpenCV4时,需要将OpenCV4的库路径添加到LD_LIBRARY_PATH环境变量中,以避免与OpenCV3的库路径冲突。
4.在使用OpenCV4时,需要将OpenCV4的头文件路径添加到INCLUDE_PATH环境变量中,以避免与OpenCV3的头文件路径冲突。
5.在使用CMake构建项目时,需要指定使用哪个版本的OpenCV。
下面是一些示例命令:
1.安装OpenCV3:
```shell
sudo apt-get install libopencv-dev
```
2.安装OpenCV4:
```shell
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv4 -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
make -j8
sudo make install
```
3.将OpenCV4的库路径添加到LD_LIBRARY_PATH环境变量中:
```shell
export LD_LIBRARY_PATH=/usr/local/opencv4/lib:$LD_LIBRARY_PATH
```
4.将OpenCV4的头文件路径添加到INCLUDE_PATH环境变量中:
```shell
export INCLUDE_PATH=/usr/local/opencv4/include:$INCLUDE_PATH
```
5.在CMake中指定使用OpenCV4:
```cmake
find_package(OpenCV 4 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
```
阅读全文