Controller//控制器

Posted claireyuancy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Controller//控制器相关的知识,希望对你有一定的参考价值。

#include<opencv2\core\core.hpp>
#include<opencv2\imgproc\imgproc.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<iostream>


using namespace std;
using namespace cv;




class ColorDetector
{
public:
ColorDetector():minDist(100)
{
target[0]=target[1]=target[0]=0;
};
void setColorDistanceThreshold(int distance)
{
if(distance<0)
distance=0;
minDist=distance;
};
int getColorDistanceThreshold() const
{
return minDist;
};
void setTargetColor(unsigned char red,
                   unsigned char green,
unsigned char blue)
{
target[0]=blue;
target[1]=green;
target[2]=red;
};
void setTargetColor(cv::Vec3b color)
{
target=color;
};
cv::Vec3b getTargetColor() const
{
return target;
};
int getDistance(const cv::Vec3b& color) const
{
return abs(color[0]-target[0])+abs(color[1]-target[1])+abs(color[2]-target[2]);
};
cv::Mat process(const cv::Mat &image);//核心算法。在类外实现
private:
int minDist;
cv::Vec3b target;
cv::Mat result;
};
cv::Mat ColorDetector::process(const cv::Mat &image)
{
result.create(image.rows,image.cols,CV_8U);
cv::Mat_<cv::Vec3b>::const_iterator it=image.begin<cv::Vec3b>();
cv::Mat_<cv::Vec3b>::const_iterator itend=image.end<cv::Vec3b>();
cv::Mat_<uchar>::iterator itout=result.begin<uchar>();
for(;it!=itend;++it,++itout)
{
if(getDistance(*it)<minDist)
{
*itout=255;
}
else
{
*itout=0;
}
}
return result;
}
class ColorDetectController//控制器
{
private:
ColorDetector *cdetect;
cv::Mat image;
cv::Mat result;
public:
ColorDetectController()
{
cdetect=new ColorDetector();
};
void setColorDistanceThreshold(int distance)
{
cdetect->setColorDistanceThreshold(distance);
};
int getColorDistanceThreshold() const
{
return cdetect->getColorDistanceThreshold();
};
void setTargetColor(unsigned char red,unsigned char green,unsigned char blue)
{
cdetect->setTargetColor(red,green,blue);
};
void getTargetColor(unsigned char &red,unsigned char &green,unsigned char &blue)const
{
cv::Vec3b color=cdetect->getTargetColor();
red=color[2];
green=color[1];
blue=color[0];
};
bool setInputImage(std::string filename)
{
image=cv::imread(filename);
if(!image.data)
return false;
else
return true;
};
const cv::Mat getInputImage()const
{
return image;
};
void process()
{
result=cdetect->process(image);
};
const cv::Mat getLastResult() const
{
return result;
};
~ColorDetectController()
{
delete cdetect;
};
}

以上是关于Controller//控制器的主要内容,如果未能解决你的问题,请参考以下文章

Jmeter (二十六)逻辑控制器 之 Module Controller and Include Controller

Jmeter (二十六)逻辑控制器 之 Module Controller and Include Controller

Jmeter(十八)Logic Controller 之 Random Controller and Random order Controller

Kubernetes 中 controller 控制器

Kubernetes 中 controller 控制器

Spring Controller 处理所有其他 Controller 不匹配的请求