OpenCV复习(一) 接触图像

1.1 引言

主要讲OpenCV的基础元素,完成最基本的操作:读取、显示及保存图像。

我用的IDE是KDE4。因为免费。

1.2 安装OpenCV库

注意安装OpenCV时,带上扩展模块。可以搜可视化界面安装GUI。在这里不赘述了。

OpenCV的官方网址,可以在这里找到官方文档和源码,方便查阅。

注意:OpenCV库目前被划分为多个模块。这些模块编译成库文件后,位于lib文件中。

  • opencv_core 模块,包含核心功能,尤其是对底层数据结构和算法函数。
  • opencv_imgproc 模块,包含图像处理函数。
  • opencv_highgui 模块,包含读写图像以及视频的函数,以及操作图形用户界面的函数。
  • opencv_features2d模块,包含兴趣点关键子、描述子以及兴趣点匹配框架。
  • opencv_calib3d 模块,包含相机标定、双目几何估算及立体视觉函数。
  • opencv_video 模块,包含运动估算、特征追踪以及前景提取函数与类。
  • opencv_objdetect 模块,包含物体检测函数,如脸部与行人检测。

还有其他工具模块,如机器学习(opencv_ml)、计算几何(opencv_flann),第三方代码(opencv_conrrib)、废弃的代码(opencv_legacy)及GPU加速过的代码(opencv_gpu)。

这些模块都有一个单独的头文件(位于include文件夹)。典型的OpenCV C++代码将包含所需的模块,声明如下:

#include<opencv2/core/core.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>

提示一下,如果看到下面的开始方式:

#include "cv.h"

这是因为它使用了旧的代码方式,那时候库还没有被划分为各个模块。

1.3 用KDE4创建OpenCV工程

创建过程省略,我们主要看下CMakeList.txt怎么写(Linux环境下开发是最舒适地):

cmake_minimum_required(VERSION 2.6)
set(CMAKE_BUILD_TYPE "Debug")  
set( CMAKE_CXX_FLAGS "-std=c++11 -O3" )
project(study_OpenCV)
find_package(OpenCV 3 REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )

add_executable(study_OpenCV main.cpp)
target_link_libraries(study_OpenCV ${OpenCV_LIBS})
install(TARGETS study_opencv RUNTIME DESTINATION bin)

1.4 载入、显示及保存图像

具体实现,来,先声明一个表示图像的变量,在OpenCV2中,这个变量将是cv::Mat类型。

cv::Mat image;

上面是一个实例化操作。这句话将创建宽高都为0的图像,通过调用cv::Mat的size()方法,可以获取该图像的尺寸,我们可以

。。。。。写到一半断网了,网页一刷新啥也没了。。。。下面就直接截图了。

解压到sln一级目录项目属性 C/C++ 附加包含目录 填写Libs/x86/opencv_v3.4.0/include路径 属性中链接器,所有选项附加库目录填写Libs/x86/opencv_v3.4.0/lib 附加依赖项: opencv_aruco340.lib;f.lib;opencv_bgsegm340.lib;opencv_bgsegm340d.lib;opencv_bioinspired340.lib;opencv_bioinspired340d.lib;opencv_calib3d340.lib;opencv_calib3d340d.lib;opencv_ccalib340.lib;opencv_ccalib340d.lib;opencv_core340.lib;opencv_core340d.lib;opencv_datasets340.lib;opencv_datasets340d.lib;opencv_dnn340.lib;opencv_dnn340d.lib;opencv_dpm340.lib;opencv_dpm340d.lib;opencv_face340.lib;opencv_face340d.lib;opencv_features2d340.lib;opencv_features2d340d.lib;opencv_flann340.lib;opencv_flann340d.lib;opencv_fuzzy340.lib;opencv_fuzzy340d.lib;opencv_highgui340.lib;opencv_highgui340d.lib;opencv_imgcodecs340.lib;opencv_imgcodecs340d.lib;opencv_imgproc340.lib;opencv_imgproc340d.lib;opencv_img_hash340.lib;opencv_img_hash340d.lib;opencv_line_descriptor340.lib;opencv_line_descriptor340d.lib;opencv_ml340.lib;opencv_ml340d.lib;opencv_objdetect340.lib;opencv_objdetect340d.lib;opencv_optflow340.lib;opencv_optflow340d.lib;opencv_phase_unwrapping340.lib;opencv_phase_unwrapping340d.lib;opencv_photo340.lib;opencv_photo340d.lib;opencv_plot340.lib;opencv_plot340d.lib;opencv_reg340.lib;opencv_reg340d.lib;opencv_rgbd340.lib;opencv_rgbd340d.lib;opencv_saliency340.lib;opencv_saliency340d.lib;opencv_shape340.lib;opencv_shape340d.lib;opencv_stereo340.lib;opencv_stereo340d.lib;opencv_stitching340.lib;opencv_stitching340d.lib;opencv_structured_light340.lib;opencv_structured_light340d.lib;opencv_superres340.lib;opencv_superres340d.lib;opencv_surface_matching340.lib;opencv_surface_matching340d.lib;opencv_text340.lib;opencv_text340d.lib;opencv_tracking340.lib;opencv_tracking340d.lib;opencv_video340.lib;opencv_video340d.lib;opencv_videoio340.lib;opencv_videoio340d.lib;opencv_videostab340.lib;opencv_videostab340d.lib;opencv_xfeatures2d340.lib;opencv_xfeatures2d340d.lib;opencv_ximgproc340.lib;opencv_ximgproc340d.lib;opencv_xobjdetect340.lib;opencv_xobjdetect340d.lib;opencv_xphoto340.lib;opencv_xphoto340d.lib;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值