Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exact Skin color HSV range

I have seen all questions on SO for range of HSV color space for skin
But I can only figure out this

Code -

CvScalar  hsv_min = cvScalar(0, 30, 60, 0);
CvScalar  hsv_max = cvScalar(20, 150, 255, 0);
//range I am using is { 0,30,60,0 & 20,150,255,0 }
cvCvtColor(src, hsv_image, CV_BGR2HSV);
cvInRangeS (hsv_image, hsv_min, hsv_max, hsv_mask);
cvDilate(hsv_mask,hsv_mask,0,1);
cvErode(hsv_mask,hsv_mask,0,1);
cvSmooth( hsv_mask, hsv_mask, CV_MEDIAN);

Problem with this range ( { 0,30,60,0 & 20,150,255,0 } ) is it detects even red color and when you place your hand in red background it does not track your skin...
Please Help !!!

like image 372
Wazy Avatar asked Jan 06 '12 05:01

Wazy


People also ask

What is the HSV for skin color?

HSV stands for Hue (color / hue), Saturation (saturation), Value /Luminance (lightness / luminosity / luminosity, not to be confused with brightness). Hue sets the position of the color on the color wheel (from 0' to 360'). Saturation is a percentage of saturation (0% to 100%).

What is the range of HSV values?

It ranges from 0 to 255, with 0 being completely dark and 255 being fully bright. 4) White has an HSV value of 0-255, 0-255, 255.

What is the color code for skin tone?

Skin color code RGB A typical natural skin color codes RGB values are (232, 190, 172). This represents a natural skin tone color and be used for general purposes.

What is skin tone detection?

Skin detection is the process of finding skin-colored pixels and regions in an image or a video. This process is typically used as a preprocessing step to find regions that potentially have human faces and limbs in images. Several computer vision approaches have been developed for skin detection.


1 Answers

This is one of the ideal solution for skin detection..

Most of the answers above work for variety of skin colors like dark red, light yellow, light orange, .... But these colors are not supposed to be skin colors as they are barely seen in images.

As you can see in this pic, the red range is somewhere between 350 to 20. enter image description here

So there are two possible ranges of Hue for skins.

HSV range

#1st range of Hue
lower -> [0, 30, 53]
upper -> [20, 150, 255]

#2nd range of Hue (OpenCV converts 360 to 180)
lower2 -> [172, 30, 53]
upper2 -> [180, 180, 210]

Full code:

import os, cv2
import numpy as np

image = cv2.imread(os.path.join('skin.png'))

# Covers both range
lower = np.array([0, 30, 53], dtype = "uint8")
upper = np.array([20, 180, 255], dtype = "uint8")

lower2 = np.array([172, 30, 53], dtype = "uint8")
upper2 = np.array([180, 180, 210], dtype = "uint8")

converted = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

skinMask = cv2.inRange(converted, lower, upper)
skinMask2 = cv2.inRange(converted, lower2, upper2)

#Gaussian Blur
skinMask = cv2.GaussianBlur(skinMask, (3, 3), 0)
skinMask2 = cv2.GaussianBlur(skinMask2, (3, 3), 0)

skin1 = cv2.bitwise_and(image, image, mask = skinMask)
skin2 = cv2.bitwise_and(image, image, mask = skinMask2)
skin = cv2.bitwise_or(skin1,skin2) #adding both ranges

# show the skin in the image along with the mask
cv2.imshow("images", np.hstack([frame, skin]))
cv2.waitKey(0)
like image 149
Prakash Dahal Avatar answered Oct 19 '22 15:10

Prakash Dahal