将Opencv加入到环境变量中

1.Cmake 命令出错问题分析,以下语句报错,cmake是通过系统查找对应的模块的地址的,所以没有找到应该是环境变量错误了。

  FIND_PACKAGE( OpenCV 4.0.0 REQUIRED )

2.重新添加系统环境变量。

将Opencv加入到环境变量中_第1张图片

 

3.直接测试对应的程序并对于cmake文件做了修改。

原始Cmake文件

cmake_minimum_required (VERSION 3.0)

PROJECT(Photo_Tool)

set (CMAKE_CXX_STANDARD 11)

IF(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
    include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
    conan_basic_setup()
ENDIF()

# Requires OpenCV
# FIND_PACKAGE( OpenCV 4.0.0 REQUIRED )

FIND_PACKAGE( OpenCV 4.0.0 REQUIRED )

MESSAGE("OpenCV version : ${OpenCV_VERSION}")

include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${OpenCV_LIB_DIR})

ADD_EXECUTABLE( ${PROJECT_NAME} main.cpp )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${OpenCV_LIBS} )

ADD_EXECUTABLE( ch3_sample1 sample1.cpp )
TARGET_LINK_LIBRARIES( ch3_sample1 ${OpenCV_LIBS} )

ADD_EXECUTABLE( ch3_sample2 sample2.cpp )
TARGET_LINK_LIBRARIES( ch3_sample2 ${OpenCV_LIBS} )

ADD_EXECUTABLE( ch3_sample3 sample3.cpp )
TARGET_LINK_LIBRARIES( ch3_sample3 ${OpenCV_LIBS} )

ADD_EXECUTABLE( ch3_sample4 sample4.cpp )
TARGET_LINK_LIBRARIES( ch3_sample4 ${OpenCV_LIBS} )

ADD_EXECUTABLE( ch3_sample5 sample5.cpp )
TARGET_LINK_LIBRARIES( ch3_sample5 ${OpenCV_LIBS} -lglut -lGL -lGLU)

ADD_EXECUTABLE( ch3_sample6 sample6.cpp )
TARGET_LINK_LIBRARIES( ch3_sample6 ${OpenCV_LIBS} )

 

 更新后Cmake

cmake_minimum_required (VERSION 3.0)

PROJECT(Photo_Tool)

set (CMAKE_CXX_STANDARD 11)

IF(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
    include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
    conan_basic_setup()
ENDIF()

# Requires OpenCV
# FIND_PACKAGE( OpenCV 4.0.0 REQUIRED )

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}  
                         "D:/Code/opencv_cxx/opencv-4.0.0-bin"
)
set(OpenCV_DIR  "D:/Code/opencv_cxx/opencv-4.0.0-bin")
FIND_PACKAGE( OpenCV 4.0.0 REQUIRED )
MESSAGE("OpenCV version : ${OpenCV_VERSION}")

include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${OpenCV_LIB_DIR})
Link_directories(D:/Code/opencv_cxx/opencv-4.0.0-bin/install/include/opencv2)
ADD_EXECUTABLE( ${PROJECT_NAME} main.cpp )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${OpenCV_LIBS} )

ADD_EXECUTABLE( ch3_sample1 sample1.cpp )
TARGET_LINK_LIBRARIES( ch3_sample1 ${OpenCV_LIBS} )

ADD_EXECUTABLE( ch3_sample2 sample2.cpp )
TARGET_LINK_LIBRARIES( ch3_sample2 ${OpenCV_LIBS} )

ADD_EXECUTABLE( ch3_sample3 sample3.cpp )
TARGET_LINK_LIBRARIES( ch3_sample3 ${OpenCV_LIBS} )

ADD_EXECUTABLE( ch3_sample4 sample4.cpp )
TARGET_LINK_LIBRARIES( ch3_sample4 ${OpenCV_LIBS} )

ADD_EXECUTABLE( ch3_sample5 sample5.cpp )
TARGET_LINK_LIBRARIES( ch3_sample5 ${OpenCV_LIBS} -lglut -lGL -lGLU)

ADD_EXECUTABLE( ch3_sample6 sample6.cpp )
TARGET_LINK_LIBRARIES( ch3_sample6 ${OpenCV_LIBS} )

4.一次编译通过

将Opencv加入到环境变量中_第2张图片

 

 5.打开VS2017运行结果,cmake在编译和配置方面确实很方便。

OpenCV4.0的Qt控件的融合要是很赞,直接可以放缩以及查看像素值。

将Opencv加入到环境变量中_第3张图片

 

转载于:https://www.cnblogs.com/codeAndlearn/p/11581936.html

你可能感兴趣的:(将Opencv加入到环境变量中)