ocr_convert.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. # -*- coding:utf-8 -*-
  2. import sys, os, time
  3. reload(sys)
  4. sys.setdefaultencoding("utf-8")
  5. from TST.NetOCR import *
  6. from ssat_sdk.picture import image_util
  7. from ssat_sdk.utils import LoggingUtil
  8. from sat_environment import *
  9. from utils import string_util
  10. from picture.ocr_baidu import OCRBaidu
  11. from picture.ocr_tesseract import OCRTes
  12. from picture import ocr_tesseract
  13. import json
  14. import cv2 as cv
  15. import numpy as np
  16. EXP_Info = "ERR<Exp>"
  17. #所有语言定义
  18. OCR_LanDIC = ["chineseprc+english", "chinesetaiwan+english", "spanish", "chineseprc","chinesetaiwan","russian","french"
  19. ,"english","vietnamese","hebrew","thai","arabic","portuguese","german","italian","japanese","korean"]
  20. '''
  21. OCR Type定义:
  22. abbyy:0~999
  23. tesseract:1000~9999
  24. baidu:10000~10100
  25. '''
  26. #泰彼OCR定义
  27. Abbyy_LanDIC = {"chineseprc+english": "ChinesePRC+English", "chinesetaiwan+english": "ChineseTaiwan+English",
  28. "spanish": "Spanish",
  29. "chineseprc": "ChinesePRC", "chinesetaiwan": "ChineseTaiwan", "russian": "Russian", "french": "French",
  30. "english": "English", "vietnamese": "Vietnamese", "hebrew": "Hebrew", "thai": "Thai"
  31. }
  32. ABBYY_BASIC = 0
  33. ABBYY_MAX = 999
  34. ABBYY_CONTRAST_ENABLE = ABBYY_BASIC
  35. ABBYY_CONTRAST_DISABLE = ABBYY_BASIC+1
  36. ABBYY_NORMAL = ABBYY_BASIC+2
  37. ABBYY_CONVERSION_ENGINE_ENABLE = ABBYY_BASIC+3
  38. ABBYY_INVERT_IMAGE_ENABLE = ABBYY_BASIC+4
  39. ABBYY_CONVERSION_AND_CONTRAST_ENABLE = ABBYY_BASIC+5
  40. ABBYY_ENGLISH_RECOMMENDATION_MODE = 253
  41. Abbyy_TypeList = [ABBYY_CONTRAST_ENABLE,ABBYY_CONTRAST_DISABLE,ABBYY_NORMAL,ABBYY_CONVERSION_ENGINE_ENABLE
  42. ,ABBYY_INVERT_IMAGE_ENABLE,ABBYY_CONVERSION_AND_CONTRAST_ENABLE,ABBYY_ENGLISH_RECOMMENDATION_MODE]
  43. #Tesseract OCR定义。没有Type
  44. Tes_LanDIC = ocr_tesseract.Tes_LanDIC
  45. Tes_BASIC = 1000
  46. Tes_MAX = 9999
  47. Tes_TypeList = [Tes_BASIC]
  48. #百度 OCR定义。
  49. Baidu_LanDIC = {"chineseprc+english": "CHN_ENG",
  50. "spanish": "SPA","russian": "RUS",
  51. "french": "FRE",
  52. "english": "ENG", "portuguese": "POR", "german": "GER", "italian": "ITA", "japanese": "JAP", "korean": "KOR"}
  53. Baidu_BASIC = 10000
  54. Baidu_MAX = 10100
  55. Baidu_General = Baidu_BASIC
  56. Baidu_Accurate = Baidu_BASIC + 1
  57. Baidu_TypeList=[Baidu_General,Baidu_Accurate]
  58. OCR_TMP_DIR = getOCRTmpDir()
  59. OCR_ERR_DIR = getOCRErrDir()
  60. if not os.path.exists(OCR_TMP_DIR):
  61. os.mkdir(OCR_TMP_DIR)
  62. if not os.path.exists(OCR_ERR_DIR):
  63. os.mkdir(OCR_ERR_DIR)
  64. class OCRConvert():
  65. OCR_PRODUCT_BAIDU = "baidu"
  66. OCR_PRODUCT_ABBYY = "abbyy"
  67. OCR_PRODUCT_TES = "tesseract"
  68. def __init__(self):
  69. self.timeout = 3
  70. self.ocrBaidu = OCRBaidu()
  71. self.ocrTes = OCRTes()
  72. def setTimeOut(self, seconds):
  73. self.timeout = seconds
  74. '''
  75. 根据自然语言描述,和OCR Type,返回OCR识别语言的字符串定义
  76. :param language: chineseprc+english/chinesetaiwan+english/spanish/chineseprc/chinesetaiwan/russian/french/english/vietnamese/hebrew
  77. /portuguese/german/italian/japanese/korean
  78. :param type: OCR识别类型编号
  79. :return OCR语言类别定义的字符串.如果在字典库找不到,直接返回传入的language。
  80. '''
  81. def getOCRLaParam(self, language, type):
  82. if type <ABBYY_MAX and type >= ABBYY_BASIC:
  83. if Abbyy_LanDIC.has_key(language.lower()):
  84. return Abbyy_LanDIC[language.lower()]
  85. else:
  86. return language
  87. elif type <Tes_MAX and type >= Tes_BASIC:
  88. if Tes_LanDIC.has_key(language.lower()):
  89. return Tes_LanDIC[language.lower()]
  90. else:
  91. return language
  92. elif type < Baidu_MAX and type>=Baidu_BASIC:
  93. if Baidu_LanDIC.has_key(language.lower()):
  94. return Baidu_LanDIC[language.lower()]
  95. else:
  96. return language
  97. else:
  98. return language
  99. """
  100. 根据传入的语言类型(无论自然语言类型,或者ocr语言类型),转换成目标自然语言类型
  101. """
  102. def getHumanLan(self, language, type):
  103. if type < ABBYY_MAX and type >= ABBYY_BASIC:
  104. if Abbyy_LanDIC.has_key(language):
  105. return language
  106. for humanLan in Abbyy_LanDIC:
  107. # print "getHumanLan:", humanLan
  108. if string_util.strcmp(Abbyy_LanDIC[humanLan], language):
  109. return humanLan
  110. return ""
  111. elif type < Tes_MAX and type >= Tes_BASIC:
  112. if Tes_LanDIC.has_key(language):
  113. return language
  114. for humanLan in Tes_LanDIC:
  115. # print "getHumanLan:", humanLan
  116. if string_util.strcmp(Tes_LanDIC[humanLan], language):
  117. return humanLan
  118. return ""
  119. elif type < Baidu_MAX and type >= Baidu_BASIC:
  120. if Baidu_LanDIC.has_key(language):
  121. return language
  122. for humanLan in Baidu_LanDIC:
  123. # print "getHumanLan:", humanLan
  124. if string_util.strcmp(Baidu_LanDIC[humanLan], language):
  125. return humanLan
  126. return ""
  127. else:
  128. return ""
  129. '''
  130. 根据传入的OCR 类型,返回厂家名字
  131. :param type:OCR识别类型编号
  132. :return OCR厂家名称
  133. '''
  134. def getOCRProductByType(self, type):
  135. if type < ABBYY_MAX and type >= ABBYY_BASIC:
  136. return self.OCR_PRODUCT_ABBYY
  137. elif type < Tes_MAX and type >= Tes_BASIC:
  138. return self.OCR_PRODUCT_TES
  139. elif type < Baidu_MAX and type >= Baidu_BASIC:
  140. return self.OCR_PRODUCT_BAIDU
  141. else:
  142. return ""
  143. def sendPicToServer(self, picPath, lan, type):
  144. try:
  145. ocr = NetOCR(getOCRIpAddr(), getOCRPort(), picPath, lan, type)
  146. # ocr.setTimeOut(self.timeout)
  147. return ocr
  148. except Exception, e:
  149. print "OCR", u"SCBC OCR连接失败,Err:" ,e
  150. return None
  151. '''
  152. 在getStr函数基础上,添加了图片处理参数。处理图片后,再使用图片识别。
  153. :param imgProcParams: 字典:{"Threshold":[127,250, 阈值类型], "contrast":[], "LaplaceSharp":[], "Noisy":[]}
  154. :param picPath: 图片路径
  155. :param lan :OCR识别用的语言类别,不同OCR产品的定义不一样
  156. :param type:OCR识别的类型编号
  157. :return 识别后的字符串。同getStr函数
  158. '''
  159. def getStrWithImgProcess(self, picPath, imgProcParams, lan, type, reconTimes = 5):
  160. print "getStrWithImgProcess, param:", picPath, imgProcParams,lan,type,reconTimes
  161. destPicPath = os.path.join(OCR_TMP_DIR, "ocr_"+str(time.time())+".png")
  162. img = self.handleImage(picPath, imgProcParams)
  163. cv.imwrite(destPicPath, img)
  164. return self.getStr(destPicPath, lan, type)
  165. '''
  166. 根据图片处理参数,处理图片,返回image对象
  167. :param imgProcParams: 字典:{"Threshold":[127,250, 阈值类型], "contrast":[], "LaplaceSharp":[], "Noisy":[]}
  168. :param picPath: 图片路径
  169. :return 返回图片image对象
  170. '''
  171. def handleImage(self, picPath, imgProcParams):
  172. print u"handleImage,imgProcParams:", imgProcParams
  173. srcImg = cv.imread(picPath)
  174. destPicPath = picPath
  175. img = srcImg
  176. if imgProcParams.has_key("Threshold"):
  177. img = image_util.saveThresholdPicImg(srcImg, \
  178. imgProcParams["Threshold"][0], imgProcParams["Threshold"][1], imgProcParams["Threshold"][2])
  179. return img
  180. '''
  181. 根据传入的图片路径,获取图片的字符串。
  182. :param picPath.图片的绝对路径
  183. :param lan. OCR识别的文字语言类别。
  184. type<10000:
  185. ChinesePRC+English
  186. ChineseTaiwan+English
  187. Spanish
  188. ChinesePRC
  189. ChineseTaiwan
  190. Russian
  191. French
  192. English
  193. Vietnamese
  194. Hebrew
  195. Thai
  196. :param type. OCR识别文字时的识别模型编号。
  197. :param reconTimes. OCR识别文字异常时,重新尝试识别的次数,默认为5次,最高为10次。
  198. :return str. 返回识别的字符串。未识别到,返回"",如果type未10000,10001表示采用百度OCR,返回字符串数组
  199. 如果属于字符识别异常:返回字符串"ERR<Exp>"
  200. '''
  201. def getStr(self, picPath, lan, type, reconTimes = 5):
  202. print "getStr, param:", picPath, lan, type, reconTimes
  203. lan = self.getOCRLaParam(lan, type)
  204. if type < ABBYY_MAX and type >= ABBYY_BASIC:
  205. ocr = self.sendPicToServer(picPath, lan, type)
  206. if (ocr == None):
  207. return ""
  208. try:
  209. LoggingUtil.printLog("OCR", u"泰彼 OCR")
  210. string = ocr.getStr()
  211. # print string
  212. return string_util.toUTF8Str(string)
  213. except Exception, e:
  214. print u"OCR", u"获取文字失败.error:" ,e
  215. return EXP_Info
  216. finally:
  217. ocr.close()
  218. elif type >=Tes_BASIC and type < Tes_MAX:
  219. return self.ocrTes.getStr(picPath, lan, type)
  220. else:
  221. # 超出范围的重连次数,都默认为10次;
  222. if reconTimes > 10 or reconTimes < 0:
  223. reconTimes = 10
  224. # by zippo 把百度的返回数组转换成字符串,统一返回值
  225. allStr = self.ocr_BaiduGS(picPath, type - 10000, lan)
  226. while allStr is None or allStr == EXP_Info and reconTimes > 0:
  227. LoggingUtil.printLog("OCR", u'百度OCR重连')
  228. time.sleep(1)
  229. reconTimes -= 1
  230. allStr = self.ocr_BaiduGS(picPath, type - 10000, lan)
  231. return EXP_Info if allStr is None else allStr
  232. # return self.ocr_Baidu(picPath, type-10000, lan)
  233. # 字符串比对
  234. def cmpOcrStr(self, ocrStr, stdStr, erase = [], picPath=None):
  235. # print u"OCR_Convert:cmpOcrStr start param:", ocrStr, stdStr, erase, picPath if type(picPath) == type('') else 'path is imgObj'
  236. if type(ocrStr) == type(u''):
  237. ocrStr = str(ocrStr).encode('utf-8')
  238. else:
  239. try:
  240. ocrStr = str(ocrStr).encode('utf-8')
  241. except Exception:
  242. pass
  243. if type(stdStr) == type(u''):
  244. stdStr = str(stdStr).encode('utf-8')
  245. else:
  246. try:
  247. stdStr = str(stdStr).encode('utf-8')
  248. except Exception:
  249. pass
  250. # 去除空格;
  251. ocrStr = ocrStr.replace(' ', '').lower()
  252. stdStr = stdStr.replace(' ', '').lower()
  253. # 移除指定字符;
  254. for char in erase:
  255. ocrStr = ocrStr.replace(char, '').lower()
  256. stdStr = stdStr.replace(char, '').lower()
  257. #长度判断
  258. if len(ocrStr) != len(stdStr):
  259. self.saveOCRErr(ocrStr, stdStr, picPath)
  260. return False
  261. # 遍历字符串
  262. result = True
  263. # 忽略的相似字符;
  264. ignore = [{'i','l','1','t','I','T'},{'o','0','O'}]
  265. cnt = len(stdStr)
  266. for i in range(0, cnt):
  267. if stdStr[i] == ocrStr[i]:
  268. continue
  269. elif stdStr[i] in ignore[0] and ocrStr[i] in ignore[0]:
  270. continue
  271. elif stdStr[i] in ignore[1] and ocrStr[i] in ignore[1]:
  272. continue
  273. else:
  274. result = False
  275. break
  276. #endfor
  277. if result is False:
  278. self.saveOCRErr(ocrStr,stdStr, picPath)
  279. return result
  280. #end
  281. def saveOCRErr(self, ocrStr, stdStr, pic):
  282. if pic is None or pic == '':
  283. print u"Warn:Save OCR Error picture fail. <pic> is None or Empty"
  284. return
  285. destPicName = unicode(ocrStr + "_" + stdStr + ".png")
  286. destPic = os.path.join(OCR_ERR_DIR, destPicName)
  287. try:
  288. if type(pic) == type(""):# 如果是路径;
  289. shutil.copyfile(pic, destPic)
  290. else:# 如果是图像数组;numpy.ndarray
  291. cv.imwrite(destPic,pic)
  292. except Exception,e:
  293. print u"Warn:Save OCR Error picture fail.",e.message
  294. '''
  295. 根据传入的目标字符串stdStr,如果指定的OCR type可以识别到文字,则返回True和OCR字符串。
  296. 如果指定的OCR type识别不到文字,遍历所有OCR type方式识别文字,返回最终遍历结果。
  297. :param stdStr : 目标字符串
  298. :param picPath: 图片路径
  299. :param lan :OCR识别用的语言类别,不同OCR产品的定义不一样
  300. :param type:OCR识别的类型编号
  301. :param imgProcParams: 字典:{"Threshold":[127,250, 阈值类型], "contrast":[], "LaplaceSharp":[], "Noisy":[]}
  302. :param erase:erase 字符数组,文字比对时,需过滤掉的字符。
  303. :return boolean,string: boolean标识是否成功(ture/false),string 是指定的OCR type识别到的文字。
  304. '''
  305. def findPicStr(self, stdStr, picPath, lan, type, imgProcParams={}, erase = []):
  306. #匹配自然语言类型
  307. humanLan = self.getHumanLan(lan, type)
  308. ocrStr = self.getStrWithImgProcess(picPath, imgProcParams, lan, type, reconTimes = 1)
  309. ret = self.cmpOcrStr(ocrStr, stdStr,erase, picPath)
  310. return ret,ocrStr
  311. if ret is True:
  312. return True,ocrStr
  313. for typeA in Abbyy_TypeList:
  314. if type <> typeA:
  315. ocrLan = self.getOCRLaParam(humanLan, typeA)
  316. ocrStr = self.getStrWithImgProcess(picPath, imgProcParams, ocrLan, typeA, reconTimes=1)
  317. ret = self.cmpOcrStr(ocrStr, stdStr, erase, "")
  318. if ret is True:
  319. return True, ocrStr
  320. for typeB in Baidu_TypeList:
  321. if type <> typeB:
  322. ocrLan = self.getOCRLaParam(humanLan, typeB)
  323. ocrStr = self.getStrWithImgProcess(picPath, imgProcParams, ocrLan, typeB, reconTimes=1)
  324. ret = self.cmpOcrStr(ocrStr, stdStr, erase, "")
  325. if ret is True:
  326. return True, ocrStr
  327. return False, ocrStr
  328. # 指定ocr列表,遍历查找;
  329. def findPicStrEx(self, stdStr, picPath, list_ocr, imgProcParams={}, erase = []):
  330. result,ocrStr = False,''
  331. for item in list_ocr:
  332. ocrStr = self.getStrWithImgProcess(picPath, imgProcParams, item["lan"], item["type"], reconTimes = 1)
  333. if stdStr.lower() in ocrStr.lower():
  334. result = True
  335. break
  336. return result, ocrStr
  337. '''
  338. 根据传入的图片路径,获取图片的字符串。
  339. :param picPath.图片的绝对路径
  340. :param lan. OCR识别的文字语言类别。
  341. :param type. OCR识别文字时的识别模型编号。
  342. :param area. OCR识别的图片区域。要求是图片刚好适配的矩形框区域。
  343. :return str. 返回识别的字符串。未识别到,返回"".
  344. '''
  345. def getPositionStr(self, picPath, lan, type, area):
  346. ocr = self.sendPicToServer(picPath, lan, type)
  347. if (ocr == None):
  348. return ""
  349. try:
  350. startX, startY, endX, endY = area
  351. string = ocr.getPositionStr(startX, startY, endX, endY)
  352. return string_util.toUTF8Str(string)
  353. except Exception, e:
  354. print "OCR", u"获取文字失败.error:",e
  355. return EXP_Info
  356. finally:
  357. ocr.close()
  358. '''
  359. 根据传入的图片路径,获取图片的字符串。
  360. :param picPath.图片的绝对路径
  361. :param lan. OCR识别的文字语言类别。
  362. :param type. OCR识别文字时的识别模型编号。
  363. :param keyword. OCR需要寻找的文字。
  364. :return str. 返回识别的字符串。未识别到,返回[-1,-1,-1,-1],
  365. '''
  366. def getStrPosition(self, picPath, lan, type, keyword):
  367. ocr = self.sendPicToServer(picPath, lan, type)
  368. if (ocr == None):
  369. return [-1, -1, -1, -1]
  370. try:
  371. area = ocr.getStrPosition(keyword)
  372. return area
  373. except Exception, e:
  374. print "OCR", u"获取文字位置失败.error:",e
  375. return [-1, -1, -1, -1]
  376. finally:
  377. ocr.close()
  378. '''
  379. 根据传入的图片路径,获取图片的字符串。
  380. :param picPath.图片的绝对路径
  381. :param lan. OCR识别的文字语言类别。
  382. :param type. OCR识别文字时的识别模型编号。
  383. :param area. OCR识别的图片区域。
  384. :return str. 返回识别的字符串。未识别到,返回"",
  385. '''
  386. def getAreaStr(self, picPath, lan, type, area):
  387. ocr = self.sendPicToServer(picPath, lan, type)
  388. if (ocr == None):
  389. return ""
  390. try:
  391. startX, startY, endX, endY = area
  392. string = ocr.getAreaStr(startX, startY, endX, endY)
  393. return string_util.toUTF8Str(string)
  394. except Exception, e:
  395. print "OCR", u'获取文字失败.error:',e
  396. return EXP_Info
  397. finally:
  398. ocr.close()
  399. def close(self):
  400. pass
  401. '''
  402. :param language:
  403. 识别语言类型,默认为CHN_ENG。可选值包括:
  404. - CHN_ENG#中英文混合;
  405. - ENG#英文;
  406. - POR#葡萄牙语;
  407. - FRE#法语;
  408. - GER#德语;
  409. - ITA#意大利语;
  410. - SPA#西班牙语;
  411. - RUS#俄语;
  412. - JAP#日语;
  413. - KOR#韩语
  414. :param type:
  415. 0 basicGeneral;1 basicAccurate 高精度通用文字; 选择高精度时,language参数失效。
  416. :return :
  417. 正常返回字符串数组,如果异常,返回['ERR<Exp>']
  418. '''
  419. def ocr_Baidu(self, pic_path, type, language="CHN_ENG"):
  420. if type == 0:
  421. ret = self.ocrBaidu.basicGeneral(pic_path, language)
  422. if ret is None:
  423. return [EXP_Info]
  424. return ret
  425. elif type == 1:
  426. ret = self.ocrBaidu.basicAccurate(pic_path, language)
  427. if ret is None:
  428. return [EXP_Info]
  429. return ret
  430. '''
  431. :param language:
  432. 识别语言类型,默认为CHN_ENG。可选值包括:
  433. - CHN_ENG#中英文混合;
  434. - ENG#英文;
  435. - POR#葡萄牙语;
  436. - FRE#法语;
  437. - GER#德语;
  438. - ITA#意大利语;
  439. - SPA#西班牙语;
  440. - RUS#俄语;
  441. - JAP#日语;
  442. - KOR#韩语
  443. :param type:
  444. 0 basicGeneral;1 basicAccurate 高精度通用文字; 选择高精度时,language参数失效。
  445. '''
  446. def ocr_BaiduGS(self, pic_path, type, language="CHN_ENG"):
  447. str1 = ""
  448. strList = self.ocr_Baidu(pic_path, type, language="CHN_ENG")
  449. for index in range(strList.__len__()):
  450. strT = strList[index]
  451. if index == 0:
  452. str1 = strT
  453. continue
  454. str1 += " "+strT
  455. return str1
  456. if __name__ == "__main__":
  457. if 0:
  458. # DIR = r"D:\ocr_err\\"
  459. DIR = r"D:\temp-pic\gbk\\"
  460. # picPath = DIR + "mi_4.png"
  461. # picPath = DIR + "ocr_2.png"
  462. picPath = DIR + "546473243246047508.png"
  463. # DIR = u"D:/temp-pic/"
  464. # picPath = DIR + "20180604113525.png"
  465. # pic_path = r"D:\ocr_err\checkChannelList_crop.jpg"
  466. pic_path = r"D:\ocr_err\11.png"
  467. pic_path = r"D:\ocr_err\mi_1.png"
  468. pic_path = r"D:\ocr_err\mi\5.png"
  469. ocrCon = OCRConvert()
  470. # allStr = ocrCon.getStr(pic_path,"english", 1000, -1)
  471. allStr = ocrCon.getStr(pic_path,"chineseprc", 1000, -1)
  472. print "ocr:",allStr
  473. sys.exit(0)
  474. if 0:
  475. # s = u'林'
  476. # print s.encode('utf-8')
  477. # print s.encode('gbk')
  478. ocrCon = OCRConvert()
  479. ocrStr = u"1你好T0i"
  480. stdStr = u"i你好io1"
  481. result = ocrCon.cmpOcrStr(ocrStr, stdStr)
  482. print u'结果',result
  483. ocrStr = "1你好T0i"
  484. stdStr = "i你好io1"
  485. result = ocrCon.cmpOcrStr(ocrStr, stdStr)
  486. print u'结果',result
  487. ocrStr = "1你好T0i"
  488. stdStr = u"i你好io1"
  489. result = ocrCon.cmpOcrStr(ocrStr, stdStr)
  490. print u'结果',result
  491. # ocrStr = unicode("1你好T0i",'gbk')
  492. # stdStr = u"i你好io1"
  493. # print ocrStr,stdStr,type(ocrStr),type(stdStr)
  494. # result = ocrCon.cmpOcrStr(ocrStr, stdStr)
  495. # print u'结果',result
  496. if 1:
  497. ocr = OCRConvert()
  498. pic = r'D:\temp-pic\UI\NT72-1\home.png'
  499. # strAll = ocr.getStr(pic, "english", 253)
  500. # print "strall:",strAll
  501. position = ocr.getStrPosition(pic, "english", 253, "hdmi")
  502. print "position:",position