Home > front end >  Face Detection without cutting the head
Face Detection without cutting the head

Time:12-07

I have tried several libraries and ways to detect faces and export them as an image. The problem is that all the algorithms are cutting a lot of the head. Example from the enter image description here

While I want something like:

enter image description here

Is there a way of doing so? Or adding "padding" to the coordinates in a smart way?

I get start and end points.

CodePudding user response:

I build a function to do that with simple math:

def increase_rectangle_size(points: list[int64,int64,int64,int64], increase_percentage: int):
    delta_x = (points[0] - points[2]) * increase_percentage // 100
    delta_y = (points[1] - points[3]) * increase_percentage // 100

    new_points = [points[0]   delta_x, points[1]   delta_y, points[2] - delta_x, points[3] - delta_y]

    return [(i > 0) * i for i in new_points]  # Negative numbers to zeros.

What it basically does is increase the distance between the two dots (On the dots 'line').

I don't want less than 0 values so I checked for negative numbers at the end of the function. I do not care if I get out of the frame (for bigger numbers).

I get the two points as a list ([x1, y1, x2, y2]) because this is how the library I use handles that but you can change it to 2 points of course.

  • Related