face_classification icon indicating copy to clipboard operation
face_classification copied to clipboard

Face next to frame edge problems.

Open mirceaciu opened this issue 7 years ago • 9 comments

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.

mirceaciu avatar Oct 24 '17 10:10 mirceaciu

onTopic: the first issus is cause of gender_offsets = (30, 60). Guess it's there for a reason

mirceaciu avatar Oct 24 '17 11:10 mirceaciu

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?

oarriaga avatar Nov 02 '17 17:11 oarriaga

/src/video_emotion_gender_demo.py.

mirceaciu avatar Nov 03 '17 08:11 mirceaciu

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)

mirceaciu avatar Nov 28 '17 14:11 mirceaciu

Hello mirceaciu...could you share with me changes in /src/video_emotion_gender_demo.py...

fadsamo avatar Jan 15 '18 04:01 fadsamo

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!

LeeCheer00 avatar Aug 02 '18 07:08 LeeCheer00

I tried the utils. opencv-utils, both of them don't work. Could you give some advices?

LeeCheer00 avatar Aug 02 '18 07:08 LeeCheer00

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 avatar Apr 04 '19 15:04 KJhari

@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.

mirceaciu avatar Apr 04 '19 19:04 mirceaciu