Face identification box is too large, so the fixing function breaks hair and accessories #292

Open
opened 2026-01-29 21:46:32 +00:00 by claunia · 1 comment
Owner

Originally created by @grexzen on GitHub (Dec 16, 2022).

Is there a way to adjust the face identification to focus only on eyes or really only inside the face?

The current box is too large and breaks anything outside the face (hair accessory, earrings).

00005-240035775-mdjrny-v4 style, portrait of a male cleric, D D, fantasy, intricate, elegant, highly detailed, digital painting, artstation, con_00

Using a simpler but probably not generally accurate code we can find the eyes only.

But it has been hard to then run the fixing function through it.

localhost embedded

Any way to make the face identification much tighter or focus only on eyes?

Thanks!

Simple code to identify only eyes.

import facexlib
import tensorflow as tf
import cv2
from google.colab.patches import cv2_imshow

# Load the Haar cascade for detecting eyes
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')

# Read the image and convert it to grayscale
image = cv2.imread('img.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Adjust the scale factor and minimum neighbor count for the classifier
scale_factor = 1.33
min_neighbors = 18

# Detect eyes in the image
eyes = eye_cascade.detectMultiScale(gray, scale_factor, min_neighbors)

# Draw a rectangle around the eyes
for (x,y,w,h) in eyes:
    cv2.rectangle(image, (x,y), (x+w, y+h), (255,0,0), 2)

# Show the image
cv2_imshow(image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Originally created by @grexzen on GitHub (Dec 16, 2022). Is there a way to adjust the face identification to focus only on eyes or really only inside the face? The current box is too large and breaks anything outside the face (hair accessory, earrings). ![00005-240035775-mdjrny-v4 style, portrait of a male cleric, D D, fantasy, intricate, elegant, highly detailed, digital painting, artstation, con_00](https://user-images.githubusercontent.com/30579087/208147582-531a40d8-dc75-4d45-8744-26e5039d8491.png) Using a simpler but probably not generally accurate code we can find the eyes only. But it has been hard to then run the fixing function through it. ![localhost embedded](https://user-images.githubusercontent.com/30579087/208147787-c2f2394b-c71b-422e-926d-494f06641b63.png) **Any way to make the face identification much tighter or focus only on eyes?** Thanks! Simple code to identify only eyes. ``` import facexlib import tensorflow as tf import cv2 from google.colab.patches import cv2_imshow # Load the Haar cascade for detecting eyes eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') # Read the image and convert it to grayscale image = cv2.imread('img.png') gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Adjust the scale factor and minimum neighbor count for the classifier scale_factor = 1.33 min_neighbors = 18 # Detect eyes in the image eyes = eye_cascade.detectMultiScale(gray, scale_factor, min_neighbors) # Draw a rectangle around the eyes for (x,y,w,h) in eyes: cv2.rectangle(image, (x,y), (x+w, y+h), (255,0,0), 2) # Show the image cv2_imshow(image) cv2.waitKey(0) cv2.destroyAllWindows() ```
Author
Owner

@pmeems commented on GitHub (Jan 6, 2023):

I've got a similar question.
In my case the box used to fix the face is not nicely blend into the original (larger) image, resulting in a clearly visible square in my image.
Or can this be solved using another parameter or something?

@pmeems commented on GitHub (Jan 6, 2023): I've got a similar question. In my case the box used to fix the face is not nicely blend into the original (larger) image, resulting in a clearly visible square in my image. Or can this be solved using another parameter or something?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TencentARC/GFPGAN#292