OCR:如何比较图像、排序不匹配并快速完成此操作?

发布于 2024-07-14 18:18:45 字数 291 浏览 6 评论 0原文

我设法将每个字符存储在位图中,并正在寻找一种方法来快速确定它是哪个字符。

因此,我将把每个可能的字符存储到一个由 1 和 0 组成的数组中,并将它们与我刚刚抓取的位图数组进行比较。

我可以做简单的检查,例如比较我得到的黑色像素的数量,比较尺寸等等,但所有这些检查都很慢(只是猜测......)。

所以我正在寻找一种方法,它从下到上遍历每个像素,或者随机地将数组与一组数组进行比较,并对不匹配的进行排序,直到只剩下一个数组。 但我该如何实现呢?

感谢您的帮助。

斯文

I managed to have each character stored in a bitmap and am looking for a way to quickly determine which character it is.

Therefore I'm about to store every possible character into an array of 1 and 0, and compare them to an array of the bitmap I just grabbed.

I could do simple checks like compare how many black pixels I got, compare the dimensions and so on, but all these checks are slow (just a guess..).

So what I'm looking for is a method, which goes trough every pixel from bottom to top, or randomly which compares the array to a set of arrays and sorts unmatching out, till only one array remains. But how can I implement that?

Thanks for your help.

Sven

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦明 2024-07-21 18:18:45

在 OCR 世界中,您很少会遇到目标资源与原始比较资源之间的“完美匹配”。

实际上这是一个巨大的科学领域,但这里有一篇关于这个主题的很好的论文,应该可以为您提供一些基本知识:
http://www.discover.uottawa.ca/~qchen/my_papers/ master_thesis.pdf

请注意,此类算法的数学运算量非常大,并且现在已针对标准 x86 CPU 进行了优化。

如果你正在寻找一个完美的匹配(我的意思是,非常完美,精确到字节)并且你想快速简单地实现这个,我建议你做一个“快速跳过明显的不匹配”——有点算法——类似于:

1) 比较数组的大小,如果不同,则不是您要查找的

2) 比较每个位图的哈希值

3) 逐一比较每个位/字节,一旦发现差异,这不是您想要的

4) 获胜,您找到了匹配项:)

这非常慢,具体取决于您想要实现的目标,但很容易实现并且会起作用。 对于类似原型的应用程序来说,这很适合。 正如我所说,OCR(以及所有其他形式的数字信号处理)是一个巨大的研究领域,因此您不能指望人们在快速论坛帖子中教您,遗憾的是:(

祝您好运

[编辑]查看评论在你的 OQ 中,我会说哈希表/字典数据结构对你来说是最快的,或者二叉搜索树。两者都非常依赖于你的哈希键生成器:)

[EDIT2 (xD)]“它是计算机生成的别名文本背景不同,但文本始终具有相同的颜色。” 那里有非常重要的信息:P 文本/位图的大小也始终相同吗? 我建议要么实现自己的哈希算法,丢弃预设的背景颜色,以便哈希值仅取决于文本的颜色(以及文本的形状),要么简单地重写目标中的所有背景像素与原始颜色相同(或者只是将原始背景设置为目标的颜色?再次取决于您在这里使用的数据 - 需要更多信息:))。

In the OCR-world it's pretty seldom that you run into a "perfect match" between a targetresource and your original comparing resource.

Actually it's a huge field of science, but here's a nice thesis on the subject which should give you some basic knowledge:
http://www.discover.uottawa.ca/~qchen/my_papers/master_thesis.pdf

Note that algorithms like these are very math heavy and in now way optimized for a standard x86 CPU.

If you are looking for a perfect match (I mean, really perfect, down to byte-to-byte) and you want to implement this fast and easy, I'd suggest doing a "skip the obvious mismatches fast"-kinda algorithm - something like:

1) Compare size of arrays, if different, it's not what you look for

2) Compare a hash-value of each bitmaps

3) Compare each bit / byte one-by-one and as soon as you see a difference, it's not what you look for

4) Win, you found a match :)

This is very slow, depending on what you're trying to achieve, but easy to implement and it will work. So goes well for a prototype-alike application. As I said, OCR (and all other forms of digital signal processing) are a huge field of research, so it's not something you can expect people to teach you in a quick forumpost, sadly :(

Good luck

[EDIT] Looking at the comment in your OQ, I'll say going for a hashtable / dictionary datastructure would be the fastest for you. That, or a binary search tree.. Both very reliant onj your hash-key generator :)

[EDIT2 (xD)] "It's aliased text generated by a computer. The Background is different, but the text always has the same color." Pretty important information there :P Are the size of the text / bitmaps always the same as well? I'd suggest that either implement your own hashing algorithm where you discard the preset background colors, so that the hashing value only depends on the color of the text (and the shape of this too ofc) or simply rewrites all background pixels in your targets to be the same color as your original (or just set the original background to that of your targets? Depends again on which data you are fighting with here - need more information :) ).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文