Reputation: 1209
I am using OpenCV
or dlib
to detect face from images. The result is very good. Here is an example:
However, I also want to take the hair and the neck from the image, like that:
I have tried to look for a library or framework to help me achieve that but I can't find one.
Are there any way to do that?
Upvotes: 2
Views: 6344
Reputation: 381
In case you want to extract exactly region of hair and neck, you need to train your own model because the current dlib model does not include them.
Otherwise, you just want to capture relatively, you can use Openpose which gives you the landmarks of faces + ears + shoulders (even body and hand fingers). From those landmarks you can draw your interested area.
Example:
the width of rectangle = the length of shoulder (point 2 -> point 5)
the height = the length from the neck to (point 1) to the nose (point 0) x 2. (point 1 - point 0)*2
Upvotes: 1
Reputation: 533
use this code to increase the bounding box by percentage.
rects = detector(original_image, 1)
for rect in rects:
(x, y, w, h) = rect_to_bb(rect)
x_inc = int(w*0.3)
y_inc = int(h*0.3)
sub_face = original_image[y-y_inc:y+h+y_inc, x-x_inc:x+w+x_inc]
newimg = cv2.resize(sub_face,(int(224),int(224)))
Upvotes: 0