I am building Face detection app using OpenCv. I am processing preview frame data received on callback onPreviewFrame. I am using camera in portrait mode, whereas onPreviewF
Problem: Dont traverse image in column-order. Since, you are not benefited by locality of reference, the code will run very slow.
For opencv, you can use combination of transpose and flip command.
switch (angle) {
case 0:
srcImage.copyTo(dstImage);
break;
case 90:
Core.transpose(srcImage, dstImage);
Core.flip(dstImage, dstImage, 1);
break;
case 180:
Core.flip(srcImage, dstImage, -1);
break;
case 270:
Core.transpose(srcImage, dstImage);
Core.flip(dstImage, dstImage, 0);
break;
default:
Logger.error(
"ROTATE_IMAGE_CLOCKWISE: Incorrect rotation value received: {}",
angle);
return srcImage;
}
This is the same code used to read input image when Image(jpeg) has Orientation metadata. See opencv source code here. The above code is in java.
See my answer here, to know how orientation works. Put opencv and the image from my answer together, and its very simple.
I think you have already an answer in this:
Android: How to rotate a bitmap on a center point
in your case your rotation is just mRotation = 90 degrees.