How to access the command line for Tesseract from Python?

情到浓时终转凉″ 提交于 2019-12-12 04:45:10

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/42966322/how-to-access-the-command-line-for-tesseract-from-python

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