Mac下安装PIL相关问题处理

另外tesseract依赖leptonica-1.69,注意安装tesseract前,首先安装leptonica,编译tesseract前指定:CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" ./configure


http://www.hulufei.com/post/how-to-install-pytesser-in-mac

好吧,假定你在Mac折腾pytesser遇到了问题,这里是一些个人经验的记录,希望能提供一些参考

Mac OS X 10.6(Snow Leopard),pytesser-0.0.1,tesseract-3.00

pytesser实际上只是一个方便Python调用terract-ocr引擎的库

第一步,安装OCR引擎,tesseract-ocr (http://code.google.com/p/tesseract-ocr/

需要编译安装,下载源码包:tesseract-3.00.tar.gz,流程一套:

./configure
make
sudo make install

第二步,下载语言包,eng.traineddata.gz (English language data for Tesseract (3.00 and up))

将解压后的语言包文件复制到terract的tessdata目录,如果编译时没有指定目录,默认应该是/usr/local/share/tessdata

现在在终端下输入tesseract应该能找到这个命令了

第三步,安装PIL

tesseract本身不支持png,jpg这样图片格式,pytesser需要利用PIL将这种图片转换成tif格式,这是安装PIL的目的之一

sudo easy_install pil

有可能会出现import PIL还是找不到的情况,可以尝试这样修复:

cd /Library/Python/2.6/site-packages/
ln -s PIL-1.1.7-py2.6-macosx-10.6-universal.egg/ PIL

第四步,下载pytesser(http://code.google.com/p/pytesser/

解压pytesser就是一个可用的Python包,按照pytesser里面的示例使用,下面是遇到一些错误

IOError: [Errno 2] No such file or directory: 'tesseract.log'

修改errors.py文件中的check_for_errors函数:

def check_for_errors(logfile = "tesseract.log"):
    raise Tesser_General_Exception

为了能够获取调用tesseract命令扫描返回的字符串,需要修改调用方式,将pytesser.py中的call_tesseract函数其中两行:

proc = subprocess.Popen(args)
retcode = proc.wait()

替换为

retcode = subprocess.call(args)

经过这些调整,pytesser终于可以在Mac下可用了。

p.s tesseract只能扫描出白底黑字的图片


http://mariz.org/blog/2007/01/26/mac-os-x-decoder-jpeg-not-available/


If you are using  PIL(Python Imaging Library) on Mac OS X(Tiger), you will probably have a  "decoder jpeg not available" when resizing a jpeg image.
This probably means that PIL doesn't have JPEG support, because libjpeg wasn't found when PIL was being configured. 
Here is the solution:
  • Download, compile and install jpeglib and zlib
  • Edit PIL setup.py and change to:
    JPEG_ROOT = "/usr/local/include"
    ZLIB_ROOT = "/usr/local/include"
    
  • Compile:
    python setup.py build_ext -i
    
  • Test:
    python selftest.py
    
  • If the result is something like this:
    "57 tests passed."
    
  • You are ready to go:
    python setup.py install


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值