How to find RGB/HSV color parameters for color tracking?
I would like to track a color in a set of images. For this reason I use the algorithm of constant thresholding mentioned in Introduction to Autonomous Mobile Robots. This method simply marks all those pixels that are among a mini开发者_StackOverflow社区mum and a maximum threshold of red, green, blue (or hue, saturation, value in my case).
My problem is that - although HSV is less sensitive to changing light conditions - I still would like to set the thresholds from program to minimize the number of false positives and false negatives. In other words the algorithm would ensure that only a given set of pixels is marked in the end, for example a rectangle on a calibration image.
I know that the problem is a search in a 6-dimensional parameter space and I could come up with possible solutions but I am looking for other programmers' opinion and experience on this subject.
If that matters I try to implement it in C++ with OpenCV.
As far as I understand the question you are looking for procedure to calibrate 6 thresholds (min and max for each of the HSV channels) from a calibration image that contains your tracking marker. To achieve this I would:
- first manually delineate the region, in the calibration image, where the marker appears
- calculate that region's histograms, one for each of the HSV channels
- set the min and max thresholds to the histogram percentiles 0.05 and 0.95 respectively
Not using the histogram's minimum and maximum values, but rather its 0.05 and 0.95 percentiles helps the measure be more robust to noise.
EDIT:
A modification of the second step: If you want to minimize the error, you could establish a normilzed histogram of the marker and a normalized histogram of the environment (this can be 2 separate images) and subtract the latter from the first. The resulting marker histogram will have background pixel values attenuated. This will affect the values of the above mentioned percentiles.
精彩评论