使用tesseract识别车牌 [英] Using tesseract to recognize license plates

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

问题描述

我正在开发一款可以识别车牌(ANPR)的应用程序。第一步是从图像中提取牌照。我正在使用OpenCV来检测基于宽高比的印版,这非常有效:

I'm developing an app which can recognize license plates (ANPR). The first step is to extract the licenses plates from the image. I am using OpenCV to detect the plates based on width/height ratio and this works pretty well:

但是正如你所看到的,OCR结果非常糟糕。

But as you can see, the OCR results are pretty bad.

我在 Objective C (iOS)环境中使用 tesseract 。启动引擎时,这些是我的 init 变量:

I am using tesseract in my Objective C (iOS) environment. These are my init variables when starting the engine:

// init the tesseract engine.
    tesseract = new tesseract::TessBaseAPI();
    int initRet=tesseract->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding], [language UTF8String]);
    tesseract->SetVariable("tessedit_char_whitelist", "BCDFGHJKLMNPQRSTVWXYZ0123456789-");
    tesseract->SetVariable("language_model_penalty_non_freq_dict_word", "1");
    tesseract->SetVariable("language_model_penalty_non_dict_word ", "1");
    tesseract->SetVariable("load_system_dawg", "0");

如何改善结果?我是否需要让OpenCV进行更多的图像处理?或者我可以通过tesseract改进一些东西吗?

How can I improve the results? Do I need to let OpenCV do more image manipulation? Or is there something I can improve with tesseract?

推荐答案

有两件事情可以解决这个问题:

Two things will fix this completely:


  1. 从图像中删除 not text 的所有内容。您需要使用一些CV来查找印版区域(例如通过颜色等),然后屏蔽背景的所有。您希望tesseract的输入为黑色和白色,其中文本为黑色,其他所有内容均为白色

  1. Remove everything which is not text from the image. You need to use some CV to find the plate area (for example by color, etc) and then mask out all of the background. You want the input to tesseract to be black and white, where text is black and everything else is white

删除偏斜(如上面的FrankPI所述)。 tesseract实际上应该可以正常工作(请参阅 Tesseract OCR Engine 概述由R.史密斯)但另一方面它并不总是工作,特别是如果你有一行而不是几段。因此,如果您可以可靠地执行此操作,首先手动删除倾斜总是好的。你可能会知道步骤1中板块的边界梯形的确切形状,所以这不应该太难。在删除歪斜的过程中,您还可以删除透视:所有牌照(通常)都具有相同的字体,如果您将它们缩放到相同(无透视)的形状,字母形状将完全相同,这将有助于文本识别。

Remove skew (as mentioned by FrankPI above). tesseract is actually supposed to work okay with skew (see "Tesseract OCR Engine" overview by R. Smith) but on the other hand it doesn't always work, especially if you have a single line as opposed to a few paragraphs. So removing skew manually first is always good, if you can do it reliably. You will probably know the exact shape of the bounding trapezoid of the plate from step 1, so this should not be too hard. In the process of removing skew, you can also remove perspective: all license plates (usually) have the same font, and if you scale them to the same (perspective-free) shape the letter shapes would be exactly the same, that would help text recognition.

一些进一步的指示......

Some further pointers...

首先不要尝试对此进行编码:从一个非常容易的OCR(即:直接从前面,没有透视)图片的板块,在photoshop(或gimp)中编辑它并通过命令行上的tesseract运行它。以不同的方式继续编辑,直到这样做。例如:按颜色选择(或选择字母形状),填充黑色,反转选择,填充白色,透视变换,因此板的角是矩形等。拍摄一堆图片,有些更难(可能来自奇数)角度等)。与所有人一起做这件事。一旦这完全有效,想想如何制作一个与你在photoshop中做同样事情的CV算法:)

Don't try to code this at first: take a really easy to OCR (ie: from directly in front, no perspective) picture of a plate, edit it in photoshop (or gimp) and run it through tesseract on the commandline. Keep editing in different ways until this works. For example: select by color (or flood select the letter shapes), fill with black, invert selection, fill with white, perspective transform so corners of plate are a rectangle, etc. Take a bunch of pictures, some harder (maybe from odd angles, etc). Do this with all of them. Once this works completely, think about how to make a CV algorithm that does the same thing you did in photoshop :)

P.S。此外,如果可能,最好从更高分辨率的图像开始。看起来您的示例中的文本大约有14像素高。 tesseract与300 dpi的12点文本相当不错,大约50像素高,在600 dpi时效果更好。尽量让你的信件大小至少为50,最好是100像素。

P.S. Also, it is better to start with higher resolution image if possible. It looks like the text in your example is around 14 pixels tall. tesseract works pretty well with 12 point text at 300 dpi, this is about 50 pixels tall, and it works much better at 600 dpi. Try to make your letter size be at least 50 preferably 100 pixels.

P.P.S。您是否正在做任何事情来培训tesseract ?我认为你必须这样做,这里的字体不同就足以成为一个问题。你可能还需要一些东西来识别(而不是惩罚)破折号,这些破折号在你的文本中很常见,看起来在第二个例子中T-被识别为H.

P.P.S. Are you doing anything to train tesseract? I think you have to do that, the font here is different enough to be a problem. You probably also need something to recognize (and not penalize) dashes which will be very common in your texts, looks like in the second example "T-" is recognized as H.

这篇关于使用tesseract识别车牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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