def ocr(self, file): ocr = BceOCRAPI("02fbe03acf3042a1b40e067bba1971f7", "bb1d4aafe7924fc0829fc33fa26b3347") #黑白处理 # newImg = IMAGE_DIR +file newImg = self.blackWhite(file) #图像压缩处理 disImg = IMAGE_DIR + "ocrdis" + file newImg = self.resizeImg(ori_img=newImg, dst_img=disImg, dst_w=1600, dst_h=1600, save_q=100) with open(newImg, 'rb') as f: content = f.read() content = base64.b64encode(content) try: # ocr # result = ocr.get_ocr_text(content, language='CHN_ENG') result = ocr.get_ocr_text(content, language='ENG') # print("file:"+file+"----------result:"+result) # conf.info("file:"+file+"----------result:"+result) return result except Exception as e: raise
def ocrone(file): ocr = BceOCRAPI("02fbe03acf3042a1b40e067bba1971f7", "bb1d4aafe7924fc0829fc33fa26b3347") ; with open(IMAGE_DIR+file, 'rb') as f: content = f.read() content = base64.b64encode(content) try: #result = ocr.get_ocr_text(content, language='ENG') #result = ocr.get_ocr_text(content, language='CHN_ENG') #result = ocr.get_ocr_line(content, language='CHN_ENG') result = ocr.get_ocr_char(content, language='CHN_ENG') #result = ocr.get_ocr_char(content, language='ENG') #print("file:"+file+"----------result:"+result) logger.info("file:"+file+"----------result:"+result) except Exception as e: raise
def ocrone(file): ocr = BceOCRAPI("02fbe03acf3042a1b40e067bba1971f7", "bb1d4aafe7924fc0829fc33fa26b3347") with open(IMAGE_DIR + file, 'rb') as f: content = f.read() content = base64.b64encode(content) try: #result = ocr.get_ocr_text(content, language='ENG') #result = ocr.get_ocr_text(content, language='CHN_ENG') #result = ocr.get_ocr_line(content, language='CHN_ENG') result = ocr.get_ocr_char(content, language='CHN_ENG') #result = ocr.get_ocr_char(content, language='ENG') #print("file:"+file+"----------result:"+result) logger.info("file:" + file + "----------result:" + result) except Exception as e: raise
def ocr(self,file): ocr = BceOCRAPI("02fbe03acf3042a1b40e067bba1971f7", "bb1d4aafe7924fc0829fc33fa26b3347"); #黑白处理 # newImg = IMAGE_DIR +file newImg = self.blackWhite(file) #图像压缩处理 disImg = IMAGE_DIR +"ocrdis"+file newImg = self.resizeImg(ori_img=newImg,dst_img=disImg,dst_w=1600,dst_h=1600,save_q=100) with open(newImg, 'rb') as f: content = f.read() content = base64.b64encode(content) try: # ocr # result = ocr.get_ocr_text(content, language='CHN_ENG') result = ocr.get_ocr_text(content, language='ENG') # print("file:"+file+"----------result:"+result) return result except Exception as e: raise
#!bin/evn python #-*-coding:utf8-*- ''' python bceocr.py test.jpg ''' from credential import BceCredentials from bceocrapi import BceOCRAPI import base64 import sys import re reload(sys) sys.setdefaultencoding('utf-8') ocr = BceOCRAPI("02fbe03acf3042a1b40e067bba1971f7", "bb1d4aafe7924fc0829fc33fa26b3347") ; with open('public/uploads/bceocr/'+sys.argv[1], 'rb') as f: content = f.read() content = base64.b64encode(content) #result = ocr.get_ocr_text(content, language='CHN_ENG') result = ocr.get_ocr_text(content, language='CHN_ENG') #result = ocr.get_ocr_line(content, language='CHN_ENG') # result = ocr.get_ocr_char(content, language='CHN_ENG') #计算数字个数 digitpatt = re.compile('\d')
#!bin/evn python #-*-coding:utf8-*- ''' python bceocr.py test.jpg ''' from credential import BceCredentials from bceocrapi import BceOCRAPI import base64 import sys import re reload(sys) sys.setdefaultencoding('utf-8') ocr = BceOCRAPI("02fbe03acf3042a1b40e067bba1971f7", "bb1d4aafe7924fc0829fc33fa26b3347") with open('public/uploads/bceocr/' + sys.argv[1], 'rb') as f: content = f.read() content = base64.b64encode(content) #result = ocr.get_ocr_text(content, language='CHN_ENG') result = ocr.get_ocr_text(content, language='CHN_ENG') #result = ocr.get_ocr_line(content, language='CHN_ENG') # result = ocr.get_ocr_char(content, language='CHN_ENG') #计算数字个数 digitpatt = re.compile('\d')