nagadomi / lbpcascade_animeface

A Face detector for anime/manga using OpenCV
1.93k stars 294 forks source link

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

Open YukiSakuma opened 4 years ago

YukiSakuma commented 4 years ago

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 commented 4 years ago

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?

nagadomi commented 4 years ago

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)