当前位置:网站首页>Opencv3.2 and opencv2.4 installation

Opencv3.2 and opencv2.4 installation

2022-07-04 14:22:00 wu_ zhiyuan

OpenCV2 and 3 coexistence :

If 2 The default compilation installs , that 2 The location of the library should be /usr/local/lib , Again CMakeLists.txt in find_package, By default, the system will find /usr/local/share/OpenCVConfig.cmake
Download again 3 Source code , After decompressing

mkdir build
cd build 

Change the installation directory ( First in /usr/local I'm gonna go ahead and create a new folder opencv3)

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

compile :

make -j 
sudo make install

This way 3 Installed in the opencv3 The folder (bin lib share include)

In use , stay CMakelists.txt in , For use 3, stay find_package Front indicated path :

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

use 2 When :

find_package(OpenCV 2 REQUIRED)

If you want to use gdb debugging , Need to be in txt in :

SET(CMAKE_BUILD_TYPE "Debug")

However, this will slow down compilation

If you want to use C++11:

add_definitions(-std=c++11)

The simplest process :

cmake_minimum_required(VERSION 2.8)
project(XXX)
# Specify compiler :
SET(CMAKE_C_COMPILER g++)
# Find the bag you want to use :
find_package(OpenCV 3 REQUIRED) 
include_directories(
${
    PROJECT_SOURCE_DIR}
# Other header file paths 
)
# Create a library :
add_library(${
    PROJECT_NAME} SHARED
XXXXX.cpp
)
\# Link the library to the open source library 
target_link_libraries(${
    PROJECT_NAME}
${
    OpenCV_LIBS}
)
# Generate executable files , Link to the created library 
add_executable(main main.cpp)
target_link_libraries(main ${
    PROJECT_NAME})

eigen Use
First of all, it needs to be in the root directory

 mkdir cmake_modules

And in cmake_modules Put it in FindEigen3.cmake file
then :

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

Add :
opencv solve ippicv Download question , offline :ippicv_2019_lnx_intel64_general_20180723.tgz
https://blog.csdn.net/orDream/article/details/84311697
OpenCV must make install Install elsewhere , Otherwise, the relevant header file cannot be found , Also, you must specify the header file path , Otherwise I can't find it .

set(OpenCV_DIR /usr/local/opencv3/share/OpenCV)
# This kind of annotation is not good , Not recommended 
#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://yzsam.com/2022/185/202207041222496728.html