public void transform(View view) {
Mat sampledImage = ImageUtils.bitmapToMat(mBitmap);
Mat correctedImage = new Mat(sampledImage.rows(), sampledImage.cols(), sampledImage.type());
Map<Integer, PointF> points = mPolygonView.getPoints();
List<Point> srccorners = getSrcPoint(mBitmap, points);
List<Point> descorners = new ArrayList<>();
descorners.add(new Point(0, 0));
descorners.add(new Point(correctedImage.cols(), 0));
descorners.add(new Point(0, correctedImage.rows()));
descorners.add(new Point(correctedImage.cols(), correctedImage.rows()));
Mat srcPoints = Converters.vector_Point2f_to_Mat(srccorners);
Mat desPoints = Converters.vector_Point2f_to_Mat(descorners);
Mat transformation = Imgproc.getPerspectiveTransform(srcPoints, desPoints);
Imgproc.warpPerspective(sampledImage, correctedImage, transformation, correctedImage.size());
displayImage(correctedImage);
}
public static Mat bitmapToMat(Bitmap bitmap) {
Mat mat = new Mat(bitmap.getHeight(), bitmap.getWidth(), CvType.CV_8U, new Scalar(4));
Bitmap bitmap32 = bitmap.copy(Bitmap.Config.ARGB_8888, true);
Utils.bitmapToMat(bitmap32, mat);
return mat;
}
public static Bitmap matToBitmap(Mat mat) {
Bitmap bitmap = Bitmap.createBitmap(mat.cols(), mat.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mat, bitmap);
return bitmap;
}
private List<Point> getSrcPoint(Bitmap original, Map<Integer, PointF> points) {
List<Point> src