Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python CVLIB-如何将模糊子面添加到原始图像?_Python_Opencv_Computer Vision_Cvlib - Fatal编程技术网

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

Python CVLIB-如何将模糊子面添加到原始图像?,python,opencv,computer-vision,cvlib,Python,Opencv,Computer Vision,Cvlib,朋友们,我需要实现一个代码,从给定的图像中模糊人脸(我不是开发人员,所以这对我来说非常困难)。我发现我可以使用OpenCV和cvlib来完成这项工作,并找到了一个示例代码(cvlib中的存储库),它完成了部分工作 我知道我需要获得子面并对其应用面部模糊,我可以做到,但现在我不知道如何将模糊的面部添加到原始图像中。有人能帮我吗 import cvlib as cv import sys from cv2 import cv2 import os # read input image image

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

我知道我需要获得子面并对其应用面部模糊,我可以做到,但现在我不知道如何将模糊的面部添加到原始图像中。有人能帮我吗

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()

我终于想出了办法:

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()