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

时间:2022-11-14 13:08:27

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库(比如从平板扫描仪中检索到的那些)?

5 个解决方案

#1


4  

ImageMagick can do that; you can use the ImageMagick Java bindings. The auto-crop operator 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绝对可以为你解开它。

#2


3  

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

我写了一个非常好的deskewer的简单端口。如果图像中有一些文本,则效果最佳。

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

#3


2  

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图像,双角度)结合使用。

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

有关如何在tess4j项目Tesseract1Test.java的测试文件夹中使用它的示例

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 $43,456.78 <lazy> #90 dog";
    String result = instance.doOCR(bi);
    logger.info(result);
    assertEquals(expResult, result.substring(0, expResult.length()));
}

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

#4


1  

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

我想有人已经在Java Advanced Imaging API之上构建了一个库来实现这一目标。您可以尝试使用Google搜索“Java Advanced Imaging deskew”。

#5


1  

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

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

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

#1


4  

ImageMagick can do that; you can use the ImageMagick Java bindings. The auto-crop operator 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绝对可以为你解开它。

#2


3  

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

我写了一个非常好的deskewer的简单端口。如果图像中有一些文本,则效果最佳。

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

#3


2  

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图像,双角度)结合使用。

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

有关如何在tess4j项目Tesseract1Test.java的测试文件夹中使用它的示例

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 $43,456.78 <lazy> #90 dog";
    String result = instance.doOCR(bi);
    logger.info(result);
    assertEquals(expResult, result.substring(0, expResult.length()));
}

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

#4


1  

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

我想有人已经在Java Advanced Imaging API之上构建了一个库来实现这一目标。您可以尝试使用Google搜索“Java Advanced Imaging deskew”。

#5


1  

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

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

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