I am using below method to rotate an image Mat src in angle degrees, making use of opencv dll to perform this operation. However, the output image needs to be resized and re-scaled. How the scaling factor should be decided depending on rotation angle so that the origin is retained. Currently I have given scaling factor as 1.0. Also, how the new Size of the image should be manipulated depending on the rotation angle? 1. The image obtained on 90 degrees rotation: 2. Desired result: How can I obtain image no. 2?
private static Mat deskew(Mat src, double angle) {
Point center = new Point(src.width() / 2, src.height() / 2);
Mat rotImage = Imgproc.getRotationMatrix2D(center, angle, 1.0);
Size size = new Size(src.width(), src.height());
Imgproc.warpAffine(src, src, rotImage, size, Imgproc.INTER_LINEAR
+ Imgproc.CV_WARP_FILL_OUTLIERS);
return src;
}