1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| IplImage *cropFace(IplImage * image, CvPoint eye_left, CvPoint eye_right, double offset_pct[2], CvSize dest_sz)
{
//calculate offsets in original image
...
//matrice de rotation
cv::Mat affine_matrix;
affine_matrix = cv::getRotationMatrix2D(eye_left, rotation, scale);
//mtx est la conversion de image IplImage* en matrice mtx
cv::Mat mtx = cv::Mat(image, true);
cv::Mat mtx2;
cv::warpAffine(mtx, mtx2, affine_matrix, mtx.size(), cv::INTER_LINEAR, cv::BORDER_CONSTANT, cv::Scalar::all(255));
//mtx est la conversion de matrice mtx2 en image IplImage*
IplImage image1 = mtx2;
//crop the rotated image
double crop_x = eye_left.x - scale * offset_h;
double crop_y = eye_left.y - scale * offset_v;
double crop_size0 = dest_sz.width * scale;
double crop_size1 = dest_sz.height * scale;
CvRect region;
region.x = cvFloor(crop_y);
region.y = cvFloor(crop_y);
region.width = cvFloor(crop_size0);
region.height = cvFloor(crop_size1);
//c'est au niveau cette ligne que le code ne marche pas
IplImage *image2 = cropImage(&image1, region);
IplImage *image3 = resizeImage(image2, dest_sz.width, dest_sz.width);
return image3;
} |
Partager