java 图像 数字 识别,识别java中图像中的数字

I want to recognize numbers in the following image

6AXwH.jpg

I am currently using Tess4J library in eclipse java project but it only recognizes the characters in a plane color background. For this image it could not even identify that there are characters(numbers) on this image. Help me find a way to accomplish this task.

Here is my current code:

import net.sourceforge.tess4j.*;

import java.io.File;

public class Main {

public static void main(String[] args) {

File imageFile = new File("image.png");

Tesseract instance = Tesseract.getInstance();

try {

String result = instance.doOCR(imageFile);

System.out.println(result);

} catch (TesseractException e) {

System.err.println(e.getMessage());

}

}

}

and if there is way to count the squares separated by yellow lines.

Thank you

解决方案

If your image is representative, then all you need as a first step is a binarization at a threshold close to the maximum value followed by discarding of small components.

f = Import["http://i.stack.imgur.com/6AXwH.jpg"]

step1 = SelectComponents[Binarize[ColorConvert[f, "Grayscale"], 0.9],

"Count", #1 > 100 &]

yxezVm.png

Now, if you know that the digits cannot be too tall or too thin (this is dependent on image dimensions), then you can filter the remaining components based on its bounding box.

SelectComponents[step1, "BoundingBox",

And[10 < #[[2, 1]] - #[[1, 1]] < 100, 50 < #[[2, 2]] - #[[1, 2]] < 100] &]

fOmSZm.png

To separate each of the regions, you could consider using a colorspace where there is a channel dedicated to the yellow color. CMYK is a possibility here, and again all you need is a threshold at a high value, together with the basic morphological closing to complete the lines (since in your example the lines do not extend to the border of the image). Instead of using morphological closings here, you could detect the lines using Hough or RANSAC, for example.

rects = Closing[

Closing[Binarize[ColorSeparate[f, "CMYK"][[3]], 0.9],

ConstantArray[1, {1, 15}]], ConstantArray[1, {15, 1}]] (* left image *)

Colorize[MorphologicalComponents[ColorNegate[rects]],

ColorFunction -> "Rainbow"] (* right image *)

fyT1Om.png

0g1otm.png

The tools used here are very simple, and almost any image processing library will provide them. There are also more robust approaches that could be taken, but for the given image it is not needed.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值