Skin Segmentation
Module: Computer Vision | Difficulty: Beginner
Skin Color Models
YCbCr Space
Skin clusters in a compact region: and .
HSV Space
Gaussian Model
import cv2
import numpy as np
def detect_skin_ycbcr(img):
ycbcr = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)
lower = np.array([0, 133, 77])
upper = np.array([255, 173, 127])
mask = cv2.inRange(ycbcr, lower, upper)
return mask
def detect_skin_hsv(img):
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
lower = np.array([0, 58, 30])
upper = np.array([50, 174, 255])
mask = cv2.inRange(hsv, lower, upper)
return mask
Key Takeaways
- Skin segmentation is fundamental for face/hand detection
- YCbCr and HSV spaces provide robust skin color modeling
- Illumination changes require adaptive thresholds