精品文档---下载后可任意编辑本节对应-----第 3 章 Processing Imageswith Classes 中的 Using a Controller to communicate with processing modules 的部分。本节把书中的提要详细化,给自已备份的同时也希望给别人一点启发。开始一、打开 VS2024,建立项目二、下一步后,原来的“使用 Unicode 库”勾去掉。三、完成后,出现编辑界面四、编辑对话框,设计成如下界面。精品文档---下载后可任意编辑五、点开“解决方案资源管理器”,添加头文件 colordetector.h#if !defined COLORDETECT#define COLORDETECT#includeclass ColorDetector{private://minimum acceptable distanceint minDist;//target colorcv::Vec3b target;//image containing resulting binary mapcv::Mat result;//inline private member function//Computes the distance from target color.int getDistance(const cv::Vec3b& color)const;public://empty constructorColorDetector():minDist(100) {// default parameter initialization heretarget[0] = target[1] = target[2] = 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 thresholdint getColorDistanceThreshold() const;// Sets the color to be detectedvoid setTargetColor(unsignedchar red,unsignedchar green,unsignedchar blue);// Sets the color to be detectedvoid setTargetColor(cv::Vec3b color);// Gets the color to be detectedcv::Vec3b getTargetColor() const;// Processes the image. Returns a 1-channel binary image.cv::Mat proecess(const cv::Mat &image);};#endif六、添加源文件#include"StdAfx.h"#include"colordetector.h"int ColorDetector::getDistance(const cv::Vec3b& color) const{return abs(color[0]-target[0])+abs(color[1]-target[1])+abs(color[2]-target[2]);}void ColorDetector::setColorDistanceThreshold(int distance){if ( distance < 0 ){distance = 0;}minDist = distance;}int ColorDetector::getCo...