I am using Opencv in Android to calculate the rotation angle
of a detected object then I rotate that object back to its normal position for further image traitment like segmentation and object matching.
This is what I've got so far
double rect_angle = rbox.angle - 90.0f;
Size rect_size = rbox.size;
double d = rect_size.width;
rect_size.width = rect_size.height;
rect_size.height = d;
M = Imgproc.getRotationMatrix2D(rbox.center, rect_angle, 1.0);
Imgproc.warpAffine(origMat, rotated, M, origMat.size());
If I rotate my object a little here is the result
And if I don't rotate the object here is what I get
I need to keep the object always centered.
My problem is similar to this question Rotate an image without cropping in OpenCV in C++
but I couldn't achieve that in java.
I hope you guys can help me achieve that.