I need to rotate an image by either 90, 180 or 270 degrees. In OpenCV4Android I can use:
Imgproc.getRotationMatrix2D(new Point(center, center), degrees, 1);
Here is a solution using the Android API. Here, I am using it to rotate images from a camera which could be mounted in various orientations.
if (mCameraOrientation == 270) {
// Rotate clockwise 270 degrees
Core.flip(src.t(), dst, 0);
} else if (mCameraOrientation == 180) {
// Rotate clockwise 180 degrees
Core.flip(src, dst, -1);
} else if (mCameraOrientation == 90) {
// Rotate clockwise 90 degrees
Core.flip(src.t(), dst, 1);
} else if (mCameraOrientation == 0) {
// No rotation
dst = src;
}