def get_hsv_mask(img, debug=False):
assert isinstance(img, numpy.ndarray), 'image must be a numpy array'
assert img.ndim == 3, 'skin detection can only work on color images'
logger.debug('getting hsv mask')
lower_thresh = numpy.array([0, 50, 0], dtype=numpy.uint8)
upper_thresh = numpy.array([120, 150, 255], dtype=numpy.uint8)
img_hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
msk_hsv = cv2.inRange(img_hsv, lower_thresh, upper_thresh)
msk_hsv[msk_hsv < 128] = 0
msk_hsv[msk_hsv >= 128] = 1
if debug:
scripts.display('input', img)
scripts.display('mask_hsv', msk_hsv)
return msk_hsv.astype(float)
评论列表
文章目录