首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CVLIB -如何将模糊的子面添加到原始图像?

CVLIB -如何将模糊的子面添加到原始图像?
EN

Stack Overflow用户
提问于 2020-09-26 01:29:45
回答 1查看 35关注 0票数 1

朋友们,我需要实现一个代码,从给定的图像中模糊人脸(我不是开发人员,所以这对我来说真的很难)。我发现我可以使用OpenCV和cvlib来完成这项工作,并找到了一个示例代码(来自cvlib的存储库),它完成了部分工作。

我知道我需要得到子面孔,并将面部模糊应用于它们,我可以做到这一点,但现在我不知道如何将模糊的脸添加到原始图像中。有人能帮我一下吗?

代码语言:javascript
复制
import cvlib as cv
import sys
from cv2 import cv2
import os 

# read input image
image = cv2.imread('path')

# apply face detection
faces, confidences = cv.detect_face(image)

print(faces)
print(confidences)

# loop through detected faces
for face,conf in zip(faces,confidences):

    (startX,startY) = face[0],face[1]
    (endX,endY) = face[2],face[3]

    subFace = image[startY:endY,startX:endX]
    subFace = cv2.GaussianBlur(subFace,(23, 23), 30)
# display output
# press any key to close window           
cv2.imshow("face_detection", image)
cv2.waitKey()

cv2.imshow("face_detection", subFace)


# release resources
cv2.destroyAllWindows()
EN

回答 1

Stack Overflow用户

发布于 2020-09-26 05:28:45

我终于想出了怎么做:

代码语言:javascript
复制
import cvlib as cv
import sys
from cv2 import cv2
import os 

# read input image
image = cv2.imread('path')

# apply face detection
faces, confidences = cv.detect_face(image)

# print the array with the coordinates and the confidence
print(faces)
print(confidences)

# loop through detected faces
for face,conf in zip(faces,confidences):

    (startX,startY) = face[0],face[1]
    (endX,endY) = face[2],face[3]
    
    # get the subface
    subFace = image[startY:endY,startX:endX]
    # apply gaussian blur over subfaces
    subFace = cv2.GaussianBlur(subFace,(23, 23), 30)
    # add the subfaces to de original image
    image[startY:startY+subFace.shape[0], startX:startX+subFace.shape[1]] = subFace
         
cv2.imshow("face_detection", image)
cv2.waitKey()

# save output
cv2.imwrite("face_detection.jpg", image)

# release resources
cv2.destroyAllWindows()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64068825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档