Poor man's OCR: need performance improvement tips

John J. Lee jjl at pobox.com
Sat Sep 24 18:53:20 EDT 2005


"qvx" <qvx3000 at gmail.com> writes:
[...]
> 4. Process each line: compare pixels of each letter of alphabet with
> corresponding pixels in line of input picture. This consists of loops
> comparing pixel by pixel. This is my performance bottleneck.
> 
> I'm using PIL for initial image processing. But then I use plain Python
> loops for pixel matrix comparision. One nice optimization was to call
> PIL.Image.getdata() at the begining and then use data[y*w+x] instead of
> PIL.Image.getpixel(xy). I would like to compare each character raster
> with corresponding image pixels in a "single operation" and avoid
> (Python) loops.
[...]

I don't know what exactly "compare" means here, so no Numeric code,
but GIYF when it comes to the PIL<-->Numeric conversion (I imagine
numarray is almost identical here, though I've not used it in anger):

http://effbot.org/zone/pil-numpy.htm


Since you mention C++, scipy.weave may also be of interest to you.


John




More information about the Python-list mailing list