1 | initial version |
Hi guys. As I promised on my last comment, here is the solution that I found (as I said, I don't think that is a elegant solution, but it works):
Mat rotate_landmarks(Mat &src) {
Mat dst = src.clone();
Point2f l = get_left_eye_centroid(src);
Point2f r = get_right_eye_centroid(src);
Point2f center(
(r.x - l.x) / 2,
(r.y - l.y) / 2
);
Mat rot = getRotationMatrix2D(center, get_alignment_angle(src), 1);
double angle_cos = rot.at<double>(0,0);
double angle_sin = rot.at<double>(1,0);
for (int i = 0; i <= 66; i++) {
double x = src.row(0).at<float>(i);
double y = src.row(1).at<float>(i);
dst.row(0).at<float>(i) = (x*angle_cos) - (y*angle_sin);
dst.row(1).at<float>(i) = (y*angle_cos) + (x*angle_sin);
}
return dst;
}
I'm applying the rotation for each point, using:
dst.row(0).at<float>(i) = (x*angle_cos) - (y*angle_sin);
dst.row(1).at<float>(i) = (y*angle_cos) + (x*angle_sin);
I actually don't like this solution very much because I'm generating the rotationMatrix2D but it is not being used directly, that's because i'm not working with a conventional image matrix.
If someone have any solution that uses the rotationMatrix directly please add the answer to this topic and I probably will mark it as the best answer.
Thank to everyone that helped.
2 | No.2 Revision |
Hi guys. As I promised on my last comment, here is the solution that I found (as I said, I don't think that is a elegant solution, but it works):
Mat rotate_landmarks(Mat &src) {
Mat dst = src.clone();
Point2f l = get_left_eye_centroid(src);
Point2f r = get_right_eye_centroid(src);
Point2f center(
(r.x - l.x) / 2,
(r.y - l.y) / 2
);
Mat rot = getRotationMatrix2D(center, get_alignment_angle(src), 1);
double angle_cos = rot.at<double>(0,0);
double angle_sin = rot.at<double>(1,0);
for (int i = 0; i <= 66; i++) {
double x = src.row(0).at<float>(i);
double y = src.row(1).at<float>(i);
dst.row(0).at<float>(i) = (x*angle_cos) - (y*angle_sin);
dst.row(1).at<float>(i) = (y*angle_cos) + (x*angle_sin);
}
return dst;
}
I'm applying the rotation for each point, using:
dst.row(0).at<float>(i) = (x*angle_cos) - (y*angle_sin);
dst.row(1).at<float>(i) = (y*angle_cos) + (x*angle_sin);
I actually don't like this solution very much because I'm generating the rotationMatrix2D but it is not being used directly, that's because i'm not working with a conventional image matrix.
If someone have any solution that uses the rotationMatrix directly please add the answer to this topic and I probably will mark it as the best answer.
Thank to everyone that helped.
3 | No.3 Revision |
Hi guys. As I promised on my last comment, here is the solution that I found (as I said, I don't think that is a elegant solution, but it works):
Mat rotate_landmarks(Mat &src) {
Mat dst = src.clone();
Point2f l = get_left_eye_centroid(src);
Point2f r = get_right_eye_centroid(src);
Point2f center(
(r.x - + l.x) / 2,
(r.y - + l.y) / 2
);
Mat rot = getRotationMatrix2D(center, get_alignment_angle(src), 1);
double angle_cos = rot.at<double>(0,0);
double angle_sin = rot.at<double>(1,0);
for (int i = 0; i <= 66; i++) {
double x = src.row(0).at<float>(i);
double y = src.row(1).at<float>(i);
dst.row(0).at<float>(i) = (x*angle_cos) - (y*angle_sin);
dst.row(1).at<float>(i) = (y*angle_cos) + (x*angle_sin);
}
return dst;
}
I'm applying the rotation for each point, using:
dst.row(0).at<float>(i) = (x*angle_cos) - (y*angle_sin);
dst.row(1).at<float>(i) = (y*angle_cos) + (x*angle_sin);
I actually don't like this solution very much because I'm generating the rotationMatrix2D but it is not being used directly, that's because i'm not working with a conventional image matrix.
If someone have any solution that uses the rotationMatrix directly please add the answer to this topic and I probably will mark it as the best answer.
Thank to everyone that helped.