2017-03-23 49 views
0

我正在使用Python來做一些處理,並且我需要使用Tesseract進行OCR。有沒有一種方法可以讓我從蟒蛇,鍵入:如何從Python訪問Tesseract的命令行?

「正方體--tessdata-目錄的/ usr /股imagename outputbase -l工程-psm 3」

進入命令行以某種方式或等值?

謝謝!

+0

[在Python中調用外部命令]的可能重複(http://stackoverflow.com/questions/89228/calling-an-external-command-in-python) – sashoalm

回答

0

請參閱下面的示例。

import subprocess 

p = subprocess.Popen(["ping", "localhost"], stdout=subprocess.PIPE) 
output, err = p.communicate() 
print 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 

更換["ping", "localhost"]在例如與

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

你可以進一步檢查examples這裏,以獲取更多信息這execute-shell-commands-in-python問題和Python 2.7 doc