Ask Your Question
1

How to specifically know the HSV value of an object from webcam

asked 2014-01-27 05:57:54 -0600

m working on a project that need HSV color threshold for color segmentation. i find the threshold using this function

IplImage* GetThresholdedImage(IplImage* imgHSV){       
    IplImage* imgThresh=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1);
    cvInRangeS(imgHSV, cvScalar(170,160,60), cvScalar(180,2556,256), imgThresh); 
    return imgThresh;
}

my problem is the color is often not detected when i run the project in the morning, noon or night. And i have to find the range manually and input it again in my code which is tiresome.

Is there any way to automatically find the color threshold of my object. Lets say i need to find red object.

Thank you for your attention. i waited for any of your response

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-01-27 08:04:29 -0600

Ben gravatar image

No. Color is not an attribute an object does have in real world. It only has a surface that absorbs/rejects certain light frequencies. And depending on the light source that illuminates the object, it will appear to you as green, red or whatever color you perceive. For example a white wall only appears white in sunlight. If you only have a red light bulb as light source, guess what color the wall will have... Now how should a camera know that in sunlight that wall appears white? If you check the pixel's values you will get red as predominant color.

Ok, usually cameras have something called automatic white balance, which tries to guess, what light conditions you have when taking the picture and then corrects the colors towards neutral (sun)light. But this will never work as good as you might need it to get the same RGB values under every light condition for your object.

What you can do is training your system. If, for example, the light conditions only depend on the time (you always have the same light conditions at 6pm) then just measure your object's color values at different times and analyze your image taken at a certain time with the corresponding values.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-01-27 05:57:54 -0600

Seen: 1,302 times

Last updated: Jan 27 '14