识别图像中的数字 [英] Recognize a number from an image

查看:504
本文介绍了识别图像中的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个应用程序来查找图像中的数字并添加它们。

I'm trying to write an application to find the numbers inside an image and add them up.

如何识别图像中的书写数字?

How can I identify the written number in an image?

我需要在图像中有许多方框来获取左侧的数字并将它们相加以得出总数。我怎样才能实现这个目标?

There are many boxes in the image I need to get the numbers in the left side and sum them to give total. How can I achieve this?

编辑:我在图像上做了一个java tesseract ocr,但我没有得到任何正确的结果。我怎么训练呢?

i did a java tesseract ocr on the image but i didnt get any correct results. how can i train it?

我做了边缘检测我得到了这个:

i did a edge detection i got this:

推荐答案

您很可能需要执行以下操作:

You will most likely need to do the following:


  1. 应用 Hough Transform 算法在整个页面上,这应该会产生一系列页面部分。

  1. Apply the Hough Transform algorithm on the entire page, this should should yield a series of page sections.

对于您获得的每个部分,请再次应用它。如果当前部分产生了2个元素,那么你应该处理一个类似于上面的矩形。

For each section you get, apply it again. If the current section yielded 2 elements, then you should be dealing with a rectangle similar to the above.

一旦完成,你可以使用OCR提取数值。

Once that you are done, you can use an OCR to extract the numeric value.

在这种情况下,我建议你看一下 JavaCV (OpenCV Java Wrapper)应该允许你处理Hough变换部分。然后你需要类似于 Tess4j (Tesseract Java Wrapper)的东西,它应该允许你要提取你所追求的数字。

In this case, I would recommend you take a look at JavaCV (OpenCV Java Wrapper) which should allow you to tackle the Hough Transform part. You would then need something akin to Tess4j (Tesseract Java Wrapper) which should allow you to extract the numbers you are after.

作为额外的注释,为了减少误报的数量,你可能想要做以下事情:

As an extra note, to reduce the amount of false positives, you might want to do the following:


  1. 如果您确定某些坐标永远不会包含您所追踪的数据,请裁剪图像。这可以为您提供更小的图片。

  1. Crop the image if you are certain that certain coordinates will never contain data you are after. This should give you a smaller picture to work with.

将图像更改为灰度可能是明智的(假设您正在使用彩色图像) 。颜色会对OCR解析图像的能力产生负面影响。

It might be wise to change the image to grey scale (assuming you are working with a colour image). Colours can have a negative impact on the OCR's ability to resolve the image.

编辑:根据你的评论,给出这样的事情:

As per your comment, given something like this:

+------------------------------+
|                   +---+---+  |
|                   |   |   |  |
|                   +---+---+  |
|                   +---+---+  |
|                   |   |   |  |
|                   +---+---+  |
|                   +---+---+  |
|                   |   |   |  |
|                   +---+---+  |
|                   +---+---+  |
|                   |   |   |  |
|                   +---+---+  |
+------------------------------+

你会裁剪图像,以便通过裁剪图像来移除没有相关数据的区域(左边的部分),你会得到这样的东西:

You would crop the image so that your remove the area which does not have relevant data (the part on the left) by cropping the image, you would get something like so:

+-------------+
|+---+---+    |
||   |   |    | 
|+---+---+    |
|+---+---+    |
||   |   |    |
|+---+---+    |
|+---+---+    |
||   |   |    |
|+---+---+    |
|+---+---+    |
||   |   |    |
|+---+---+    |
+-------------+

这个想法将运行Hough变换,以便您可以获得包含矩形的页面段,如下所示:

The idea would be to run the Hough Transform so that you can get segments of the page which contain rectangles like so:

+---+---+    
|   |   |     
+---+---+ 

然后您将应用Hough变换再次最终得到两个段,然后你选择左段。

Which you would then apply the Hough Transform again and end up with two segments, and you take the left one.

一旦你有左段,你就可以申请OCR。

Once that you have the left segment, you would then apply the OCR.

可以尝试手动应用OCR,但最好的情况是,OCR会识别两个数字值,无论是写入的还是两种类型的,都是我得到的,不是你想要的。

You can try to apply the OCR before hand, but at best, the OCR will recognize both numeric values, both written and both typed, which from what I get, is not what you are after.

此外,描绘矩形的额外线条可能会使OCR偏离轨道,并使其产生不良结果。

Also, the extra lines which depict the rectangles might throw the OCR off track, and make it yield bad results.

这篇关于识别图像中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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