已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026广东河源市连平县招聘临聘教师16人备考题库附答案详解ab卷
- 2026广东江门市台山市应急救援和保障中心招聘7人备考题库及答案详解(夺冠)
- 2026北京智能驾驶事业部招聘7人备考题库带答案详解(研优卷)
- 2026上半年安徽事业单位联考宣城市市直单位招聘8人备考题库及完整答案详解1套
- 2026北京兴宾通人力资源管理有限公司面向社会招聘劳务派遣人员4人备考题库附答案详解(预热题)
- 2026山东枣庄市第一批次市直就业见习招聘113人备考题库及1套完整答案详解
- 2026云南昆明官渡区上海师范大学附属官渡实验学校(中学)招聘1人备考题库含答案详解(巩固)
- 水龙头及卫浴配件制作工岗前技能实操考核试卷含答案
- 铸造造型(芯)工成果测试考核试卷含答案
- 肥料配方师安全操作水平考核试卷含答案
- 2025年司法鉴定人资格考试历年真题试题及答案
- 江苏省连云港市2024-2025学年第一学期期末调研考试高二历史试题
- 生成式人工智能与初中历史校本教研模式的融合与创新教学研究课题报告
- 2025年湖北烟草专卖局笔试试题及答案
- 2026年开工第一课复工复产安全专题培训
- 特殊人群(老人、儿童)安全护理要点
- 2026年检察院书记员面试题及答案
- 《煤矿安全规程(2025)》防治水部分解读课件
- 2025至2030中国新癸酸缩水甘油酯行业项目调研及市场前景预测评估报告
- 2025年保安员职业技能考试笔试试题(100题)含答案
- 尾矿库闭库综合治理工程项目可行性研究报告
评论
0/150
提交评论