Friday, April 3rd, 2009, 342 days ago
Color recognition using openCV 2
Related Post: Color recognition using openCV
Recognising colors in computer vision using openCV is not so complicated as it is expected. Actually, getting the capture image from webcam or some other advanced cameras, converting the color from RGB to HSV or HSI( not sure it is right ), and extracting the specific color(s) from the converted image, that is done. After that, some filters like CVSMOOTH, CANNY and CVTHRESHOLD can be applied to take off the noises in the previous image.
Give some codes here :
IplImage* src = cvCreateImage( sz, 8, 3 );
IplImage* hsv_image = cvCreateImage( sz, 8, 3);
IplImage* hsv_mask = cvCreateImage( sz, 8, 1);
IplImage* hsv_edge = cvCreateImage( sz, 8, 1);
CvScalar hsv_min = cvScalar(0, 80, 80, 0);
CvScalar hsv_max = cvScalar(20, 150, 255, 0);
/*——————————————*/src = cvQueryFrame( capture);
cvCvtColor(src, hsv_image, CV_BGR2HSV);
cvInRangeS (hsv_image, hsv_min, hsv_max, hsv_mask);
cvSmooth( hsv_mask, hsv_mask, CV_MEDIAN, 13, 0, 0, 0 );
cvCanny(hsv_mask, hsv_edge, 1, 3, 5);






Hi
I have a problem with recognize color. Please send me all code. Thanks for HELP.
you can refer here: http://img.andol.info/2009/02/colorrecg.pdf
hi,i am so happy to find your blog,there are so many code and method which are just what i want.Thank you for your sharing ! One problem is i conld not download the source code ,could you solve it or tell me why!Waiting for your reply!
hi,ur code was very useful for me ,i need to know the position of this object
for(int i = 1;i < sz.height; i++)
{
for(int j = 1;j <sz.width; j++)
{
if (cvGet2D(hsv_mask,i-1,j).val==s.val &&cvGet2D(hsv_mask,i,j).val==s.val&&cvGet2D(hsv_mask,i+1,j).val&&cvGet2D(hsv_mask,i,j-1).val==s.val&&cvGet2D(hsv_mask,i,j).val==s.val&&cvGet2D(hsv_mask,i,j+1).val)
{
select_object=1;
selection.width=30;
selection.height=30;
selection.x=i;
selection.y=j;
}
i trying this code but it fails