如何在java中分隔文本区域和图像 [英] How do I separates text region from image in java

查看:354
本文介绍了如何在java中分隔文本区域和图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OCR来识别护照详细信息,因为我使用的是Tesseract Java API。为了获得更好的准确性,我需要将整个图像(可以是.png,.jpeg,.tiff)划分为文本区域。是否有任何开源java库将文本区域与图像分开。请给我任何建议。

解决方案



输出图片:





源代码:

  import static marvin.MarvinPluginCollection。*; 

公共类TextRegions {

public static void main(String [] args){

MarvinImage image = MarvinImageIO.loadImage(./ res /passport.png);
MarvinImage originalImage = image.clone();
列表< MarvinSegment> segments = findTextRegions(image,15,8,30,150);

for(MarvinSegment s:segments){
if(s.height> = 5){
originalImage.drawRect(s.x1,s.y1,s.x2) -s.x1,s.y2-s.y1,Color.red);
}
}

MarvinImageIO.saveImage(originalImage,./ sts / passport_2.png);
}
}


I am working on OCR to recognised passport details, Since I am using Tesseract Java API. To achieve better accuracy I need to divide the whole image (can be of .png,.jpeg, .tiff) only into text regions. Is there any open source java library which separates text regions from image. Please give me any suggestions on it.

解决方案

Marvin provides a method exactly for this purpose.

public static java.util.List<MarvinSegment> findTextRegions(MarvinImage imageIn,
                                        int maxWhiteSpace,
                                        int maxFontLineWidth,
                                        int minTextWidth,
                                        int grayScaleThreshold)

Input image:

Output image:

Source code:

import static marvin.MarvinPluginCollection.*;

public class TextRegions{

        public static void main(String[] args) {

        MarvinImage image = MarvinImageIO.loadImage("./res/passport.png");
        MarvinImage originalImage = image.clone();
        List<MarvinSegment> segments = findTextRegions(image, 15, 8, 30, 150);

        for(MarvinSegment s:segments){
            if(s.height >= 5){
                originalImage.drawRect(s.x1, s.y1, s.x2-s.x1, s.y2-s.y1, Color.red);
            }
        }

        MarvinImageIO.saveImage(originalImage, "./res/passport_2.png");
    }
}

这篇关于如何在java中分隔文本区域和图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆