app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import cv2 # Load the image image = cv2.imread("bg.jpg") # Load Haar cascade for face detection (included with OpenCV) face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml") # Convert to grayscale for detection gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Detect faces faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5) # Draw black circles over each face for (x, y, w, h) in faces: center = (x + w // 2, y + h // 2) radius = max(w, h) // 2 cv2.circle(image, center, radius, (255, 255, 255), thickness=-1) # filled black circle # Save result cv2.imwrite("faces_hidden.jpg", image) print("Faces have been hidden and saved as faces_hidden.jpg") |