Exact Skin color HSV range

2019-03-11 16:40发布

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 !!!

7条回答
孤傲高冷的网名
2楼-- · 2019-03-11 16:59

I know it is too late to reply to this. But I am doing the same, and I used K means clustering to get the skin color. That is first you have to Detect the face, which I am doing with the use of Haar cascade classifier, and then based on the coordinates of the face you can crop the face and then use it as the source to cluster the color. Find out the cluster that has the most elements and that will be your skin color. Or without specifying one particular value you can get the cluster center point and you can use it as a range by deducting and adding a particular value. This will be helpful http://answers.opencv.org/question/23196/k-mean-clustering-of-hsv-histogram-of-frames-of-a-video/

查看更多
放荡不羁爱自由
3楼-- · 2019-03-11 17:00

Try this preprocessing function in your code:

def preprocess(action_frame):

    blur = cv2.GaussianBlur(action_frame, (3,3), 0)
    hsv = cv2.cvtColor(blur, cv2.COLOR_RGB2HSV)

    lower_color = np.array([108, 23, 82])
    upper_color = np.array([179, 255, 255])

    mask = cv2.inRange(hsv, lower_color, upper_color)
    blur = cv2.medianBlur(mask, 5)

    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (8, 8))
    hsv_d = cv2.dilate(blur, kernel)

return hsv_d

I have been using this for months now. It might solve your problem forever.

查看更多
SAY GOODBYE
4楼-- · 2019-03-11 17:11

Adaptive skin detector exist on OpenCv see samples/c/adaptiveskindetector_sample.cpp

查看更多
The star\"
5楼-- · 2019-03-11 17:11

And if you are using video caption, you should be concerned that in most of the cases the cameras make an automatic contrast adjust, this impact in your images because you are going to have a significant difference of tones, also you should consider the shadows and light sources that impact in the skin

查看更多
forever°为你锁心
6楼-- · 2019-03-11 17:16

I have tried
lower = np.array([0, 10, 60], dtype = "uint8") upper = np.array([20, 150, 255], dtype = "uint8") It gives almost good result .

查看更多
祖国的老花朵
7楼-- · 2019-03-11 17:22

Basically, it's hard to have one fixed color range for skin, because even if you want to detect only your own skin, its color will actually change a lot depending on lighting conditions.

So, maybe you can use the idea of this nice scientific article from 2011:

http://www.robots.ox.ac.uk/~vgg/research/hands/

Basically, they detect face (it's easy with oepncv). Then they extract the skin color of the face (which is very specific to the persons on the image). Then they detect skin using this color. Since the color is very specific, they should have much less false detection, than what you have with your fixed color range.

查看更多
登录 后发表回答