如何从图像中选择皮肤?

2024-06-23 19:48:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从图像中选择手。我所发现的只是定制像素颜色。我在这方面有没有更好的方法或改进

我尝试了从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

以下是不太好的结果


Tags: thetopathimgnpmaskarraycv2

热门问题