




已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
OpenCV 学习笔记之(二):图像的基本操作(VS2010+OpenCV3.0 ) 本节对应 OpenCV.2.Computer.Vision.Application.Programming.Cookbook -第 3 章 Processing Images with Classes 中的 Using a Controller to communicate with processing modules 的部分。 本节把书中的提要详细化,给自已备份的同时也希望给别人一点启发。 开始 一、打开 VS2010,建立项目 二、下一步后,原来的“使用 Unicode 库”勾去掉。 三、完成后,出现编辑界面 四、编辑对话框,设计成如下界面。 五、点开“解决方案资源管理器” ,添加头文件 colordetector.h #if !defined COLORDETECT #define COLORDETECT #include class ColorDetector private: /minimum acceptable distance int minDist; /target color cv:Vec3b target; /image containing resulting binary map cv:Mat result; /inline private member function /Computes the distance from target color. int getDistance(const cv:Vec3b public: /empty constructor ColorDetector():minDist(100) / default parameter initialization here target0 = target1 = target2 = 0; /Getters and setters /Sets the color distance threshold /Threshold must be positive,otherwise distance threshold is set to 0. void setColorDistanceThreshold(int distance); /Gets the color distance threshold int getColorDistanceThreshold() const; / Sets the color to be detected void setTargetColor(unsigned char red,unsigned char green,unsigned char blue); / Sets the color to be detected void setTargetColor(cv:Vec3b color); / Gets the color to be detected cv:Vec3b getTargetColor() const; / Processes the image. Returns a 1-channel binary image. cv:Mat proecess(const cv:Mat ; #endif 六、添加源文件 colordetector.cpp #include “StdAfx.h“ #include“colordetector.h“ int ColorDetector:getDistance(const cv:Vec3b void ColorDetector:setColorDistanceThreshold(int distance) if ( distance :const_iterator it = image.begin(); cv:Mat_:const_iterator itend = image.end(); cv:Mat_:iterator itout = result.begin(); / for each pixel for ( ; it != itend; +it, +itout ) / process each pixel - / compute distance from target color if ( getDistance(*it) #include #include“colordetector.h“ class ColorDetectController private: static ColorDetectController *singleton; / pointer to the singleton ColorDetector *cdetect; / The image to be processed cv:Mat image; cv:Mat result; public: ColorDetectController(); / Sets the color distance threshold void setColorDistanceThreshold(int distance); / Gets the color distance threshold int getColorDistanceThreshold() const; / Sets the color to be detected void setTargetColor(unsigned char red,unsigned char green,unsigned char blue); / Gets the color to be detected void getTargetColor(unsigned char / Sets the input image. Reads it from file bool setInputImage(std:string filename); / Returns the current input image. const cv:Mat getInputImage() const; / Performs image processing void process(); / Returns the image result from the latest processing const cv:Mat getLastResult() const; / Deletes all processor objects created by the controller ColorDetectController(); / Singleton static members static ColorDetectController *getInstance() if (singleton = 0) singleton= new ColorDetectController; return singleton; / Releases the singleton instance of this controller. static void destroy(); ; #endif /colorDetectController.cpp #include “StdAfx.h“ #include“colorDetectController.h“ ColorDetectController *ColorDetectController:singleton = 0; ColorDetectController:ColorDetectController() / private constructor / setting up the application cdetect = new ColorDetector(); void ColorDetectController:setColorDistanceThreshold(int distance) cdetect-setColorDistanceThreshold(distance); int ColorDetectController:getColorDistanceThreshold() const return cdetect-getColorDistanceThreshold(); void ColorDetectController:setTargetColor(unsigned char red, unsigned char green, unsigned char blue) cdetect-setTargetColor(red,green,blue); void ColorDetectController:getTargetColor(unsigned char red = color2; green = color1; blue = color0; bool ColorDetectController:setInputImage(std:string filename) image = cv:imread(filename); if ( !image.data ) return false; else return true; const cv:Mat ColorDetectController:getInputImage() const return image; void ColorDetectController:process() result = cdetect-proecess(image); const cv:Mat ColorDetectController:getLastResult() const return result; ColorDetectController:ColorDetectController() delete cdetect; void ColorDetectController:destroy() if ( singleton != 0 ) delete singleton; singleton = 0; 八,双击 ColourDetectorDlg.h,出现编辑界面,导入头文件 colorDetectController.h 和定义 变量 colordetect 九、添加“Open Image”按钮和“Process ”按钮的事件处理程序 十、分别添加代码 void CColourDetectorDlg:OnBnClickedOpenButton() / TODO: 在此添加控件通知处理程序代码 CFileDialog dlg(TRUE,_T(“*.bmp“),NULL,OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY,_T(“image file(*.bmp; *.jpg)|*.bmp; *.jpg|All Files(*.*)|*.*|“),NULL); dlg.m_ofn.lpstrTitle = _T(“Open Image“); / if a filename has been selected if ( IDOK = dlg.DoModal() ) std:string filename = dlg.GetPathName(); / set and display the input image colordetect.setInputImage(filename); cv:imshow(“Input Image“,colordetect.getInputImage(); void CColourDetectorDlg:OnBnClickedProcessButton() / TODO: 在此
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 健康职场小知识
- 真正的游戏课件
- 西藏民族大学《儿童戏剧与表演》2023-2024学年第二学期期末试卷
- 肇庆学院《边坡与基坑工程》2023-2024学年第二学期期末试卷
- 南昌健康职业技术学院《健美操四》2023-2024学年第一学期期末试卷
- 九江理工职业学院《煤层气开采概论》2023-2024学年第二学期期末试卷
- 2025标准房屋租赁合同协议书样本
- 土坝开槽泄洪方案范本
- 长春建筑学院《体操(3)》2023-2024学年第二学期期末试卷
- 《航天技术的应用与课件整合》
- 12J12 天津市建筑标准设计图集(2012版)无障碍设施
- 妊娠合并HIV感染孕产妇入院后处理流程
- 深度业务交换网关
- 医院灾害脆弱性分析报告(2020版)
- 钢木质隔热防火门成品检验报告
- SB/T 10104-2017糖果充气糖果
- GB/Z 18462-2001激光加工机械金属切割的性能规范与标准检查程序
- GB/T 4457.4-2002机械制图图样画法图线
- GB/T 2421.1-2008电工电子产品环境试验概述和指南
- 国外发票模板invoice
- 企业重组相关税收政策培训课件
评论
0/150
提交评论