rpa_ocr_normal

通用文字图片识别,获取图片中的文字信息

1. 函数

rpa_ocr_normal(picPath)

  • picPath:识别图片的本地绝对路径.

    说明:图片大小不能超过5M

2. 返回值

字符串类型,图片识别文字信息JSON串:不为空表示成功,为空表示识别信息失败,通过rpa_getLastErrorCode()获取错误码,rpa_getLastErrorMsg()获取错误信息。 可以使用rpa_ocr_parseCharacterInfo解析成RpaHelper.CharacterRecognitionResult,CharacterRecognitionResult类定义如下:

class TextInfo:
    def __init__(self,jsonInfo):
        self.area_x = jsonInfo['location']['x']
        self.area_y =  jsonInfo['location']['y']
        self.area_width = jsonInfo['location']['width']
        self.area_height = jsonInfo['location']['height']
        self.probability = jsonInfo['score']  
        self.text = jsonInfo['text']  

class CharacterRecognitionResult:
    def __init__(self,result):
        self.success = self.__translateStatus(result['message'])
        self.status = result['message']  
        textInfoArr = []
        jsonInfo = result['targets']
        for info in jsonInfo:
            textInfoArr.append(TextInfo(info))
        self.listText = textInfoArr
        self.url = result['url']

    def __translateStatus(self, statusCode):
        if statusCode == 'Success':
            return True
        return False

3. 示例

picPath = "D:/test/识别图片.png"
resultData = rpa_ocr_normal(pic_path)

if not resultData:
    rpa_log('识别信息为空,错误信息:err=%s' % rpa_getLastErrorMsg())
    rpa_exit()

recognizeResult = rpa_ocr_parseCharacterInfo(resultData)
if not recognizeResult:
    rpa_log('解析识别结果失败,错误信息:err=%s' % rpa_getLastErrorMsg())
    rpa_exit()

#识别结果标识
rpa_log('status=%s(%s)' % (recognizeResult.success,recognizeResult.status))

#识别文本信息
listText = recognizeResult.listText
for textInfo in listText:
    rpa_log('识别文本:%s' % textInfo.text)
    rpa_log('识别结果可信度:%s' % textInfo.probability)
    rpa_log('识别结果区域信息:x=%s,y=%s,width=%s,height=%s' % (textInfo.area_x,textInfo.area_y,textInfo.area_width,textInfo.area_height))
powered by Gitbook修订时间: 2021-04-15 15:56:53

找到相关内容

    未找到""相关内容

    找到相关内容

      未找到""相关内容