将Opencv加入到环境变量中

Posted codeandlearn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将Opencv加入到环境变量中相关的知识,希望对你有一定的参考价值。

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

  FIND_PACKAGE( OpenCV 4.0.0 REQUIRED )

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

技术图片

 

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.一次编译通过

技术图片

 

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

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

技术图片

 

以上是关于将Opencv加入到环境变量中的主要内容,如果未能解决你的问题,请参考以下文章

C++ 需要有关 OpenCV 教程中代码的帮助

如何通过单击适配器类中代码的项目中的删除按钮来删除列表视图中的项目后重新加载片段?

Visual c++ 6.0配置OpenCV开发环境

Java中代码的执行顺序

学习Opencv 2.4.9 ---Opencv + vs2012环境配置

opencv vs环境配置