OpenCV 检测数字

发布于 2024-11-05 00:42:57 字数 838 浏览 4 评论 0原文

我在 iPhone 上使用 OpenCV,需要检测图像中的数字。我将图像分成较小的图像,因此每个图像只有一个数字(1-9)。所有数字都是打印的,而不是手写的。

使用 OpenCV 计算数字的最佳方法是什么?

更新:

我已成功找到这些号码并提取它们。它们看起来像这样:

http://img198.imageshack.us/img198/5671/101ht。 .jpg
http://img824.imageshack.us/img824/539/606yu.jpg

当它们被提取时,它们的大小相同,依此类推。我保存了一堆图像并将它们放入 OCR 目录中,并将它们分类为数字。例如: ocr/1/100.jpg 101.jpg .... 和 ocr/2/200.jpg 201.jpg ....

然后我将使用与基本 OCR 教程中相同的方法:http://blog.damiles.com/?p=93

但是,我正在为 iPhone 编程,不能使用C++ 代码(编译错误等)并且我无法访问 highgui。

我尝试使用 cvMatchTemplate() 并匹配一堆图像,但它似乎工作得很糟糕......

我可以尝试其他想法吗?

I'm using OpenCV on the iPhone and need to detect numbers in an image. I split the image into smaller images so each image has only one number (1-9). All numbers are printed, NOT handwritten.

What would be the best approach to figure out the numbers with OpenCV?

UPDATE:

I have successfully found the numbers and extracted them. They look like this:

http://img198.imageshack.us/img198/5671/101ht.jpg
http://img824.imageshack.us/img824/539/606yu.jpg

When they are extracted they are in the same size and so on. I have saved a bunch of images and put them in a OCR dir where they are categorized into numbers. Like: ocr/1/100.jpg 101.jpg.... and ocr/2/200.jpg 201.jpg....

Then I was going to use the same approach as in the Basic OCR tutorial:http://blog.damiles.com/?p=93

However, I'm programming for iPhone and can't use C++ code (error on compiling and so on) and I don't have access to highgui.

I tried using cvMatchTemplate() and match a bunch of images but it seems to work pretty bad...

Any other ideas I can try?

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

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

发布评论

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

评论(10

小忆控 2024-11-12 00:42:57

您可以首先阅读主成分分析 (PCA)、费舍尔线性判别分析 (LDA) 和支持向量机 (SVM)。这些是对 OCR 非常有用的分类方法,并且有任何语言的库,包括 C++、Python、C# 等。

事实证明,OpenCV 已经在 PCASVM[死链接]。我还没有看到任何 OCR 的 OpenCV 代码示例,但您可以使用面部分类的某些修改版本来执行字符分类。 OpenCV 人脸识别代码的绝佳资源是此网站[死链接]。

You could start by reading about Principal Component Analysis (PCA), Fisher's Linear Discriminant Analysis (LDA), and Support Vector Machines (SVMs). These are classification methods that are extremely useful for OCR, and there are libraries in any language including C++, Python, C# etc.

It turns out that OpenCV already includes excellent implementations on PCAs and SVMs[dead link]. I haven't seen any OpenCV code examples for OCR, but you can use some modified version of face classification to perform character classification. An excellent resource for face recognition code for OpenCV is this website[dead link].

划一舟意中人 2024-11-12 00:42:57

如果打印了数字,那么工作就非常简单,您只需要找出一组合适的特征来匹配即可。如果数字是一种字体,您可以采用以下方法:

  • 提取数字
  • 找到边界框
  • 将图像缩小到 10x8 之类的大小,尝试匹配宽高比
  • 针对小型训练集执行此操作,取每个数字的“平均”图像

  • 对于新图像,请按照上述步骤操作,但最后一个只是与每个数字模板。然后取差异之和(差异图像中的像素)。最小值就是您的数字。

以上都是OpenCV的基本操作。

If the numbers are printed, the job is quite simple, you just need to figure out a nice set of features to match. If the numbers are one font, you can get away with this approach:

  • Extract the number
  • Find the bounding box
  • Scale the image down to something like 10x8, try to match the aspect ratio
  • Do this for a small training set, take the 'average' image for each number

  • For new images, follow the steps above, but the last is just a absolute image difference with each of the number-templates. Then take the sum of the differences (pixels in the difference image). The one with the minimum is your number.

All above are basic OpenCV operations.

折戟 2024-11-12 00:42:57

基本上你的问题只是对特征向量进行分类,它是经过一些预处理步骤后的像素强度集。您可以使用任何分类器来完成此任务,例如。神经网络,它应该在 OpenCV 中有一个 C 实现。您还可以尝试使用支持向量机的 C libsvm 库。

有一个与这个问题相关的好网站,有很多论文和一个培训数据库。

Basically your problem is just to classify a feature vector, which is the set of pixel intensities after some preprocessing steps. You can use any classifier for this task, like eg. neural networks, which should have a C implementation inside OpenCV. You might also try a C libsvm library for Support Vector Machines.

There is a good site related to this problem with a lot of papers and a training database.

愿得七秒忆 2024-11-12 00:42:57

也许最简单方便的方法就是使用 svm 作为 ml 算法
http://opencv.willowgarage.com/documentation/cpp/support_vector_machines.html
和灰度图像作为特征向量。

Maybe the most simple and convinient way is to use svm as ml algorithm
http://opencv.willowgarage.com/documentation/cpp/support_vector_machines.html
and gray images as feature vectors.

简美 2024-11-12 00:42:57

目标C++?
尝试将 .m 文件重命名为 .mm,然后就可以在 iPhone 项目中使用 C++。

Objective C++?
Try renaming your .m files to .mm and you can then use c++ in your iPhone project.

笨死的猪 2024-11-12 00:42:57

卷积神经网络是迄今为止手写数字的最佳算法。大多数系统(例如 USPS 等)都实现了这些算法。这里有几篇解释这些算法的论文。
http://yann.lecun.com/exdb/lenet/

Convolution Neural Networks are by far the best algorithms for hand written digits. The are implemented in most systems like USPS etc. Here are few papers explaining the algorithms.
http://yann.lecun.com/exdb/lenet/

中二柚 2024-11-12 00:42:57

这是一个很好的开源,它是iPhone上的ORCDemo。希望它对大家有用你

This is a nice open source ,It is a ORCDemo on iPhone.Hope it is useful to you

旧竹 2024-11-12 00:42:57

OpenCV-Python 中的简单数字识别 OCR

这可能会帮助您。将代码从 Python 转换为 C++ 并不是一项艰巨的任务,因为两者的 OpenCV API 是相同的。

Simple Digit Recognition OCR in OpenCV-Python

This might help you out. Converting the code from Python to C++ is not a difficult task, since OpenCV API's are same for the both.

我还不会笑 2024-11-12 00:42:57

Tesseract 也是一个很好的免费 OCR 引擎,可随时用于 iPhone,并允许您使用自己的训练图像集:
http://tinsuke.wordpress.com/2011/11/01/how-to-compile-and-use-tesseract-3-01-on-ios-sdk-5/

Tesseract is also a nice free OCR engine that is readily available for iPhone and allows you to use your own sets of training images:
http://tinsuke.wordpress.com/2011/11/01/how-to-compile-and-use-tesseract-3-01-on-ios-sdk-5/

迎风吟唱 2024-11-12 00:42:57

HOG + SVM(尝试使用内核)

HOG + SVM (Try to play with kernels)

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