Rotated image is not centralized in opencv4android

105 views
Skip to first unread message

Khawar khan

unread,
Nov 8, 2012, 7:16:24 AM11/8/12
to android...@googlegroups.com
Hi, I've successfully rotated image in opencv (4android), using code below

 // -----CALCULATION FOR NEW WIDTH/HEIGHT------
double radians = Math.toRadians(Angle);
double sin = Math.abs(Math.sin(radians));
double cos = Math.abs(Math.cos(radians));
   
double radian = Math.toRadians(waterMarkAngle);
int newWidth = (int) (scaledImage.width() * cos + scaledImage.height() * sin);
int newHeight = (int) (scaledImage.width() * sin + scaledImage.height() * cos);

// rotating water image
org.opencv.core.Point center = new org.opencv.core.Point(newWidth/2, newHeight/2);
Mat rotImage = Imgproc.getRotationMatrix2D(center, waterMarkAngle, 1.0); // 1.0 means 100 % scale
Size s = new Size(newWidth, newHeight);
Imgproc.warpAffine(scaledImage, scaledImage, rotImage, s,Imgproc.INTER_LINEAR + Imgproc.CV_WARP_FILL_OUTLIERS);//

Highgui.imwrite("mnt/sdcard/rotatedWatermark.png",scaledImage);


how do I centralize this resultant image?
Thanks in advance.

Alexander Smorkalov

unread,
Nov 9, 2012, 12:51:27 AM11/9/12
to android...@googlegroups.com
What do you mean in word "centralize"?
If you want to get rectangle image without black borders you need to get submat with your region of interest.

Khawar khan

unread,
Nov 9, 2012, 6:55:29 AM11/9/12
to android...@googlegroups.com
Thanks for your help.. what I'm doing is that I've rotated an image so its edges were cut off, then I used a formula to get new width/height of an image after rotation, so how do I make it translate to center of the new sized rectange.. this is what I'm doing.. If you have any good solution please do share..
Reply all
Reply to author
Forward
0 new messages