gpt4 book ai didi

python - 如何在带有圆形边框的opencv中模糊人脸 - Python?

转载 作者:行者123 更新时间:2023-12-02 16:14:42 26 4
gpt4 key购买 nike

我像这样在 OpenCV 中模糊了脸:

Image

我使用了这段代码:

face = cv2.medianBlur(face, 100) 
img[top:bottom,left:right] = face

但是我想让脸边框像这样圆(不需要很完美)

Output image

最佳答案

首先,创建一个蒙版图像。为此,请在黑色图像上的面部位置绘制一个白色圆圈。

其次,模糊整个图像。

第三,仅在掩码大于 0 的位置将模糊内容复制到原始图像。

p1 = (65, 65)
w, h = 100, 100
p2 = (p1[0] + w, p1[1] + h)


circle_center = ((p1[0] + p2[0])// 2, (p1[1] + p2[1]) // 2)
circle_radius = int(math.sqrt(w * w + h * h) // 2)
mask_img = np.zeros(img.shape, dtype='uint8')
cv2.circle(mask_img, circle_center, circle_radius, (255, 255, 255), -1)

img_all_blurred = cv2.medianBlur(img, 99)
img_face_blurred = np.where(mask_img > 0, img_all_blurred, img)

输出:

enter image description here

关于python - 如何在带有圆形边框的opencv中模糊人脸 - Python?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60910559/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com