使用c ++中的opencv识别不同颜色的对象 [英] Identifying objects of different colour using opencv in c++

查看:554
本文介绍了使用c ++中的opencv识别不同颜色的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我对基于颜色的物体检测和跟踪有一点疑问。我编写了一个程序,它基本上可以检测蓝色,绿色,红色,黄色并实时跟踪它。现在,问题是我想确定哪个对象是什么颜色基本上我的意思是当我拿着相机前面的蓝色物体时,我的程序应该说能够说出它的蓝色。现在,我的想法是使用HSV值我可以分离不同颜色的对象并识别它们。这是我尝试但它似乎没有工作。我该如何解决这个问题呢?



  if (标量(H_MIN) ,S_MIN,V_MIN)==标量( 51  153  0 )&& Scalar(H_MAX,S_MAX,V_MAX)==标量( 154  255  256 ))
{
cout<< 它是一个蓝色物体<< endl;
}

if (标量(H_MIN,S_MIN,V_MIN)==标量( 0 172 63 )&&& Scalar(H_MAX,S_MAX,V_MAX )==标量( 179 256 153 ))
{
cout<< 它是一个红色对象<< ENDL;
}

解决方案

是==比较对吗?如果((标量(H_MIN,S_MIN,V_MIN)> =标量(51,153,0))&&(&#;标量(H_MAX,S_MAX,V_MAX)< =标量(154,255,256)))
{
cout<<它是一个蓝色物体<< endl;
}





并且为了清晰起见还添加一些()括号。



另请参阅此openCV 文章


So, I have a little query regarding color based object detection and tracking. I have written a program which basically detects blue,green,red,yellow color and tracks it in real time. Now, here is the problem say i want to identify which object is of what color basically what i mean to say is that when i hold a blue object infront of the camera, my program should say be able to say its "blue". Now, my idea is that using the HSV values i can separate objects of different color and identify them. This is what i tried but it doesnt seem to work. How can i resolve this issue?

if(Scalar(H_MIN,S_MIN,V_MIN) == Scalar(51,153,0) && Scalar(H_MAX,S_MAX,V_MAX) == Scalar(154,255,256))
		{
			cout<<"Its a blue object"<<endl;
		}

if(Scalar(H_MIN,S_MIN,V_MIN) == Scalar(0,172,63) && Scalar(H_MAX,S_MAX,V_MAX) == Scalar(179,256,153))
		{
			cout<<"Its a red object"<<endl;
		}

解决方案

is the == comparison right? I would

if( (Scalar(H_MIN,S_MIN,V_MIN) >= Scalar(51,153,0)) && (Scalar(H_MAX,S_MAX,V_MAX) <= Scalar(154,255,256)) )
{
	cout<<"Its a blue object"<<endl;
}



and also add some () brackets for clarity.

Take also a look on this openCV article.


这篇关于使用c ++中的opencv识别不同颜色的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆