I am trying to find contours from the raw bytes received from onPreviewFrame. These raw bytes received are not rotated when we do setDisplayOrientation(according to the android developer docs). It is becoming difficult to rotate the contours alone. How to rotate these bytes efficiently and then process it ? I am using openCV to find the contours.
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
previewSize = cameraConfigUtil.cameraInstance.getParameters().getPreviewSize();
Mat srcMat = new Mat(previewSize.height, previewSize.width, CvType.CV_8UC3);
srcMat.put(0, 0, data);
rect = ImageCorrection.getLargestContour(data, previewSize.height, previewSize.width);
android.graphics.Rect rectangle = new android.graphics.Rect();
rectangle.left = rect.x;
rectangle.top = rect.y;
rectangle.right = rect.x + rect.width;
rectangle.bottom = rect.y + rect.height;
mOverlay.clear();
BarcodeGraphic graphic = new BarcodeGraphic(mOverlay);
mOverlay.add(graphic);
graphic.updateItem(rectangle);
Imgproc.rectangle(srcMat, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(255, 0, 0, 255), 3);
Utils.matToBitmap(srcMat, bitmap);
}
Here rectangle gives the four points of the contour, I want this to be rotated according to the angle set in setDisplayOrientation.