OpenCV——视频颜色识别

#include <opencv2/opencv.hpp>
#include <iostream> using namespace std;
using namespace cv; int minh,maxh,mins,maxs,minv,maxv;
void helptext()
{
cout << "B——黑色\n";
cout << "H——灰色\n";
cout << "W——白色\n";
cout << "R——红色\n";
cout << "O——橙色\n";
cout << "Y——黄色\n";
cout << "G——绿色\n";
cout << "L——蓝色\n";
cout << "P——紫色\n";
cout << "输入要求识别的颜色对应的字母:" ;
} void deal(char color)
{
switch(color){
case 'B':
minh = ;
maxh = ;
mins = ;
maxs = ;
minv = ;
maxv = ;
break;
case 'H':
minh = ;
maxh = ;
mins = ;
maxs = ;
minv = ;
maxv = ;
break;
case 'W':
minh = ;
maxh = ;
mins = ;
maxs = ;
minv = ;
maxv = ;
break;
case 'R':
minh = ;
maxh = ;
mins = ;
maxs = ;
minv = ;
maxv = ;
break;
case 'O':
minh = ;
maxh = ;
mins = ;
maxs = ;
minv = ;
maxv = ;
break;
case 'Y':
minh = ;
maxh = ;
mins = ;
maxs = ;
minv = ;
maxv = ;
break;
case 'G':
minh = ;
maxh = ;
mins = ;
maxs = ;
minv = ;
maxv = ;
break;
case 'L':
minh = ;
maxh = ;
mins = ;
maxs = ;
minv = ;
maxv = ;
break;
case 'P':
minh = ;
maxh = ;
mins = ;
maxs = ;
minv = ;
maxv = ;
break;
default:
cout << "输入错误" << endl;
exit();
}
} int main( )
{
VideoCapture capture();
Mat special;
helptext(); char color;
cin >> color;
deal(color);
while(){
Mat frame; //存储每一帧的图像
capture >> frame; //读取当前帧
Mat fhsv;
cvtColor(frame,fhsv,COLOR_BGR2HSV); //将图像转换为HSV模型 inRange(fhsv,Scalar(minh,mins,minv),Scalar(maxh,maxs,maxv),special); //找寻在要求区间内的颜色
imshow("ABC",special);
if(waitKey() >= )break;
} return ;
}
上一篇:Java基础系列3:多线程超详细总结


下一篇:php7.33 configure