用cv2模糊部分图像后的锐利边缘

2024-06-23 19:50:42 发布

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

要在该图像上使用python和hsm来检测图像,请执行以下操作:

original image

# "org" is the original image, i convert it to HSV color and save in "frame"
frame = cv2.cvtColor(org, cv2.COLOR_BGR2HSV)

# then using "cv2.inRange" to find skin part
v1_min, v2_min, v3_min = 6, 36, 89
v1_max, v2_max, v3_max = 27, 255, 255

skinmask = cv2.inRange(frame, (v1_min, v2_min, v3_min), (v1_max, v2_max, v3_max))
clothmask = 255 - skinmask

# save skin part of image in "skin" and others in "cloth"
cloth = cv2.bitwise_and(org, org, mask=clothmask)
skin = cv2.bitwise_and(org, org, mask=skinmask)

# color around the skin is black after mask apply. 
#so change it to a color near white human skin color to prevent black edges after blur
skin[skinmask == 0] = (24 * 5, 35 * 5, 220)

# now blur the skin part
skin = cv2.blur(skin, (30, 30))

# apply "skinmask" to skin part after blur
skin = cv2.bitwise_and(skin, skin, mask=skinmask)

# put the cloth and skin together
result = cv2.bitwise_or(skin, cloth)

result image

我不知道为什么皮肤周围的边缘太差了。 你知道问题是来自我的皮肤选择方法还是模糊或其他什么吗?在

谢谢


Tags: andthetoorgimagev3mincv2

热门问题