码迷,mamicode.com
首页 > 其他好文 > 详细

将Opencv加入到环境变量中

时间:2019-09-25 00:34:40      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:exist   rar   bsp   lin   测试   get   set   stand   install   

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加入到环境变量中

标签:exist   rar   bsp   lin   测试   get   set   stand   install   

原文地址:https://www.cnblogs.com/codeAndlearn/p/11581936.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!