1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- # -*- coding:utf-8 -*-
- import os
- import sys
- import time
- import numpy as np
- import cv2 as cv
- import json
- from BaseLog import CBaseLog
- from OptionConfig import COptionConfig
- from ssat_sdk import OCRConvert, ImageCMP
- # 测试加头文件;
- from TData import CTData
- from UIT_PathManage import UITPathManage
- class COptionOCR(CBaseLog):
- def __init__(self, optionConfig, pathManager):
- # COptionConfig对象;
- self.__optionConfig = optionConfig
- if self.__optionConfig is None:
- self.error("configManger对象空")
- # 路径对象;
- self.__pathManager = pathManager
- # 创建OCR对象
- self.__ocr = OCRConvert()
- # 图片切割对象
- self.__imgCMP = ImageCMP()
-
- '''
- 函数:获取指定原图中指定的文本区域内的文本内容;
- 参数:
- src_pid: 原图文件路径;
- texb_box: 原图中要获取文本内容的区域坐标;
- ocr_config: 使用何种方式识别文本; 示例:{"lan": "ChinesePRC+English", "type": 4}
- 返回:
- 返回文本内容;
- '''
- def getOptionFocusTextByFile(self, src_pic, text_box, ocr_config):
- src_img = cv.imread(src_pic)
- if src_img is None:
- self.error("读取图片失败:%s" % src_pic)
- return None
- return self.getOptionFocusText(src_img, text_box, ocr_config)
-
- '''
- 函数:获取指定原图中指定的文本区域内的文本内容;
- 参数:
- src_img: 原图图片对象(cv2.imread的结果值);
- texb_box: 原图中要获取文本内容的区域坐标;
- ocr_config: 使用何种方式识别文本; 示例:{"lan": "ChinesePRC+English", "type": 4}
- 返回:
- 返回文本内容;
- '''
- def getOptionFocusText(self, src_img, text_box, ocr_config):
- pass
- '''
- 函数:识别指定图片文件的文本内容;
- 参数:
- text_pic: 要识别文本的图片路径;
- ocr_config: 使用何种方式识别文本; 示例:{"lan": "ChinesePRC+English", "type": 4}
- 返回:
- '''
- def getImageText(self, text_pic, ocr_config):
- text_img = cv.imread(text_pic)
- if text_img is None:
- self.error("读取图片失败:%s" % text_pic)
- return None
-
- return self.getImageText(text_img, ocr_config)
-
- # end-class
- if __name__ == "__main__":
- tData = CTData()
- upath = UITPathManage(tData)
- opcfg = CoptionConfig(r'D:\SAT\resource\MenuTree\RT2851\2851', upath)
- opfocus = COptionOCR(opcfg, upath)
|