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 !!!
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%).
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.
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.
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.
As you can see in this pic, the red range is somewhere between 350 to 20.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With