当前位置:网站首页>opencv3.2 和opencv2.4安装

opencv3.2 和opencv2.4安装

2022-07-04 12:51:00 wu_zhiyuan

OpenCV2和3共存:

如果2默认编译安装了,那么2的库位置应该在/usr/local/lib ,再CMakeLists.txt中 find_package,系统默认会找/usr/local/share/OpenCVConfig.cmake
再下载3源码,解压后

mkdir build
cd build 

更改安装目录(先在/usr/local下新建文件夹opencv3)

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3 ..

编译:

make -j 
sudo make install

这样就把3安装在opencv3文件夹了(bin lib share include)

在使用的时候,在CMakelists.txt中,如要用3,在find_package前指明路径:

set(OpenCV_DIR /usr/local/opencv3/share/OpenCV)
find_package(OpenCV 3 REQUIRED)

用2的时候:

find_package(OpenCV 2 REQUIRED)

如果要用gdb调试,需要在txt中:

SET(CMAKE_BUILD_TYPE "Debug")

不过这样会减慢编译速度

如果要用C++11:

add_definitions(-std=c++11)

最简单的流程:

cmake_minimum_required(VERSION 2.8)
project(XXX)
#指定编译器:
SET(CMAKE_C_COMPILER g++)
#找到要用的包:
find_package(OpenCV 3 REQUIRED) 
include_directories(
${
    PROJECT_SOURCE_DIR}
#其他头文件路径
)
#创建库:
add_library(${
    PROJECT_NAME} SHARED
XXXXX.cpp
)
\#给库链接到开源库
target_link_libraries(${
    PROJECT_NAME}
${
    OpenCV_LIBS}
)
#生成可执行文件,链接到创建的库
add_executable(main main.cpp)
target_link_libraries(main ${
    PROJECT_NAME})

eigen的使用
首先需要在根目录

 mkdir cmake_modules

并在cmake_modules里放进 FindEigen3.cmake文件
然后:

set(CMAKE_MODULE_PATH ${
    PROJECT_SOURCE_DIR}/cmake_modules)
#或者 LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
find_package(Eigen3 REQUIRED)
include_directories(     ${
    EIGEN3_INCLUDE_DIR}   )

补充:
opencv 解决ippicv下载问题,离线:ippicv_2019_lnx_intel64_general_20180723.tgz
https://blog.csdn.net/orDream/article/details/84311697
OpenCV必须make install 安装到其他地方,不然相关头文件找不到,还有必须指定头文件路径,否则找不到。

set(OpenCV_DIR /usr/local/opencv3/share/OpenCV)
#注释的这种不好,不推荐
#set(OpenCV_DIR /home/guoxianzheng/opencv-3.4/build)
find_package(OpenCV 3 REQUIRED)
message(STATUS "This is opencvdir ${OpenCV_DIR}")
include_directories(
${
    OpenCV_DIR}
)
include_directories(/usr/local/opencv3/include)
原网站

版权声明
本文为[wu_zhiyuan]所创,转载请带上原文链接,感谢
https://blog.csdn.net/wu_zhiyuan/article/details/125595135