python - Can't get output from Tesseract command run through os.system -
i've created function loops on images , gets orientation image tesseract
library. code looks this:
def fix_incorrect_orientation(pathname): filename in os.listdir(pathname): tesseractresult = str(os.system('tesseract ' + pathname + '/' + filename + ' - -psm 0')) print('tesseractresult: ' + tesseractresult) regexobj = re.search('([orientation:]+[\s][0-9]{1})',tesseractresult) if regexobj: orientation = regexobj.groups(0)[0] print('orientation123: ' + str(orientation)) else: print('not getting in regex.')
the result variable tesseractresult
0
though. in terminal following result command:
orientation: 3 orientation in degrees: 90 orientation confidence: 19.60 script: 1 script confidence: 21.33
i've tried catching output os.system
in multiple ways, such popen
, subprocess
without succes. seems can't catch output tesseract
library. so, how should this?
thanks, yenthe
literally 10 minutes after asking question found way.. first import commands:
import commands
and following code trick:
def fix_incorrect_orientation(pathname): filename in os.listdir(pathname): tesseractresult = str(commands.getstatusoutput('tesseract ' + pathname + '/' + filename + ' - -psm 0')) print('tesseractresult: ' + tesseractresult) regexobj = re.search('([orientation:]+[\s][0-9]{1})',tesseractresult) if regexobj: orientation = regexobj.groups(0)[0] print('orientation123: ' + str(orientation)) else: print('not getting in regex.')
this pass command around commands
library , output caught getstatusoutput
commands
library.
Comments
Post a Comment