用于校正和裁剪图像的 Java 图像库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/273530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 11:44:03  来源:igfitidea点击:

Java image library to deskew and crop images

javaimage-processingcrop

提问by Chris Rauber

Does anybody have a suggestion for a java library that performs automatic cropping and deskewing of images (like those retrieved from a flatbed scanner)?

有没有人对执行自动裁剪和校正图像(如从平板扫描仪检索到的图像)的 Java 库有建议?

回答by Adam Rosenfield

ImageMagickcan do that; you can use the ImageMagick Java bindings. The auto-cropoperator is probably what you're looking for. Automatic deskewing is a much harder problem and involves some significant image processing; I'm not sure if ImageMagick can handle that. If you can figure out the skewing parameters using something else, ImageMagick can definitely unskew it for you.

ImageMagick可以做到这一点;您可以使用ImageMagick Java 绑定。在自动裁剪操作也可能是你在找什么。自动纠偏是一个更难的问题,涉及一些重要的图像处理;我不确定 ImageMagick 是否可以处理。如果您可以使用其他方法找出偏斜参数,ImageMagick 绝对可以为您解除偏斜。

回答by delkant

Deskewing

纠偏

Take a look at Tess4j (Java JNA wrapper for Tesseract).

看看Tess4j(Tesseract 的 Java JNA 包装器)

You can combine ImageDeskew.getSkewAngle()with ImageHelper.rotate(BufferedImage image, double angle).

您可以将ImageDeskew.getSkewAngle()ImageHelper.rotate(BufferedImage image, double angle) 结合使用

There is an example on how to use it on the test folder of the tess4j project Tesseract1Test.java

tess4j 项目Tesseract1Test.java的 test 文件夹中有一个如何使用的例子

public void testDoOCR_SkewedImage() throws Exception {
    logger.info("doOCR on a skewed PNG image");
    File imageFile = new File(this.testResourcesDataPath, "eurotext_deskew.png");
    BufferedImage bi = ImageIO.read(imageFile);
    ImageDeskew id = new ImageDeskew(bi);
    double imageSkewAngle = id.getSkewAngle(); // determine skew angle
    if ((imageSkewAngle > MINIMUM_DESKEW_THRESHOLD || imageSkewAngle < -(MINIMUM_DESKEW_THRESHOLD))) {
        bi = ImageHelper.rotateImage(bi, -imageSkewAngle); // deskew image
    }

    String expResult = "The (quick) [brown] {fox} jumps!\nOver the ,456.78 <lazy> #90 dog";
    String result = instance.doOCR(bi);
    logger.info(result);
    assertEquals(expResult, result.substring(0, expResult.length()));
}

eurotext_deskew.png

eurotext_deskew.png

回答by anydoby

I wrote a not that simple port of a very good deskewer. It works best if you have some text in the image.

我写了一个非常好的除错器的不那么简单的端口。如果图像中有一些文字,效果最佳。

http://anydoby.com/jblog/en/java/1990

http://anydoby.com/jblog/en/java/1990

回答by Matt Passell

I'd imagine that someone has built a library on top of the Java Advanced Imaging APIfor doing this. You could try Googling for "Java Advanced Imaging deskew".

我想有人在Java Advanced Imaging API之上构建了一个库来执行此操作。您可以尝试在 Google 上搜索“Java 高级成像纠偏”。

回答by Roland Quast

I've written a simple image deskew app, includes source. Available at:

我写了一个简单的图像纠偏应用程序,包括源代码。可在:

http://www.recognition-software.com/image/deskew/

http://www.recognition-software.com/image/deskew/