-
-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created and implemented Overlay face function #3241
base: main
Are you sure you want to change the base?
Conversation
I'm concerned about the memory usage of numpy, is there a way to know how much more memory this will consume? |
@DonnieBLT sir, I'm unsure of why pre-commit test is failing continuously even though I'm running pre-commit everytime before committing the changes. Please suggest what should I do to resolve this, thank you! ![]() |
I've added |
Can you please add an automated test to this so that it starts with a face, then upload it to an issue and then check the issue and make sure that it does not detect a face |
It’s precommit formatting |
sure sir, I'll do that. thank you! |
@DonnieBLT sir, can you please explain what was required to be done here? |
Create a test |
@DonnieBLT sir, please review the changes. thank you! Screen.Recording.2025-02-05.at.5.46.25.PM.mov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove unused, dependencies, and separate the functionality into a new PR if it’s still there
@DonnieBLT ![]() after downloading dependencies: (opencv-python, numpy): ![]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets do this without 3rd party dependencies - something like this
import os
import urllib.request
from xml.etree import ElementTree
from PIL import Image, ImageDraw
# Load the Haar cascade file (pre-trained model for face detection)
HAAR_CASCADE_URL = "https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_frontalface_default.xml"
HAAR_CASCADE_PATH = "haarcascade_frontalface_default.xml"
# Download Haar cascade if not exists
if not os.path.exists(HAAR_CASCADE_PATH):
urllib.request.urlretrieve(HAAR_CASCADE_URL, HAAR_CASCADE_PATH)
# Parse Haar cascade XML file
def parse_haar_cascade(xml_path):
"""Parses Haar cascade XML and extracts feature rectangles."""
tree = ElementTree.parse(xml_path)
root = tree.getroot()
features = []
for stage in root.findall(".//stages/_/trees/_/feature/rects/_"):
feature_rects = []
for rect in stage.text.strip().split("\n"):
rect = rect.split()
x, y, w, h = map(int, rect[:4])
feature_rects.append((x, y, w, h))
features.append(feature_rects)
return features
# Face detection function using Haar features
def detect_faces(image):
"""Detect faces in an image using Haar features."""
width, height = image.size
features = parse_haar_cascade(HAAR_CASCADE_PATH)
detected_faces = []
for x in range(0, width - 24, 2): # Scanning the image
for y in range(0, height - 24, 2):
for feature in features:
if all(x + w < width and y + h < height for (_, _, w, h) in feature):
detected_faces.append((x, y, 24, 24)) # Assume minimum size of 24x24 pixels
return detected_faces
# Function to blur detected faces
def blur_faces(image, faces):
"""Apply a blur effect on detected faces."""
draw = ImageDraw.Draw(image)
for x, y, w, h in faces:
for i in range(5): # Create blur effect using rectangles
draw.rectangle([x + i, y + i, x + w - i, y + h - i], fill=(200, 200, 200, 128))
return image
# Load the image
image_path = "test_image.jpg" # Replace with your image path
image = Image.open(image_path).convert("RGB")
# Detect faces
faces = detect_faces(image)
# Apply blur
processed_image = blur_faces(image, faces)
# Save or show the processed image
processed_image.show() # Display the image
processed_image.save("blurred_faces.jpg") # Save the processed image
Closes: #2527
#3243
I've also made changes to
delete_issue
function to reduce time complexity and better optimisationScreen.Recording.2025-01-19.at.6.10.46.PM.mov