DETECTING AND BLUR THE FACE USING OPENCV AND PYTHON
The following python code shows the conversion process of the detected face to blur using the OpenCV module. The method is used to convert blur is GaussianBlur(Source, ksize, sigmaX).
source: The image.
ksize : (kernel.width, kernel.height). kernel width and kernel height can differ but they must be positive and odd.
source: The image.
ksize : (kernel.width, kernel.height). kernel width and kernel height can differ but they must be positive and odd.
Program :
import cv2
trainedDataset = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
img = cv2.imread("images/Elon Musk.jpg")
faces = trainedDataset.detectMultiScale(img)
for x, y, w, h in faces:
cv2.rectangle(img, (x, y, w, h), (50, 50, 50), 2)
img[y:y + h, x:x + w] = cv2.GaussianBlur(img[y:y + h, x:x + w], (93, 93), 0)
cv2.imshow("Image", img)
cv2.waitKey(0)
Output :
If you have any doubts in the code please refer face detection in image file using python.
Comments