yulequan / face-alignment-in-3000fps

a c++ implementation of face alignment in 3000fps
Other
377 stars 234 forks source link

adjustImage overcropping #10

Closed kencoken closed 9 years ago

kencoken commented 9 years ago

In Utils.cpp line 296 you call adjustImage when looping over face detections within an image which overlap with a face detection:

adjustImage(image,ground_truth_shape,boundingbox);
images.push_back(image);
ground_truth_shapes.push_back(ground_truth_shape);
bounding_boxs.push_back(boundingbox);

However, image is defined outside of the face loop, so when multiple detections are made which overlap with the ground truth, I believe the image will effectively be over-cropped.

This could be resolved by cloning the image and ground_truth_shape in the loop:

Mat_<uchar> adjusted_image = image.clone();
Mat_<double> adjusted_ground_truth_shape = ground_truth_shape.clone();
adjustImage(adjusted_image,adjusted_ground_truth_shape,boundingbox);
images.push_back(adjusted_image);
ground_truth_shapes.push_back(adjusted_ground_truth_shape);
bounding_boxes.push_back(boundingbox);

Furthermore, in the adjustImage function, you have the lines:

double left_x  = max(1.0, bounding_box.centroid_x - bounding_box.width*2/3);
double top_y   = max(1.0, bounding_box.centroid_y - bounding_box.height*2/3);
double right_x = min(img.cols-1.0,bounding_box.centroid_x+bounding_box.width);
double bottom_y= min(img.rows-1.0,bounding_box.centroid_y+bounding_box.height);

Followed later by:

img = img.rowRange((int)top_y,(int)bottom_y).colRange((int)left_x,(int)right_x).clone();

Should the first two lines not read max(0.0, ...?

Perhaps I'm missing something, but let me know if you agree there are errors here as happy to issue a PR.

kencoken commented 9 years ago

Realise now that you are only extracting a maximum of a single detection per image. Closing the issue – thanks for the great work on this!