如何从图像中选择皮肤?

时间:2019-04-12 20:51:52

标签: python python-3.x image cv2

我想从图像中选择手。我发现的只是捕捉像素颜色。我有什么更好的方法或可以做些改进吗?

我尝试了从RGB / BGR到HSV的转换,结果对于我的数据集来说并不是很好。

img_path = r"E:\HandmadeDataset\dataset5\A\a\color_0_0034.png"

lower = np.array([0, 30, 55], dtype = "uint8")   #[0, 30, 60] 
upper = np.array([185, 255, 220], dtype = "uint8") #[185, 255, 220]

frame = cv2.imread(img_path)
frame = imutils.resize(frame, width = 200)
converted = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

skinMask = cv2.inRange(converted, lower, upper)

# apply a series of erosions and dilations to the mask
# using an elliptical kernel
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (11, 11))
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.GaussianBlur(skinMask, (3, 3), 0)
skin = cv2.bitwise_and(frame, frame, mask = skinMask)

# show the skin in the image along with the mask
cv2.imshow("images", np.hstack([frame, skin]))
cv2.waitKey(0)
cv2.destroyAllWindows()

原件: https://ibb.co/QXQbfg7

失败的尝试: https://ibb.co/2jkHprc

这不是很好的结果

0 个答案:

没有答案