frompaddleocrimportPaddleOCR,draw_ocr# Paddleocr目前支持中英文、英文、法语、德语、韩语、日语,可以通过修改lang参数进行切换# 参数依次为`ch`, `en`, `french`, `german`, `korean`, `japan`。ocr=PaddleOCR(use_angle_cls=True,lang="ch")# need to run only once to download and load model into memoryimg_path='PaddleOCR/doc/imgs/11.jpg'result=ocr.ocr(img_path,cls=True)foridxinrange(len(result)):res=result[idx]forlineinres:print(line)# 显示结果fromPILimportImageresult=result[0]image=Image.open(img_path).convert('RGB')boxes=[line[0]forlineinresult]txts=[line[1][0]forlineinresult]scores=[line[1][1]forlineinresult]im_show=draw_ocr(image,boxes,txts,scores,font_path='/path/to/PaddleOCR/doc/fonts/simfang.ttf')im_show=Image.fromarray(im_show)im_show.save('result.jpg')
frompaddleocrimportPaddleOCR,draw_ocrocr=PaddleOCR()# need to run only once to download and load model into memoryimg_path='PaddleOCR/doc/imgs/11.jpg'result=ocr.ocr(img_path,cls=False)foridxinrange(len(result)):res=result[idx]forlineinres:print(line)# 显示结果fromPILimportImageresult=result[0]image=Image.open(img_path).convert('RGB')boxes=[line[0]forlineinresult]txts=[line[1][0]forlineinresult]scores=[line[1][1]forlineinresult]im_show=draw_ocr(image,boxes,txts,scores,font_path='/path/to/PaddleOCR/doc/fonts/simfang.ttf')im_show=Image.fromarray(im_show)im_show.save('result.jpg')
frompaddleocrimportPaddleOCRocr=PaddleOCR(use_angle_cls=True)# need to run only once to download and load model into memoryimg_path='PaddleOCR/doc/imgs_words/ch/word_1.jpg'result=ocr.ocr(img_path,det=False,cls=True)foridxinrange(len(result)):res=result[idx]forlineinres:print(line)
frompaddleocrimportPaddleOCR,draw_ocrocr=PaddleOCR()# need to run only once to download and load model into memoryimg_path='PaddleOCR/doc/imgs/11.jpg'result=ocr.ocr(img_path,rec=False)foridxinrange(len(result)):res=result[idx]forlineinres:print(line)# 显示结果fromPILimportImageresult=result[0]image=Image.open(img_path).convert('RGB')im_show=draw_ocr(image,result,txts=None,scores=None,font_path='/path/to/PaddleOCR/doc/fonts/simfang.ttf')im_show=Image.fromarray(im_show)im_show.save('result.jpg')
frompaddleocrimportPaddleOCRocr=PaddleOCR()# need to run only once to download and load model into memoryimg_path='PaddleOCR/doc/imgs_words/ch/word_1.jpg'result=ocr.ocr(img_path,det=False)foridxinrange(len(result)):res=result[idx]forlineinres:print(line)
frompaddleocrimportPaddleOCRocr=PaddleOCR(use_angle_cls=True)# need to run only once to download and load model into memoryimg_path='PaddleOCR/doc/imgs_words/ch/word_1.jpg'result=ocr.ocr(img_path,det=False,rec=False,cls=True)foridxinrange(len(result)):res=result[idx]forlineinres:print(line)
frompaddleocrimportPaddleOCR,draw_ocr,download_with_progressbar# Paddleocr目前支持中英文、英文、法语、德语、韩语、日语,可以通过修改lang参数进行切换# 参数依次为`ch`, `en`, `french`, `german`, `korean`, `japan`。ocr=PaddleOCR(use_angle_cls=True,lang="ch")# need to run only once to download and load model into memoryimg_path='http://n.sinaimg.cn/ent/transform/w630h933/20171222/o111-fypvuqf1838418.jpg'result=ocr.ocr(img_path,cls=True)foridxinrange(len(result)):res=result[idx]forlineinres:print(line)# 显示结果fromPILimportImageresult=result[0]download_with_progressbar(img_path,'tmp.jpg')image=Image.open('tmp.jpg').convert('RGB')boxes=[line[0]forlineinresult]txts=[line[1][0]forlineinresult]scores=[line[1][1]forlineinresult]im_show=draw_ocr(image,boxes,txts,scores,font_path='/path/to/PaddleOCR/doc/fonts/simfang.ttf')im_show=Image.fromarray(im_show)im_show.save('result.jpg')
importcv2frompaddleocrimportPaddleOCR,draw_ocr# Paddleocr目前支持中英文、英文、法语、德语、韩语、日语,可以通过修改lang参数进行切换# 参数依次为`ch`, `en`, `french`, `german`, `korean`, `japan`。ocr=PaddleOCR(use_angle_cls=True,lang="ch")# need to run only once to download and load model into memoryimg_path='PaddleOCR/doc/imgs/11.jpg'img=cv2.imread(img_path)# img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY), 如果你自己训练的模型支持灰度图,可以将这句话的注释取消result=ocr.ocr(img,cls=True)foridxinrange(len(result)):res=result[idx]forlineinres:print(line)# 显示结果fromPILimportImageresult=result[0]image=Image.open(img_path).convert('RGB')boxes=[line[0]forlineinresult]txts=[line[1][0]forlineinresult]scores=[line[1][1]forlineinresult]im_show=draw_ocr(image,boxes,txts,scores,font_path='/path/to/PaddleOCR/doc/fonts/simfang.ttf')im_show=Image.fromarray(im_show)im_show.save('result.jpg')
frompaddleocrimportPaddleOCR,draw_ocr# Paddleocr目前支持的多语言语种可以通过修改lang参数进行切换# 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`ocr=PaddleOCR(use_angle_cls=True,lang="ch",page_num=2)# need to run only once to download and load model into memoryimg_path='./xxx.pdf'result=ocr.ocr(img_path,cls=True)foridxinrange(len(result)):res=result[idx]forlineinres:print(line)# 显示结果importfitzfromPILimportImageimportcv2importnumpyasnpimgs=[]withfitz.open(img_path)aspdf:forpginrange(0,pdf.pageCount):page=pdf[pg]mat=fitz.Matrix(2,2)pm=page.getPixmap(matrix=mat,alpha=False)# if width or height > 2000 pixels, don't enlarge the imageifpm.width>2000orpm.height>2000:pm=page.getPixmap(matrix=fitz.Matrix(1,1),alpha=False)img=Image.frombytes("RGB",[pm.width,pm.height],pm.samples)img=cv2.cvtColor(np.array(img),cv2.COLOR_RGB2BGR)imgs.append(img)foridxinrange(len(result)):res=result[idx]image=imgs[idx]boxes=[line[0]forlineinres]txts=[line[1][0]forlineinres]scores=[line[1][1]forlineinres]im_show=draw_ocr(image,boxes,txts,scores,font_path='doc/fonts/simfang.ttf')im_show=Image.fromarray(im_show)im_show.save('result_page_{}.jpg'.format(idx))