python如何使用tessract,如何从Python访问Tesseract的命令行?

I am using Python to do some processing, and I need to OCR with Tesseract. Is there a way I can, from python, type this:

"tesseract --tessdata-dir /usr/share imagename outputbase -l eng -psm 3"

into the command line somehow or its equivalent?

thanks!

解决方案

See the example below.

import subprocess

p = subprocess.Popen(["ping", "localhost"], stdout=subprocess.PIPE)

output, err = p.communicate()

print output

Output:

Pinging w10-PC [::1] with 32 bytes of data:

Reply from ::1: time<1ms

Reply from ::1: time<1ms

Reply from ::1: time<1ms

Reply from ::1: time<1ms

Ping statistics for ::1:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 0ms, Maximum = 0ms, Average = 0ms

Replace ["ping", "localhost"] in the example with

["tesseract", "--tessdata-dir", "/usr/share", "imagename", "outputbase", "-l", "eng", "-psm", "3"].

You may further check examples here, this execute-shell-commands-in-python question and Python 2.7 doc for more information.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值