机器人视觉(2)-opencv配置

1 安装opencv

opencv下载:opencv官网
安装教程:
1 ubuntu安装opencv的正确方法
2 环境配置—Ubuntu 16.04 安装Opencv 3.4.3

2 配置opencv

2.1 ubuntu
参考链接:Linux Ubuntu 下编译Opencv c++项目的几种方法

OpenCV推荐使用CMake工具

Step1:新建一个目录用于存放我们的代码和程序中要处理的相关图片

Step2:添加cmake工具编译时所需的文件CMakeLists.txt

注:这个文件你可以到你的OpenCV源代码解压出来的文件夹下的/samples/c/example_cmake/文件夹下拷过来,然后再做修改

原文件如下:

# cmake needs this line
cmake_minimum_required(VERSION 2.8)
 
# Define project name
project(opencv_example_project)
 
# 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
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}")
 
if(CMAKE_VERSION VERSION_LESS "2.8.11")
  # Add OpenCV headers location to your include paths
  include_directories(${OpenCV_INCLUDE_DIRS})
endif()
 
# Declare the executable target built from your sources
add_executable(opencv_example example.cpp)
 
# Link your application with OpenCV libraries
target_link_libraries(opencv_example ${OpenCV_LIBS})

根据你的项目名称和该项目里包含的源码文件,修改如下:

# cmake needs this line
cmake_minimum_required(VERSION 2.8)
#这是对CMake工具最低版本要求,这里我们要检查下我们的CMake工具的版本信息,我们可以使用命令“cmake --version”查看
 
# Define project name
project(opencv_example)
#//这是建立一个工程项目(类似于我们VS中建立C++项目一样),括号里面时工程名,工程名我们可以任意给,最后程序编译出来的可执行文件就是这个名字
 
# 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
find_package(OpenCV REQUIRED)  #这是cmake用来查找opencv包用的,
 
# 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}")
 
if(CMAKE_VERSION VERSION_LESS "2.8.11")
  # Add OpenCV headers location to your include paths
  include_directories(${OpenCV_INCLUDE_DIRS})
endif()
 
# Declare the executable target built from your sources
add_executable(opencv_example main.cpp) #这里括号里面的两个参数分别是工程项目名和我们要编译文件名的意思,记住中间一空格键隔开
 
# Link your application with OpenCV libraries
target_link_libraries(opencv_example ${OpenCV_LIBS}) #这是我们链接到OpenCV库的环节,我们只要更改前面第一个参数为我们的工程项目名即可

然后我们就将终端的工作目录切换到我们建立工程文件的这个目录

Step3:让后我们输入命令"cmake ."对当前的工程进行编译。

$ cmake .
cmake: /home/yang/anaconda2/lib/libcurl.so.4: no version information available (required by cmake)
-- OpenCV library status:
--     version: 3.4.3
--     libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_shape;opencv_stitching;opencv_superres;opencv_video;opencv_videoio;opencv_videostab
--     include path: /usr/local/include;/usr/local/include/opencv
-- Configuring done
-- Generating done
-- Build files have been written to: /home/yang/桌面/learningOPencv/编译opencv_cpp文件的方法2CMake/opencv_sourceCode

Step4: make

$ make
/usr/bin/cmake: /home/yang/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/yang/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/yang/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/yang/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
[100%] Built target opencv_example
/usr/bin/cmake: /home/yang/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)

Step5:运行可执行文件

$ ./opencv_example
./opencv_example: /home/yang/anaconda2/lib/libtiff.so.5: no version information available (required by /usr/local/lib/libopencv_imgcodecs.so.3.4)
please input the image file path:
dog.jpeg

2.2 windows
windows 下OpenCV的安装部署详细教程
VS2019+OpenCV安装与配置教程
由于找不到opencv_world320d.dll,无法继续执行代码

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值