Reputation: 23
I'm working on a resize and crop workflow to allow images to be resized and then cropped to a specific size. Normally one resize the smallest dimension to fit the destination size, and then crop to get eg. a square.
However, in this case, I have some additional face-detection data: face_x, face_y and face_width and face_height. The X and Y coordinates of the face is top-left point in the original picture of where the face starts.
I want the cropped area to be centered at the face instead of in the center of the image.
Any smart minds out there who can help me out? Thanks!
Upvotes: 1
Views: 574
Reputation: 89222
The center of the face is
(face_x + face_width/2, face_y+face_height/2).
If you want the image to be (w, h) at the end, then the upper left is
(face_x + (face_width - w)/2, face_y + (face_height - h)/2)
Upvotes: 1