Issue
I want to straight an image by selecting four points in the image using getPerspectiveTransform() method of opencv in java. I know it can be done using with opencv in python: getPerspectiveTransform. If anyone used this to achieve image straightening ..please help.
Solution
There is perspective transformation which can be used to achieve quad to quad conversion. In OpenCV, there are mainly two methods to achieve getPerspectiveTransformation() and warpPerspective() method.
Here is a sample code to achieve Image Straightening:
First get four quadrilinear points in source image
Mat srcImage = Imgcodecs.imread("input.png");
Mat destImage = new Mat(500, 700, srcImage.type());
Mat src = new MatOfPoint2f(new Point(x1, y1), new Point(x2, y2), new Point(x3, y3), new Point(x4, y4));
Mat dst = new MatOfPoint2f(new Point(0, 0), new Point(destImage.width() - 1, 0), new Point(destImage.width() - 1, destImage.height() - 1), new Point(0, destImage.height() - 1));
Getting transformation metrix
Mat transform = Imgproc.getPerspectiveTransform(src, dst);
Imgproc.warpPerspective(srcImage, destImage, transform, destImage.size());
you will get transformed straighten image.
I have tested this code on this image.
Answered By - user5954693 Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.