Created
April 13, 2017 13:46
-
-
Save sminogue/7a44ae666df5047b1489047f376a6313 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Convert the ORIGINAL image | |
Planar<GrayF32> input = ConvertBufferedImage.convertFromMulti(image, null, true, GrayF32.class); | |
//Based on the four corners get the width and height of the page | |
Double width = topRight.x - topLeft.x; | |
Double height = bottomLeft.y - topLeft.y; | |
//Setup to make the page top down | |
RemovePerspectiveDistortion<Planar<GrayF32>> removePerspective = new RemovePerspectiveDistortion<>(width.intValue(), height.intValue(), ImageType.pl(3, GrayF32.class)); | |
// Specify the corners in the input image of the region. | |
// Order matters! top-left, top-right, bottom-right, bottom-left | |
if (!removePerspective.apply(input, topLeft, topRight, bottomRight, bottomLeft)) { | |
throw new RuntimeException("Failed!?!?"); | |
} | |
//Get the re-oriented image | |
Planar<GrayF32> output = removePerspective.getOutput(); | |
//Turn it into a BufferedImage. This should be the page straight on and nothind else. | |
BufferedImage flat = ConvertBufferedImage.convertTo_F32(output, null, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment