Thresholding an HSV image
Hello, I have a skin detection code which get the skin region from an HSV image. I want to threshold it to a binary image. Here's a sample output-
I want the image on the right to be a binary image. The following snippet returns an error-
frame = cv2.resize(frame,(100,100))
converted = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
skinMask = cv2.inRange(converted, l1, l2)
# using an elliptical kernel
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,5))
skinMask = cv2.erode(skinMask, kernel, iterations = 2)
skinMask = cv2.dilate(skinMask, kernel, iterations = 2)
# blur the mask to help remove noise, then apply the
# mask to the frame
skinMask = cv2.medianBlur(skinMask, 3)
skin = cv2.bitwise_and(frame, frame, mask = skinMask)
#This is my addition that causes error
skin = cv2.cvtColor(skin,cv2.COLOR_HSV2BGR)
skin = cv2.threshold(skin,10,255,cv2.THRESH_BINARY )
skin = cv2.cvtColor(skin,cv2.COLOR_BGR2HSV)
# # show the skin in the image along with the mask
cv2.imshow("images", np.hstack([frame,skin]))
How do I get a binary version of skin image?
" The following snippet returns an error-" And the 1million $-question is: "WHICH ERROR?"
you already got the 'skinMask'. use that !