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);

// result http://www.freeimagehosting.net/hb51q

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

--

Search Discussions

  • Alexander Smorkalov at Nov 9, 2012 at 5:51 am
    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 at Nov 9, 2012 at 11:55 am
    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..
    On Friday, 9 November 2012 10:51:34 UTC+5, Alexander Smorkalov wrote:

    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.
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupandroid-opencv @
categoriesandroid
postedNov 8, '12 at 12:16p
activeNov 9, '12 at 11:55a
posts3
users2
websiteandroid.com

People

Translate

site design / logo © 2020 Grokbase