I'm trying to rotate an image without cropping and I find a way on C++.
Rotate an image without cropping in OpenCV in C++
Now, I get some problem on Android, I cannot find at() method on Android. Here is my Android code:
private Mat rotateImg(Mat image, double angle) {
int centerX = Math.round(image.width() / 2);
int centerY = Math.round(image.height() / 2);
Point center = new Point(centerY, centerX);
//Size rotatedSize = new Size(image.width(), image.height());
Mat M = Imgproc.getRotationMatrix2D(center, angle, 1);
Rect bbox = new RotatedRect(center, image.size(), angle).boundingRect();
/*
rot.at<double>(0,2) += bbox.width/2.0 - center.x;
rot.at<double>(1,2) += bbox.height/2.0 - center.y;
*/
Imgproc.warpAffine(image, image, M, bbox.size());
return image;
}
I've no idea on
rot.at<double>(0,2) += bbox.width/2.0 - center.x;
rot.at<double>(1,2) += bbox.height/2.0 - center.y;