CMakeLists opencv配置

*****************************************************************************************************
***********************************************************方法一************************************
*****************************************************************************************************
cmake_minimum_required(VERSION 3.8)
project(opencv_test)

set(CMAKE_CXX_STANDARD 11)#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

add_executable(opencv_test main.cpp)#set(SOURCE_FILES main.cpp);add_executable(opencv_test ${SOURCE_FILES})


# add libs you need

#set(OpenCV_INCLUDE_DIRS
#        /usr/local/opencv2/include
#        /usr/local/opencv2/include/opencv
#        /usr/local/opencv2/include/opencv)
#include_directories(${OpenCV_INCLUDE_DIRS})

#直接法:包含目录
include_directories(/usr/local/opencv2/include)
include_directories(/usr/local/opencv2/include/opencv)
include_directories(/usr/local/opencv2/include/opencv)

#find_package(OpenCV REQUIRED)#新版本用OpenCVConfig.cmake(config mode)或者FindOpenCV.cmake(module mode)
#set(OpenCV_LIBS
#       opencv_core
#       opencv_imgproc
#        opencv_highgui
#       opencv_imgcodecs)
set(OpenCV_LIBS
        /usr/local/opencv2/lib/libopencv_gpu.so.2.4
        /usr/local/opencv2/lib/libopencv_ml.so
        /usr/local/opencv2/lib/libopencv_calib3d.so.2.4
        /usr/local/opencv2/lib/libopencv_legacy.so.2.4
        /usr/local/opencv2/lib/libopencv_gpu.so.2.4.13
        /usr/local/opencv2/lib/libopencv_objdetect.so.2.4
        /usr/local/opencv2/lib/libopencv_superres.so
        /usr/local/opencv2/lib/libopencv_objdetect.so
        /usr/local/opencv2/lib/libopencv_videostab.so.2.4
        /usr/local/opencv2/lib/libopencv_core.so.2.4
        /usr/local/opencv2/lib/libopencv_flann.so
        /usr/local/opencv2/lib/libopencv_photo.so.2.4
        /usr/local/opencv2/lib/libopencv_contrib.so.2.4.13
        /usr/local/opencv2/lib/libopencv_nonfree.so
        /usr/local/opencv2/lib/libopencv_imgproc.so
        /usr/local/opencv2/lib/libopencv_contrib.so.2.4
        /usr/local/opencv2/lib/libopencv_flann.so.2.4
        /usr/local/opencv2/lib/libopencv_superres.so.2.4.13
        /usr/local/opencv2/lib/python2.7/site-packages/cv2.so
        /usr/local/opencv2/lib/libopencv_ml.so.2.4
        /usr/local/opencv2/lib/libopencv_stitching.so.2.4
        /usr/local/opencv2/lib/libopencv_legacy.so
        /usr/local/opencv2/lib/libopencv_legacy.so.2.4.13
        /usr/local/opencv2/lib/libopencv_objdetect.so.2.4.13
        /usr/local/opencv2/lib/libopencv_ocl.so
        /usr/local/opencv2/lib/libopencv_ocl.so.2.4
        /usr/local/opencv2/lib/libopencv_nonfree.so.2.4
        /usr/local/opencv2/lib/libopencv_ml.so.2.4.13
        /usr/local/opencv2/lib/libopencv_calib3d.so.2.4.13
        /usr/local/opencv2/lib/libopencv_features2d.so
        /usr/local/opencv2/lib/libopencv_core.so
        /usr/local/opencv2/lib/libopencv_features2d.so.2.4
        /usr/local/opencv2/lib/libopencv_contrib.so
        /usr/local/opencv2/lib/libopencv_photo.so.2.4.13
        /usr/local/opencv2/lib/libopencv_imgproc.so.2.4
        /usr/local/opencv2/lib/libopencv_stitching.so
        /usr/local/opencv2/lib/libopencv_features2d.so.2.4.13
        /usr/local/opencv2/lib/libopencv_superres.so.2.4
        /usr/local/opencv2/lib/libopencv_imgproc.so.2.4.13
        /usr/local/opencv2/lib/libopencv_flann.so.2.4.13
        /usr/local/opencv2/lib/libopencv_highgui.so.2.4.13
        /usr/local/opencv2/lib/libopencv_video.so.2.4.13
        /usr/local/opencv2/lib/libopencv_videostab.so.2.4.13
        /usr/local/opencv2/lib/libopencv_nonfree.so.2.4.13
        /usr/local/opencv2/lib/libopencv_highgui.so
        /usr/local/opencv2/lib/libopencv_ocl.so.2.4.13
        /usr/local/opencv2/lib/libopencv_core.so.2.4.13
        /usr/local/opencv2/lib/libopencv_video.so.2.4
        /usr/local/opencv2/lib/libopencv_gpu.so
        /usr/local/opencv2/lib/libopencv_video.so
        /usr/local/opencv2/lib/libopencv_videostab.so
        /usr/local/opencv2/lib/libopencv_highgui.so.2.4
        /usr/local/opencv2/lib/libopencv_calib3d.so
        /usr/local/opencv2/lib/libopencv_stitching.so.2.4.13
        /usr/local/opencv2/lib/libopencv_photo.so)

target_link_libraries( opencv_test ${OpenCV_LIBS} )

*****************************************************************************************************
***********************************************************方法二************************************
*****************************************************************************************************

cmake_minimum_required(VERSION 3.8)
project(opencv_test3)

set(CMAKE_CXX_STANDARD 11)#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

add_executable(opencv_test3 main.cpp)#set(SOURCE_FILES main.cpp);add_executable(opencv_test ${SOURCE_FILES})


# add libs you need

#set(OpenCV_INCLUDE_DIRS
#        /usr/local/opencv2/include
#        /usr/local/opencv2/include/opencv
#        /usr/local/opencv2/include/opencv)
#include_directories(${OpenCV_INCLUDE_DIRS})

#直接法:包含目录
#include_directories(/usr/local/opencv3_contrib/include)
#include_directories(/usr/local/opencv3_contrib/opencv)
#include_directories(/usr/local/opencv3_contrib/opencv2)

#find_package(OpenCV REQUIRED)#新版本用OpenCVConfig.cmake(config mode)或者FindOpenCV.cmake(module mode)
#本机上有两个opencv版本。/usr/local/share/OpenCV/OpenCVConfig.cmake (2.4.6)
#和/usr/local/share/opencv/OpenCVConfig.cmake (2.1.0 zombie)
#set(OpenCV_LIBS
#       opencv_core
#       opencv_imgproc
#        opencv_highgui
#       opencv_imgcodecs)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
#设置OpenCV_DIR为包含OpenCVConfig.cmake的目录,如果报错可能是没找到包含目录,可以用直接法试试
set(OpenCV_DIR /usr/local/opencv3_contrib/share/OpenCV)
find_package(OpenCV REQUIRED)

# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
#message(STATUS "OpenCV library status:")
#message(STATUS "    version: ${OpenCV_VERSION}")
#message(STATUS "    libraries: ${OpenCV_LIBS}")
#message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")

# Add OpenCV headers location to your include paths
#include_directories(${OpenCV_INCLUDE_DIRS})


target_link_libraries( opencv_test3 ${OpenCV_LIBS} )

你可能感兴趣的:(OpenCV,opencv学习系列)