Question

Currently I am using a HaarCascade to detect a face in a picture. Which is working, I am getting a rect of where the face is.

Now I want to get the "average?" (skin color) in that rect. And use that as a base for the color range to search for other skin in the photo. How should I go about that?

I have found the inRange function, which searches for a color in a range. But I am not quite sure how I could get the average color of my skin in there. It seems that the inRange function needs HSV values? However, I don't know quite what that format is. It doesn't seem to be the same as HSB in photoshop. (Which I tried for "testing purposes").

My question boils down to this, how can I get the "average" color in a rect, and find other colours in that range (e.g, lighter and darker than that color, but the same shade).

Thanks.

Was it helpful?

Solution

Get the 3D color histogram within the detected region of interest. That is, not three 1D histograms for each channel, but one 3D histogram for all 3 channels together. OpenCV's calcHist has options for that. Here's an example which does that. This example is using Python bindings for OpenCV, but it shows how to set the parameters.

Also, set the range of the histogram within a reasonable range for skin color. As MSalters suggested in the comments, HSV is a better color space for things like this. Perhaps you can disregard the S and V channels and only do the 1D histogram for V. Try is out.

The bin with the highest count is going to be your "average" skin color.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top