face_classification
face_classification copied to clipboard
Face next to frame edge problems.
The code works great, I've used the python part as is.
One issue that comes up is when a face bounding box comes close to one of the frame edges. This will raise :
OpenCV Error: Assertion failed (ssize.width > 0 && ssize.height > 0) in resize, file /home/user/opencv-3.2.0/modules/imgproc/src/imgwarp.cpp, line 3492
Another would be when the bounding box comes near the bottom edge of the frame it will detect a 'female' regarding the actual gender.
I can make some adjustments so that faces near frame edges be ignored, but this would reduce the camera's field of vision.
onTopic: the first issus is cause of gender_offsets = (30, 60)
. Guess it's there for a reason
thank you @mirceaciu for your interest in the code, I didn't want to deal explicitly with the box offsets being bigger than the image; therefore, I just skip the frame inference by wrapping the opencv resize function with a try/exception. In which example was this happening?
/src/video_emotion_gender_demo.py
.
To make things a bit dynamic in my code I use the following:
for starters I know the face bounding box width and height:
for detected_face in detected_faces:
face_coordinates = make_face_coordinates(detected_face)
x, y, face_width, face_height = face_coordinates
Now to calculate the offsets I will:
- for x offset : 20% from face width
- for y offset: calculate half of face height
Now, before cropping a ROI with rgb_face = rgb_image[y1:y2, x1:x2]
I will test if the above offsets fall inside the frame width and height.
To calculate percentage:
def percentage(percent, whole):
return (percent * whole) / 100.0
So gender offsets could be:
gender_offsets = (int(percentage(20, face_width)), face_height/2)
Hello mirceaciu...could you share with me changes in /src/video_emotion_gender_demo.py...
The code in video_emption_gender_demo.py : line7: from utils.datasets import get_labels , what's the name of package ? how can i install it?thx!
I tried the utils. opencv-utils, both of them don't work. Could you give some advices?
To make things a bit dynamic in my code I use the following:
for starters I know the face bounding box width and height:
for detected_face in detected_faces: face_coordinates = make_face_coordinates(detected_face) x, y, face_width, face_height = face_coordinates
Now to calculate the offsets I will:
- for x offset : 20% from face width
- for y offset: calculate half of face height
Now, before cropping a ROI with
rgb_face = rgb_image[y1:y2, x1:x2]
I will test if the above offsets fall inside the frame width and height.To calculate percentage:
def percentage(percent, whole): return (percent * whole) / 100.0
So gender offsets could be:
gender_offsets = (int(percentage(20, face_width)), face_height/2)
Hi mirceaceu,
can you share the code which you changed?
@KJhari sorry. I did not touch this since I posted the comment and for sure don't remember what I was doing back then. project is long gone too.