Open YukiSakuma opened 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?
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)
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?