Friday, April 3rd, 2009, 1044 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);
POSTS MAY BE OF INTEREST
- Doing openCV in pandaboard 3 – successful installation
- Doing openCV in Pandaboard
- Hand gesture recognition for HCI
- Hand detection and image recognition
- Coming soon: A review of openCV detection & recognition
- Pattern recognition and applications
- Object tracking using AS3
- Interactive table
- Touchable holography
- About the codes sharing
- Usability of comsumer electronic products
- Rules of memory management of openCV
- Recognizing circles accurately
- Do we need more novel interaction methods?
- Hand detection using openCV

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
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!!!
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.
oh, i use Opencv 1.1 with VS C++ 2008.
thank you for your time^^.
Thank you bvoang.
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.
newby : Thanks a lot for this site (and codes/ideas)
thank you very much
it very useful