学习材料OpenCV课件教学文稿

上传人:youn****329 文档编号:137228484 上传时间:2020-07-06 格式:PPT 页数:116 大小:5.39MB
返回 下载 相关 举报
学习材料OpenCV课件教学文稿_第1页
第1页 / 共116页
学习材料OpenCV课件教学文稿_第2页
第2页 / 共116页
学习材料OpenCV课件教学文稿_第3页
第3页 / 共116页
学习材料OpenCV课件教学文稿_第4页
第4页 / 共116页
学习材料OpenCV课件教学文稿_第5页
第5页 / 共116页
点击查看更多>>
资源描述

《学习材料OpenCV课件教学文稿》由会员分享,可在线阅读,更多相关《学习材料OpenCV课件教学文稿(116页珍藏版)》请在金锄头文库上搜索。

1、OpenCV自学材料,田永鸿 北京大学数字媒体研究所,第一部分,OpenCV概述 基础结构与操作 基本OpenCV程序与示例 注:本讲义中部分代码来自OpenCV样例,部分代码来自OpenCV教程基础篇,部分代码则从网上收集。,2,OpenCV概述,OpenCV是Intel开源计算机视觉库。 它由一系列 C 函数和少量 C+ 类构成,实现了图像处理和计算机视觉方面的很多通用算法。 OpenCV 的特点 拥有包括 300 多个C函数的跨平台的中、高层 API 跨平台:Windows, Linux 免费(FREE):无论对非商业应用和商业应用 速度快 使用方便,3,4,OpenCV structu

2、re,CXCORE basic structures and algoritms, XML support, drawing functions,CV Image processing and vision,HighGUI GUI, Image and Video I/O,ML Machine Learning algorithms,CVCam video stream processing,OpenCV的下载与安装,1、下载地址 2、VC6.0下的安装与配置 参见 3、.NET 2003下的安装与配置 参见 ,6,Configuring MSVS .net 2k3,Create a Win3

3、2 Console Project,Make it an Empty Project by selecting the box under Application Settings,Configuring MSVS .net 2k3,Select C+ file and give it a name,Creating a file makes it possible to set Additional Include Directives in the C/C+ pane under the project properties.,Configuring MSVS .net 2k3,In or

4、der to build projects using OpenCV the required libraries and directives must be included in the projects properties,Configuring MSVS .net 2k3,Select the Additional Include Directives,Configuring MSVS .net 2k3,Select the Additional Dependencies,Testing MSVS .net 2k3,Now that the environment is confi

5、gured it would be a good idea to test it to make sure that a program will correctly build and run.,#include #include /*This will pop up a small box with Hello World as the text.*/ int main( int argc, char* argv ) /declare for the height and width of the image int height = 320; int width = 240; /spec

6、ify the point to place the text CvPoint pt = cvPoint( height/4, width/2 ); /Create an 8 bit, 3 plane image IplImage* hw = cvCreateImage(cvSize(height, width), 8, 3); /initialize the font CvFont font; cvInitFont( ,Testing MSVS .net 2k3,Output of Program,OpenCV 编码样式指南,1、文件命名:有cv和cvaux库文件的命名必须服从于以下规则:

7、所有的CV库文件名前缀为cv 混合的C/C+接口头文件扩展名为 .h 纯C+接口头文件扩展名为 .hpp 实现文件扩展名为 .cpp 为了与POSIX兼容,文件名都以小写字符组成,14,OpenCV 编码样式指南,2、文件结构 每个文件以BSD兼容的许可声明(模板在Contributors_BSD_Licsense.htm文件中可以找到)开头; 一行最多90个字符,不包括行结束符 不使用制表符 缩进为4个空格符,所以制表符应该用1-4个空格替换(依据开始列确定) 头文件必须使用保护宏,防止文件被重复包含。 混合C/C+接口头文件用extern C 包含C语言定义。 为了使预编译头机制在Visu

8、al C+中工作正常,源文件必须在其它头文件前包含precomp.h头文件。,15,OpenCV 编码样式指南,3、命名约定 OpenCV中使用大小写混合样式来标识外部函数、数据类型和类方法。 宏全部使用大写字符,词间用下划线分隔。 所有的外部或内部名称,若在多个文件中可见,则必须含有前缀: 外部函数使用前缀cv 内部函数使用前缀Icv 数据结构(C结构体、枚举、联合体、类)使用前缀Cv 外部或某些内部宏使用前缀CV_ 内部宏使用前缀ICV_,16,OpenCV 编码样式指南,4、函数接口设计:为了保持库的一致性,以如下方式设计接口非常重要。函数接口元素包括: 功能 名称 返回值 参数类型 参

9、数顺序 参数默认值 函数功能必须定义良好并保持精简。函数应该容易镶入到使用其它OpenCV函数的不同处理过程。函数名称应该简单并能体现函数的功能。大多数函数名形式:cv,17,18,A Simple OpenCV Program,1. #include 2. #include 3. #include 4. int main( int argc, char* argv ) 5. CvPoint center; 6. double scale=-3; 7. IplImage* image = argc=2 ? cvLoadImage(argv1) : 0; 8. if(!image) return

10、 -1; 9. center = cvPoint(image-width/2,image-height/2); 10. for(int i=0;iheight;i+) 11. for(int j=0;jwidth;j+) 12. double dx=(double)(j-center.x)/center.x; 13. double dy=(double)(i-center.y)/center.y; 14. double weight=exp(dx*dx+dy*dy)*scale); 15. uchar* ptr = ,基本数据结构,点:CvPoint 、CvPoint2D32f、CvPoint

11、3D32f 矩形框大小:CvSize 、CvSize2D32f 矩形框:CvRect 可以存放1-4个数值的数组:CvScalar 定义迭代算法的终止规则:CvTermCriteria 矩阵:CvMat 、CvMatND 、CvSparseMat IPL图像头部:IplImage 定义不确定的数组:CvArr (仅作函数参数),19,点数据结构,CvPoint 二维坐标系下的点,类型为整型 typedef struct CvPoint int x; /* X坐标, 通常以0为基点 */int y; /* y坐标, 通常以0为基点 */CvPoint;/* 构造函数 */inline CvPoi

12、nt cvPoint( int x, int y );/* 从 CvPoint2D32f类型转换得来 */inline CvPoint cvPointFrom32f( CvPoint2D32f point ) CvPoint2D32f :二维坐标下的点,类型为浮点 CvPoint3D32f :三维坐标下的点,类型为浮点,20,矩形框大小数据结构,CvSize 矩形框大小,以像素为精度 typedef struct CvSizeint width; /* 矩形宽 */int height; /* 矩形高 */CvSize;/* 构造函数 */inline CvSize cvSize( int w

13、idth, int height ); CvSize2D32f,21,矩形框数据结构,CvRect 矩形框的偏移和大小 typedef struct CvRectint x; /* 方形的最左角的x-坐标 */int y; /* 方形的最上或者最下角的y-坐标 */int width; /* 宽 */int height; /* 高 */CvRect;/* 构造函数*/inline CvRect cvRect(int x, int y, int width, int height);,22,矩阵数据结构,CvMat 二维矩阵 typedef struct CvMat int type; /*

14、CvMat 标识, 元素类型和标记 */int step; /* 以字节为单位的行数据长度*/int rows; /*行数*/int cols; /*列数*/ int* refcount; /* 数据引用计数 */unionuchar* ptr;short* s;int* i;float* fl;double* db; data; /* data 指针 */,23,矩阵数据结构,CvMatND:多维、多通道密集数组 CvSparseMat:多维、多通道稀疏数组 CvArr:不确定数组,24,图像头数据,IplImage:IPL 图像头,25,图像头数据,IplImage:IPL 图像头type

15、def struct _IplImage int nSize; /* IplImage大小 */int ID; /* 版本 (=0)*/int nChannels; /* 大多数OPENCV函数支持1,2,3 或4 个通道 */int alphaChannel; /* 被OpenCV忽略 */int depth; /* 像素的位深度: IPL_DEPTH_8U,IPL_DEPTH_8S, IPL_DEPTH_16U,IPL_DEPTH_16S, IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F 可支持 */char colorModel4; char

16、 channelSeq4; /* 被OpenCV忽略 */ int dataOrder; /* 0 - 交叉存取颜色通道, 1 - 分开的颜色通道.cvCreateImage只能创建交叉存取图像 */int origin; /* 0 - 顶左结构,1 - 底左结构 (BMP风格) */int align; /* 图像行排列 (4 or 8). OpenCV 用widthStep 代替 */,26,int width; /* 图像宽像素数 */int height; /* 图像高像素数*/struct _IplROI *roi;/* 图像感兴趣区域. 当该值非空只对该区域进行处理 */struct _IplImage *maskROI; /* 在 OpenCV中必须置NULL */void *imageId; /* 同上*/struct _IplTileInfo *tileInfo; /*同上*/ int imageSize; /* 图像数据大小,单位字节*

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 教学课件 > 高中课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号