cmake如何引入opencv

opencv cmake 使用实例

set(OpenCV_DIR "D:/opencv/build" CACHE PATH "OPENCV directory override" FORCE)

#D:/opencv/build目录包含OpenCVConfig.cmake

# 寻找OpenCV库

find_package(OpenCV REQUIRED )

target_link_libraries(
    PRIVATE ${OpenCV_LIBS}
)
    
 # 添加头文件
include_directories(${OpenCV_INCLUDE_DIRS})

#.exe下的可执行文件包含使用到的dll

#file(COPY "${OpenCV_DIR}/bin/debug/opencv_world346d.dll" DESTINATION "${PROJECT_OUTPUT_DIR}/debug")
#file(COPY "${OpenCV_DIR}/bin/debug/opencv_world346d.dll" DESTINATION "${PROJECT_OUTPUT_DIR}/release")
#file(COPY "${OpenCV_DIR}/bin/debug/opencv_core346d.dll" DESTINATION "${PROJECT_OUTPUT_DIR}/debug")
#file(COPY "${OpenCV_DIR}/bin/debug/opencv_core346d.dll" DESTINATION "${PROJECT_OUTPUT_DIR}/release")
#file(COPY "${OpenCV_DIR}/bin/debug/opencv_imgproc346d.dll" DESTINATION "${PROJECT_OUTPUT_DIR}/debug")
#file(COPY "${OpenCV_DIR}/bin/debug/opencv_imgproc346d.dll" DESTINATION "${PROJECT_OUTPUT_DIR}/release")
#file(COPY "${OpenCV_DIR}/bin/debug/opencv_imgcodecs346d.dll" DESTINATION "${PROJECT_OUTPUT_DIR}/debug")
#file(COPY "${OpenCV_DIR}/bin/debug/opencv_imgcodecs346d.dll" DESTINATION "${PROJECT_OUTPUT_DIR}/release")
#file(COPY "${OpenCV_DIR}/bin/debug/opencv_videoio346d.dll" DESTINATION "${PROJECT_OUTPUT_DIR}/debug")
#file(COPY "${OpenCV_DIR}/bin/debug/opencv_videoio346d.dll" DESTINATION "${PROJECT_OUTPUT_DIR}/release")

你可能感兴趣的:(opencv,c++)