Friday, April 3rd, 2009, 1142 days ago

Color recognition using openCV 2

colorrect

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);


14 Responses to “Color recognition using openCV 2”

  1. Idaho says:

    Hi
    I have a problem with recognize color. Please send me all code. Thanks for HELP. :)

  2. fireball says:

    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!

  3. H.Hamdy says:

    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

  4. bvhoang says:

    hi Andol, i find that this program is very useful for the people who want to start with opencv, but i wonder that if the code in pdf file is full, i debug it, but there is nothing happen, would you mind if i ask you to tell me the way to run this program. I’m a new comer with opencv. For example: which lib we have to add to input to the input (linker) in the project properties… I’ve added the lib from Opencv to C++.(include, Lib already)
    thanks a lot for your help!!!

    • Andol says:

      It is the full code, but, some parameters such like the source image and target colour detection need to be adjusted due to different application environments. Have another try, might work with different parameters.

  5. bvhoang says:

    oh, i use Opencv 1.1 with VS C++ 2008.
    thank you for your time^^.

  6. bvhoang says:

    thank you so much Andol, it was my honour when you replied to me when i’ve just asked, actually, i’m taking a thesis with opencv, but i don’t really know much about iit, i am trying to recognise the basic color as you told, but i don’t really know what to do at first in the code, could you help me with the way to solve the problem. i mean the algorithms.
    thank you for your time.

  7. swatz says:

    newby : Thanks a lot for this site (and codes/ideas)

  8. xdfuji says:

    thank you very much
    it very useful

  9. [...] numerous other monster beats by dr. dre pro studio price methods already issue they're also . hi – d beats by dre oscar de la renta mementos towel beats by dre in soho high tech a person monster beats soho always remember obligation [...]

  10. Pamela says:

    Hi,

    Can you upload the code again? It seems that it has been deleted from the previous server.

    Thanks in advanced

Leave a Reply

You can use these XHTML tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>