用Python识别图像 [英] Recognize images in Python

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

问题描述

我对OCR识别和Python都很新。

I'm kinda new both to OCR recognition and Python.

我想要实现的是从Python脚本运行Tesseract来识别一些特别数字在.tif。

What I'm trying to achieve is to run Tesseract from a Python script to 'recognize' some particular figures in a .tif.

我以为我可以为Tesseract做一些培训,但我没有在Google上找到任何类似的主题,在这里也是如此。

I thought I could do some training for Tesseract but I didn't find any similar topic on Google and here at SO.

基本上我有一些.tif包含几个图像(如'箭头','花'和其他图标),我希望脚本打印为输出名称那个图标。如果找到箭头,则打印'箭头'。

Basically I have some .tif that contains several images (like an 'arrow', a 'flower' and other icons), and I want the script to print as output the name of that icon. If it finds an arrow then print 'arrow'.

可行吗?

推荐答案

这绝不是一个完整的答案,但如果tif中有多个图像,并且如果您事先知道尺寸,则可以在对图像样本进行分类之前对其进行标准化。你可以将图像切割成tif中所有可能的矩形。

This is by no means a complete answer, but if there are multiple images in the tif and if you know the size in advance, you can standardize the image samples prior to classifying them. You would cut up the image into all the possible rectangles in the tif.

所以当你创建一个分类器时(我这里没有提到方法),最终结果将合成分类所有较小的矩形。

So when you create a classifier (I don't mention the methods here), the end result would take a synthesis of classifying all of the smaller rectangles.

因此,如果给出一个tif,'箭头'或'花'图像是16像素×16像素,比方说,你可以使用
Python PIL 来创建示例。

So if given a tif , the 'arrow' or 'flower' images are 16px by 16px , say, you can use Python PIL to create the samples.

from PIL import Image

image_samples = []

im = Image.open("input.tif")
sample_dimensions = (16,16)

for box in get_all_corner_combinations(im, sample_dimensions):

    image_samples.append(im.crop(box))


classifier = YourClassifier()

classifications = []

for sample in image_samples:
    classifications.append (classifier (sample))

label = fuse_classifications (classifications)

同样,我没有谈到实际编写 YourClassifier 的学习步骤。但希望这有助于解决部分问题。

Again, I didn't talk about the learning step of actually writing YourClassifier. But hopefully this helps with laying out part of the problem.

关于学习分类图像以及清理噪声的工作主题有很多研究。分类之前的图像。

There is a lot of research on the subject of learning to classify images as well as work in cleaning up noise in images before classifying them.

考虑浏览现有Python机器学习库的这个很好的集合。

Consider browsing through this nice collection of existing Python machine learning libraries.

http://scipy-lectures.github.com/advanced/scikit-learn/index .html

还有许多与图像相关的技术。

There are many techniques that relate to images as well.

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

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