Recognize images in Python

断了今生、忘了曾经 提交于 2019-12-31 10:50:26

问题


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

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

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

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'.

Is it feasible?


回答1:


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.

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)

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.

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.



来源:https://stackoverflow.com/questions/9258825/recognize-images-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!