Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

C++
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;
		}
Posted

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900