OpenCV学习笔记之二.docx
上传人:王子****青蛙 上传时间:2024-09-13 格式:DOCX 页数:6 大小:1.8MB 金币:10 举报 版权申诉
预览加载中,请您耐心等待几秒...

OpenCV学习笔记之二.docx

OpenCV学习笔记之二.docx

预览

在线预览结束,喜欢就下载吧,查找使用更方便

10 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

本节对应-----第3章ProcessingImageswithClasses中的UsingaControllertocommunicatewithprocessingmodules的部分。本节把书中的提要详细化,给自已备份的同时也希望给别人一点启发。开始一、打开VS2010,建立项目二、下一步后,原来的“使用Unicode库”勾去掉。三、完成后,出现编辑界面四、编辑对话框,设计成如下界面。五、点开“解决方案资源管理器”,添加头文件colordetector.h#if!definedCOLORDETECT#defineCOLORDETECT#include<opencv2/core/core.hpp>classColorDetector{private://minimumacceptabledistanceintminDist;//targetcolorcv::Vec3btarget;//imagecontainingresultingbinarymapcv::Matresult;//inlineprivatememberfunction//Computesthedistancefromtargetcolor.intgetDistance(constcv::Vec3b&color)const;public://emptyconstructorColorDetector():minDist(100){//defaultparameterinitializationheretarget[0]=target[1]=target[2]=0;}//Gettersandsetters//Setsthecolordistancethreshold//Thresholdmustbepositive,otherwisedistancethresholdissetto0.voidsetColorDistanceThreshold(intdistance);//GetsthecolordistancethresholdintgetColorDistanceThreshold()const;//SetsthecolortobedetectedvoidsetTargetColor(unsignedcharred,unsignedchargreen,unsignedcharblue);//SetsthecolortobedetectedvoidsetTargetColor(cv::Vec3bcolor);//Getsthecolortobedetectedcv::Vec3bgetTargetColor()const;//Processestheimage.Returnsa1-channelbinaryimage.cv::Matproecess(constcv::Mat&image);};#endif六、添加源文件#include"StdAfx.h"#include"colordetector.h"intColorDetector::getDistance(constcv::Vec3b&color)const{returnabs(color[0]-target[0])+abs(color[1]-target[1])+abs(color[2]-target[2]);}voidColorDetector::setColorDistanceThreshold(intdistance){if(distance<0){distance=0;}minDist=distance;}intColorDetector::getColorDistanceThreshold()const{returnminDist;}voidColorDetector::setTargetColor(unsignedcharred,unsignedchargreen,unsignedcharblue){target[2]=red;target[1]=green;target[0]=blue;}voidColorDetector::setTargetColor(cv::Vec3bcolor){target=color;}cv::Vec3bColorDetector::getTargetColor()const{returntarget;}cv::MatColorDetector::proecess(constcv::Mat&image){//re-allocatebinarymapifne