Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect skin color from live camera preview android

I am trying to build an app which can detect skin color of different parts of skin ( hand, forehead, cheeks ) regardless of lighting condition. I am able to do it using this project but its not taking care of lighting conditions. This is one of the Iphone app which does that

like image 714
Smogger Avatar asked Dec 19 '25 00:12

Smogger


1 Answers

In case you want to do some image processing on your own, i would recommend to create a histogram for each face region of your image. As long as opencv is capable of detecting the face, you should be able to normalize the histogram in that region and take the color values of the normalized version.

Maybe you want to normalize all channels (R,G,B) separately to reduce influences of colored light.

Read here for further information on histograms: https://en.wikipedia.org/wiki/Histogram

When you follow that way, I strongly recommend to take one face as a whole region to create the histogram(s) for.

[Edit]

Now that I know what you try to do, I think you can take the following approach:

As you can see, the user needs to tap the camera fore and back. As the image is lit by the backside-led of the phone, the histogram is indeed exactly what the creators of that app are creating. However, not from different pixels but from different samples of the same pixel using different lighting levels.

When you are very close to the skin, the camera will show you a nearly white image, that is, if you like, the "fixed point" for the histogram calculation.

Although I am not going to show direct code, I will try to explain the mathematical model:

  • Define a "focus" region in your image. This region is the area you take into account when calculating your histogram. All other regions at the edge will be ignored.
  • Take some samples (e.g. 3 seconds, 10 samples per second = 30 samples)
  • create a histogram of each sample and add them together:
    • For each lightness-value (there are maximal 256 of them) count the number of pixels that match this value, add all samples together
    • Find out the highest and lowest value that has at least a threshold number of values (your "working" range if you like) and call them histLow and histHigh
    • Recalculate each pixel so that pixel = (pixel-histLow) / (histHigh-histLow) * 255
    • Constrain the pixel value to the range 0 - 255
    • Take the average color value the pixels around a narrower range (e.g. only the highest number of samples)

If you don't know how to multiply or add colors in RGB, that's where you should start with a different question.

like image 104
Psi Avatar answered Dec 20 '25 15:12

Psi