lbpcascade_animeface icon indicating copy to clipboard operation
lbpcascade_animeface copied to clipboard

Is there a way to crop that includes the full head?

Open YukiSakuma opened this issue 5 years ago • 2 comments

It works great but is there a way to adjust such that the crop includes the full head so it captures the top hair too?

YukiSakuma avatar Jun 01 '20 01:06 YukiSakuma

Adding a constant in the for loop part in the 2nd argument of cv2.rectangle e.g(x, y) to (x, y + k)seems to do the trick.

Note: k should be negative

But I'm keeping this issue open for further suggestions and further enhancements like what if you also want to capture the left and right side hair?

Or what if you have a batch of images of different resolutions, how would you make the constant k to be dynamic?

YukiSakuma avatar Jun 01 '20 01:06 YukiSakuma

The easy way is to resize the bounding box as you suggest.

    top_shift_scale = 0.3 # param
    x_scale = 0.15 # param
    for (x, y, w, h) in faces:
        y_shift = int(h * top_shift_scale)
        x_shift = int(w * x_scale)
        cv2.rectangle(image, (x - x_shift, y - y_shift), (x + w + x_shift, y + h), (0, 0, 255), 2)

nagadomi avatar Jun 01 '20 16:06 nagadomi