Commit 9de9d798 by 杨林龙

项目初始化

0 parents
myvenv
.vscode
ch_ppocr_mobile_v4.0_cls_infer
ch_ppocr_server_v4.0_det_infer
ch_ppocr_server_v4.0_rec_infer
__pycache__
{"type": "figure", "bbox": [3, 0, 1396, 1078], "res": [{"text": "D", "confidence": 0.8164410591125488, "text_region": [[1263.0, 161.0], [1290.0, 161.0], [1290.0, 189.0], [1263.0, 189.0]]}, {"text": "\u673a\u52a8\u8f66", "confidence": 0.9983036518096924, "text_region": [[567.0, 175.0], [696.0, 175.0], [696.0, 207.0], [567.0, 207.0]]}, {"text": "131", "confidence": 0.8037897944450378, "text_region": [[1263.0, 184.0], [1296.0, 184.0], [1296.0, 209.0], [1263.0, 209.0]]}, {"text": "\u53d1\u7968\u4ee3\u7801 144002324260", "confidence": 0.968948483467102, "text_region": [[993.0, 219.0], [1232.0, 219.0], [1232.0, 245.0], [993.0, 245.0]]}, {"text": "\u306e", "confidence": 0.18872979283332825, "text_region": [[1269.0, 210.0], [1296.0, 210.0], [1296.0, 241.0], [1269.0, 241.0]]}, {"text": "", "confidence": 0.0, "text_region": [[759.0, 226.0], [786.0, 226.0], [786.0, 242.0], [759.0, 242.0]]}, {"text": "\u53d1\u7968\u53f7\u780101116173", "confidence": 0.9982096552848816, "text_region": [[992.0, 241.0], [1187.0, 244.0], [1186.0, 270.0], [991.0, 267.0]]}, {"text": "C", "confidence": 0.9272502064704895, "text_region": [[1276.0, 264.0], [1304.0, 264.0], [1304.0, 295.0], [1276.0, 295.0]]}, {"text": "\u673a\u6253\u4ee3\u7801", "confidence": 0.9972335696220398, "text_region": [[302.0, 290.0], [416.0, 293.0], [415.0, 325.0], [301.0, 322.0]]}, {"text": "144002324260", "confidence": 0.9929677844047546, "text_region": [[436.0, 294.0], [590.0, 299.0], [589.0, 327.0], [435.0, 322.0]]}, {"text": "00904+183+9-231/>3/9-55<71<85224844*8+", "confidence": 0.9895800352096558, "text_region": [[765.0, 285.0], [1214.0, 295.0], [1213.0, 321.0], [765.0, 311.0]]}, {"text": ".", "confidence": 0.1749241203069687, "text_region": [[211.0, 308.0], [232.0, 308.0], [232.0, 328.0], [211.0, 328.0]]}, {"text": "\u7a0e", "confidence": 0.9999998807907104, "text_region": [[722.0, 302.0], [742.0, 302.0], [742.0, 324.0], [722.0, 324.0]]}, {"text": "\u673a\u6253\u53f7\u7801", "confidence": 0.9989584684371948, "text_region": [[299.0, 322.0], [414.0, 325.0], [413.0, 355.0], [298.0, 351.0]]}, {"text": "01116173", "confidence": 0.9980354309082031, "text_region": [[436.0, 323.0], [542.0, 329.0], [541.0, 356.0], [435.0, 351.0]]}, {"text": "O", "confidence": 0.20331017673015594, "text_region": [[1286.0, 316.0], [1311.0, 316.0], [1311.0, 345.0], [1286.0, 345.0]]}, {"text": "\u63a7", "confidence": 0.9999194145202637, "text_region": [[722.0, 333.0], [746.0, 333.0], [746.0, 354.0], [722.0, 354.0]]}, {"text": "\u673a\u5668\u7f16\u53f7", "confidence": 0.9989073276519775, "text_region": [[298.0, 354.0], [411.0, 358.0], [410.0, 385.0], [297.0, 382.0]]}, {"text": "587009100492", "confidence": 0.9969142079353333, "text_region": [[434.0, 357.0], [590.0, 362.0], [589.0, 390.0], [433.0, 385.0]]}, {"text": "00", "confidence": 0.3417201638221741, "text_region": [[767.0, 353.0], [1220.0, 358.0], [1219.0, 384.0], [766.0, 379.0]]}, {"text": "6>/6/07995014+2004-+53<002<><-1**84244", "confidence": 0.9889366626739502, "text_region": [[767.0, 374.0], [1224.0, 379.0], [1224.0, 405.0], [766.0, 400.0]]}, {"text": "O", "confidence": 0.39817574620246887, "text_region": [[1294.0, 373.0], [1316.0, 373.0], [1316.0, 397.0], [1294.0, 397.0]]}, {"text": "\u7b2c", "confidence": 0.9999988079071045, "text_region": [[1246.0, 387.0], [1272.0, 387.0], [1272.0, 414.0], [1246.0, 414.0]]}, {"text": "\u7eb3\u7a0e\u4eba\u8bc6\u522b\u53f7/", "confidence": 0.9518406987190247, "text_region": [[778.0, 411.0], [909.0, 411.0], [909.0, 437.0], [778.0, 437.0]]}, {"text": "\u8d2d\u4e70\u65b9\u540d\u79f0", "confidence": 0.998746395111084, "text_region": [[300.0, 425.0], [405.0, 425.0], [405.0, 453.0], [300.0, 453.0]]}, {"text": "\u4e54\u65b0\u5b81", "confidence": 0.9925312399864197, "text_region": [[430.0, 428.0], [492.0, 428.0], [492.0, 456.0], [430.0, 456.0]]}, {"text": "\u7edf\u4e00\u793e\u4f1a\u4fe1\u7528\u4ee3\u7801/", "confidence": 0.9710140228271484, "text_region": [[780.0, 431.0], [950.0, 431.0], [950.0, 457.0], [780.0, 457.0]]}, {"text": "411202196512295016", "confidence": 0.9960861206054688, "text_region": [[980.0, 431.0], [1200.0, 433.0], [1200.0, 460.0], [979.0, 459.0]]}, {"text": "O", "confidence": 0.38792848587036133, "text_region": [[1304.0, 431.0], [1324.0, 431.0], [1324.0, 454.0], [1304.0, 454.0]]}, {"text": "\u8eab\u4efd\u8bc1\u53f7\u7801", "confidence": 0.99811851978302, "text_region": [[782.0, 446.0], [882.0, 450.0], [881.0, 477.0], [781.0, 474.0]]}, {"text": "\u53d1", "confidence": 0.9998735189437866, "text_region": [[1256.0, 456.0], [1281.0, 456.0], [1281.0, 485.0], [1256.0, 485.0]]}, {"text": "\u8f66\u8f86\u7c7b\u578b", "confidence": 0.9983723759651184, "text_region": [[292.0, 472.0], [408.0, 476.0], [407.0, 505.0], [291.0, 501.0]]}, {"text": "\u63d2\u7535\u5f0f\u589e\u7a0b\u6df7\u5408\u52a8\u529b\u591a\u7528\u9014", "confidence": 0.9847047924995422, "text_region": [[428.0, 471.0], [630.0, 471.0], [630.0, 497.0], [428.0, 497.0]]}, {"text": "\u5382\u724c\u578b\u53f7", "confidence": 0.9983156323432922, "text_region": [[638.0, 480.0], [717.0, 480.0], [717.0, 506.0], [638.0, 506.0]]}, {"text": "\u8d5b\u529b\u65af\u724cSKE6500SSHEVA2S", "confidence": 0.9951272010803223, "text_region": [[733.0, 482.0], [940.0, 482.0], [940.0, 508.0], [733.0, 508.0]]}, {"text": "\u4ea7\u5730\u91cd\u5e86\u5e02", "confidence": 0.9942835569381714, "text_region": [[1049.0, 478.0], [1167.0, 482.0], [1166.0, 511.0], [1048.0, 508.0]]}, {"text": "\u7968", "confidence": 0.9869633316993713, "text_region": [[1262.0, 492.0], [1287.0, 492.0], [1287.0, 520.0], [1262.0, 520.0]]}, {"text": "O", "confidence": 0.5006667971611023, "text_region": [[1311.0, 488.0], [1330.0, 488.0], [1330.0, 512.0], [1311.0, 512.0]]}, {"text": "\u5408\u683c\u8bc1\u53f7", "confidence": 0.9994290471076965, "text_region": [[290.0, 522.0], [405.0, 522.0], [405.0, 549.0], [290.0, 549.0]]}, {"text": "YU6501000092211", "confidence": 0.9888136386871338, "text_region": [[428.0, 526.0], [573.0, 526.0], [573.0, 552.0], [428.0, 552.0]]}, {"text": "\u8fdb\u53e3\u8bc1\u660e\u4e66\u53f7", "confidence": 0.9977635741233826, "text_region": [[638.0, 525.0], [750.0, 525.0], [750.0, 551.0], [638.0, 551.0]]}, {"text": "\u5546\u68c0\u5355\u53f7", "confidence": 0.9975115656852722, "text_region": [[1028.0, 526.0], [1102.0, 526.0], [1102.0, 554.0], [1028.0, 554.0]]}, {"text": "\u8054", "confidence": 0.9999758005142212, "text_region": [[1264.0, 528.0], [1292.0, 528.0], [1292.0, 558.0], [1264.0, 558.0]]}, {"text": "O", "confidence": 0.5002836585044861, "text_region": [[1317.0, 548.0], [1340.0, 548.0], [1340.0, 569.0], [1317.0, 569.0]]}, {"text": "\u53d1\u52a8\u673a\u53f7\u7801", "confidence": 0.9980593919754028, "text_region": [[286.0, 568.0], [403.0, 568.0], [403.0, 595.0], [286.0, 595.0]]}, {"text": "24665221", "confidence": 0.9986093044281006, "text_region": [[424.0, 571.0], [507.0, 571.0], [507.0, 597.0], [424.0, 597.0]]}, {"text": "\u8f66\u8f86\u8bc6\u522b\u4ee3\u53f7/\u8f66\u67b6\u53f7\u7801", "confidence": 0.964383065700531, "text_region": [[760.0, 571.0], [957.0, 571.0], [957.0, 597.0], [760.0, 597.0]]}, {"text": "LM8F7E991RA167498", "confidence": 0.9903372526168823, "text_region": [[969.0, 571.0], [1184.0, 571.0], [1184.0, 597.0], [969.0, 597.0]]}, {"text": "\u4ef7\u7a0e\u5408\u8ba1", "confidence": 0.999421238899231, "text_region": [[280.0, 617.0], [402.0, 613.0], [402.0, 641.0], [281.0, 645.0]]}, {"text": "\u53c1\u62fe\u4e07\u53c1\u4edf\u634c\u4f70\u5706\u6574", "confidence": 0.9806077480316162, "text_region": [[430.0, 617.0], [620.0, 617.0], [620.0, 643.0], [430.0, 643.0]]}, {"text": "\u5c0f\u5199\uffe5303800.00", "confidence": 0.9778823852539062, "text_region": [[1018.0, 615.0], [1204.0, 615.0], [1204.0, 641.0], [1018.0, 641.0]]}, {"text": "\u9500\u8d27\u5355\u4f4d\u540d\u79f0", "confidence": 0.9969012141227722, "text_region": [[280.0, 663.0], [400.0, 663.0], [400.0, 690.0], [280.0, 690.0]]}, {"text": "\u4e1c\u839e\u5e02\u9a8f\u4e1a\u6c7d\u8f66\u9500\u552e\u670d\u52a1\u6709\u9650\u516c\u53f8", "confidence": 0.9952832460403442, "text_region": [[422.0, 664.0], [700.0, 664.0], [700.0, 690.0], [422.0, 690.0]]}, {"text": "\u7535\u8bdd", "confidence": 0.999814510345459, "text_region": [[950.0, 661.0], [993.0, 661.0], [993.0, 686.0], [950.0, 686.0]]}, {"text": "13802381129", "confidence": 0.9938368201255798, "text_region": [[1005.0, 663.0], [1110.0, 663.0], [1110.0, 689.0], [1005.0, 689.0]]}, {"text": "O", "confidence": 0.416404128074646, "text_region": [[1336.0, 667.0], [1354.0, 667.0], [1354.0, 690.0], [1336.0, 690.0]]}, {"text": "\u7eb3\u7a0e\u4eba\u8bc6\u522b\u53f7", "confidence": 0.9990637302398682, "text_region": [[276.0, 712.0], [396.0, 712.0], [396.0, 739.0], [276.0, 739.0]]}, {"text": "91441900MA56J0TP4E", "confidence": 0.9910343885421753, "text_region": [[422.0, 709.0], [664.0, 709.0], [664.0, 735.0], [422.0, 735.0]]}, {"text": "\u8d26\u53f7", "confidence": 0.9982724189758301, "text_region": [[950.0, 706.0], [996.0, 706.0], [996.0, 735.0], [950.0, 735.0]]}, {"text": "2010022609000204238", "confidence": 0.9965273141860962, "text_region": [[1005.0, 707.0], [1186.0, 707.0], [1186.0, 733.0], [1005.0, 733.0]]}, {"text": "\u5730", "confidence": 0.9999797344207764, "text_region": [[273.0, 761.0], [302.0, 761.0], [302.0, 790.0], [273.0, 790.0]]}, {"text": "\u5740", "confidence": 0.9997761845588684, "text_region": [[368.0, 761.0], [396.0, 761.0], [396.0, 789.0], [368.0, 789.0]]}, {"text": "\u5e7f\u4e1c\u7701\u4e1c\u839e\u5e02\u5357\u57ce\u8857\u9053\u839e\u592a\u8def\u5357\u57ce\u6bb5345\u53f71\u680b101\u5ba4", "confidence": 0.9954195022583008, "text_region": [[417.0, 759.0], [807.0, 756.0], [807.0, 784.0], [417.0, 787.0]]}, {"text": "\u5f00\u6237\u94f6\u884c", "confidence": 0.9981158375740051, "text_region": [[823.0, 758.0], [908.0, 758.0], [908.0, 784.0], [823.0, 784.0]]}, {"text": "\u5de5\u884c\u4e1c\u839e\u9633\u5149\u652f\u884c", "confidence": 0.9967478513717651, "text_region": [[910.0, 756.0], [1056.0, 756.0], [1056.0, 784.0], [910.0, 784.0]]}, {"text": "\u4e3b\u7ba1\u7a0e\u52a1 \u56fd\u5bb6\u7a0e\u52a1\u603b\u5c40\u4e1c\u839e\u5e02\u7a0e\u52a1\u5c40\u5357\u57ce\u7a0e\u52a1\u5206\u5c40", "confidence": 0.975624144077301, "text_region": [[846.0, 795.0], [1285.0, 790.0], [1286.0, 821.0], [846.0, 825.0]]}, {"text": "\u589e\u503c\u7a0e\u7a0e\u7387", "confidence": 0.999567985534668, "text_region": [[268.0, 806.0], [394.0, 802.0], [395.0, 834.0], [269.0, 838.0]]}, {"text": "13%", "confidence": 0.9774405360221863, "text_region": [[418.0, 816.0], [464.0, 816.0], [464.0, 841.0], [418.0, 841.0]]}, {"text": "\uffe534950.44", "confidence": 0.9729591012001038, "text_region": [[634.0, 812.0], [762.0, 812.0], [762.0, 839.0], [634.0, 839.0]]}, {"text": "\u6216\u5f81\u6536\u7387", "confidence": 0.9997372627258301, "text_region": [[268.0, 833.0], [394.0, 830.0], [395.0, 862.0], [269.0, 866.0]]}, {"text": "\u673a\u5173\u53ca\u4ee3\u7801", "confidence": 0.9973434209823608, "text_region": [[849.0, 825.0], [952.0, 825.0], [952.0, 851.0], [849.0, 851.0]]}, {"text": "14419280000", "confidence": 0.9978823065757751, "text_region": [[962.0, 824.0], [1110.0, 824.0], [1110.0, 850.0], [962.0, 850.0]]}, {"text": "\u5e97", "confidence": 0.38232114911079407, "text_region": [[450.0, 868.0], [471.0, 868.0], [471.0, 881.0], [450.0, 881.0]]}, {"text": "\u5b8c\u7a0e\u51ed\u8bc1\u53f7\u7801", "confidence": 0.9986302852630615, "text_region": [[655.0, 871.0], [784.0, 870.0], [785.0, 897.0], [656.0, 899.0]]}, {"text": "\u9650\u4e58\u4eba\u65705", "confidence": 0.9984155893325806, "text_region": [[1138.0, 862.0], [1250.0, 862.0], [1250.0, 890.0], [1138.0, 890.0]]}, {"text": "\u4e0d\u542b\u7a0e\u4ef7", "confidence": 0.9963133335113525, "text_region": [[265.0, 879.0], [392.0, 874.0], [393.0, 906.0], [266.0, 912.0]]}, {"text": "HR4900A580PS", "confidence": 0.5674064755439758, "text_region": [[434.0, 873.0], [644.0, 865.0], [646.0, 906.0], [436.0, 915.0]]}, {"text": "N", "confidence": 0.22507067024707794, "text_region": [[154.0, 914.0], [189.0, 914.0], [189.0, 939.0], [154.0, 939.0]]}, {"text": "\u53d1\u7968\u4e13\u7528\u7ae0", "confidence": 0.9984194040298462, "text_region": [[484.0, 914.0], [601.0, 906.0], [604.0, 943.0], [486.0, 950.0]]}, {"text": "\u5f00\u7968\u4eba \u9f50\u56fd\u7acb", "confidence": 0.9408449530601501, "text_region": [[694.0, 915.0], [835.0, 911.0], [836.0, 943.0], [695.0, 947.0]]}, {"text": "\u5907\u6ce8\uff1a\u4e00\u8f66\u4e00\u7968", "confidence": 0.9962071776390076, "text_region": [[1050.0, 907.0], [1195.0, 903.0], [1196.0, 936.0], [1051.0, 939.0]]}, {"text": "\u9500\u8d27\u5355\u4f4d\u76d6\u7ae0", "confidence": 0.9978023171424866, "text_region": [[252.0, 924.0], [389.0, 919.0], [390.0, 951.0], [253.0, 956.0]]}, {"text": "0", "confidence": 0.4615001082420349, "text_region": [[1368.0, 924.0], [1392.0, 924.0], [1392.0, 956.0], [1368.0, 956.0]]}, {"text": "O", "confidence": 0.6134055256843567, "text_region": [[159.0, 953.0], [188.0, 953.0], [188.0, 979.0], [159.0, 979.0]]}], "img_idx": 0}
table/1.png

758 KB

from PIL import Image
import numpy as np
from paddleocr import PaddleOCR
# load model
# Paddleocr目前支持中英文、英文、法语、德语、韩语、日语,可以通过修改 lang参数进行切换
# lang参数依次为`ch`, `en`, `french`, `german`, `korean`, `japan`
ocr = PaddleOCR(
use_angle_cls=True,
# use_angle_cls=False,
lang="ch",
# use_gpu=False,
use_gpu=True,
use_tensorrt=True,
det_algorithm="DB",
# det_algorithm="EAST",
det_db_score_mode="slow",
# use_space_char=False, #不可用
det_model_dir="ch_ppocr_server_v4.0_det_infer/",
cls_model_dir="ch_ppocr_mobile_v4.0_cls_infer/",
rec_model_dir="ch_ppocr_server_v4.0_rec_infer/",
det_db_thresh=0.1,
det_db_box_thresh=0.1,
det_db_unclip_ratio=2.0,
max_batch_size=20,
use_dilation=True,
# rec_algorithm="SVTR_LCNet",
)
# path='./ocr_invoice/ocr-vin-0007.jpg'
path='./enhanced_image.jpg'
original_image = Image.open(path)
if original_image.mode == "RGBA":
original_image = original_image.convert("RGB")
result = ocr.ocr(np.asarray(original_image), cls=True)
for line in result:
print(line)
print('Text: ', line[-1][0])
print('Score: ', line[-1][1])
print('Location: ', line[0])
# 图像方向分类+版面分析+表格识别
import os
import cv2
from paddleocr import PPStructure,draw_structure_result,save_structure_res
table_engine = PPStructure(show_log=True, image_orientation=True)
save_folder = "./output"
# img_path = './table/1.png'
img_path = "./ocr_invoice/ocr-vin-0007.jpg"
img = cv2.imread(img_path)
result = table_engine(img)
save_structure_res(result, save_folder,os.path.basename(img_path).split('.')[0])
for line in result:
line.pop("img")
print(line)
from PIL import Image
font_path = 'doc/fonts/simfang.ttf' # PaddleOCR下提供字体包
image = Image.open(img_path).convert('RGB')
im_show = draw_structure_result(image, result,font_path=font_path)
im_show = Image.fromarray(im_show)
im_show.save('result02.jpg')
# 版面分析+表格识别
import os
import shutil
import cv2
from paddleocr import PPStructure, draw_structure_result, save_structure_res
table_engine = PPStructure(
mode="structure",
layout=True,
ocr=True,
table=True,
show_log=True,
# invert=True,
use_angle_cls=True,
# det_model_dir="ch_ppocr_server_v4.0_det_infer/",
det_model_dir="ch_ppocr_server_v4.0_det_infer/",
cls_model_dir="ch_ppocr_mobile_v4.0_cls_infer/",
rec_model_dir="ch_ppocr_server_v4.0_rec_infer/",
re_model_dir="re_vi_layoutxlm_xfund_infer",
# layout_model_dir=''
use_tensorrt=True,
use_dilation=True,
image_orientation=True,
recovery=True,
)
save_folder = "./output"
# img_path = './table/1.png'
img_path = "./ocr_invoice/ocr-vin-0007.jpg"
img = cv2.imread(img_path)
result = table_engine(img)
# 删除文件
print(save_folder + "/" + os.path.basename(img_path).split(".")[0])
if os.path.exists(save_folder + "/" + os.path.basename(img_path).split(".")[0]):
shutil.rmtree(save_folder + "/" + os.path.basename(img_path).split(".")[0])
save_structure_res(result, save_folder, os.path.basename(img_path).split(".")[0])
for line in result:
line.pop("img")
print(line)
from PIL import Image
font_path = "doc/fonts/simfang.ttf" # PaddleOCR下提供字体包
image = Image.open(img_path).convert("RGB")
im_show = draw_structure_result(image, result, font_path=font_path)
im_show = Image.fromarray(im_show)
os.remove("result03.jpg")
im_show.save("result03.jpg")
# 版面分析
import os
import cv2
from paddleocr import PPStructure,save_structure_res
table_engine = PPStructure(table=False, ocr=False, show_log=True)
save_folder = './output'
# img_path = './table/1.png'
img_path = "./ocr_invoice/ocr-vin-0007.jpg"
img = cv2.imread(img_path)
result = table_engine(img)
save_structure_res(result, save_folder, os.path.basename(img_path).split('.')[0])
for line in result:
line.pop('img')
print(line)
# 表格识别
import os
import cv2
from paddleocr import PPStructure, save_structure_res
table_engine = PPStructure(layout=False, show_log=True)
save_folder = "./output"
img_path = './table/table.jpg'
img = cv2.imread(img_path)
result = table_engine(img)
save_structure_res(result, save_folder, os.path.basename(img_path).split('.')[0])
for line in result:
line.pop('img')
print(line)
# 版面恢复
import os
import cv2
from paddleocr import PPStructure,save_structure_res
from paddleocr.ppstructure.recovery.recovery_to_doc import sorted_layout_boxes, convert_info_docx
# 中文测试图
table_engine = PPStructure(recovery=True)
# 英文测试图
# table_engine = PPStructure(recovery=True, lang='en')
save_folder = './output'
# img_path = "./table/1.png"
img_path = "./ocr_invoice/ocr-vin-0007.jpg"
img = cv2.imread(img_path)
result = table_engine(img)
save_structure_res(result, save_folder, os.path.basename(img_path).split('.')[0])
for line in result:
line.pop('img')
print(line)
h, w, _ = img.shape
res = sorted_layout_boxes(result, w)
convert_info_docx(img, res, save_folder, os.path.basename(img_path).split(".")[0])
import os
import numpy as np
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
from pprint import pprint
# load model
# Paddleocr目前支持中英文、英文、法语、德语、韩语、日语,可以通过修改 lang参数进行切换
# lang参数依次为`ch`, `en`, `french`, `german`, `korean`, `japan`
ocr = PaddleOCR(
use_angle_cls=True,
# use_angle_cls=False,
lang="ch",
# use_gpu=False,
use_gpu=True,
use_tensorrt=True,
det_algorithm="DB",
# det_algorithm="EAST",
det_db_score_mode="slow",
# use_space_char=False, #不可用
det_model_dir="ch_ppocr_server_v4.0_det_infer/",
cls_model_dir="ch_ppocr_mobile_v4.0_cls_infer/",
rec_model_dir="ch_ppocr_server_v4.0_rec_infer/",
det_db_thresh=0.1,
det_db_box_thresh=0.1,
det_db_unclip_ratio=2.0,
max_batch_size=20,
# det_db_box_thresh=0.3,
use_dilation=True,
image_orientation=True,
cls=True,
# rec_algorithm="SVTR_LCNet",
)
img_path = "./ocr_invoice/ocr-vin-0007.jpg"
# path='./enhanced_image.jpg'
original_image = Image.open(img_path)
if original_image.mode == "RGBA":
original_image = original_image.convert("RGB")
result = ocr.ocr(np.asarray(original_image), cls=True)
# result = ocr.ocr(original_image, cls=False)
for line in result:
print(line)
# print("Text: ", line[-1][0])
# print("Score: ", line[-1][1])
# print("Location: ", line[0])
image = Image.open(img_path).convert("RGB")
boxes = [line[0] for line in result[0]]
txts = [line[1][0] for line in result[0]]
# all_context = "\n".join(txts)
all_context = "".join(txts)
# print("\n".join(txts))
print(all_context)
scores = [line[1][1] for line in result[0]]
im_show = draw_ocr(image, boxes, txts, scores, font_path="./simfang.ttf")
im_show = Image.fromarray(im_show)
# im_show.show()
if os.path.exists("result04.jpg"):
os.remove("result04.jpg")
im_show.save("result04.jpg")
from paddlenlp import Taskflow
schema = ["车辆类型", "账号", "机关及代码", "备注"]
ie = Taskflow("information_extraction",schema=schema)
ie.set_schema(schema)
one = ie(all_context)
print("one===")
pprint(one)
from paddleocr import PaddleOCR, draw_ocr
# paddleocr目前支持中英文、英文、法语、德语、韩语、日语等80个语种,可以通过修改lang参数进行切换
ocr = PaddleOCR(
use_angle_cls=False, lang="ch"
) # need to run only once to download and load model into memory
img_path = "./ocr_invoice/ocr-vin-0007.jpg"
result = ocr.ocr(img_path, cls=False)
print("result===")
print(result)
# for line in result:
# print(line)
# 可视化结果
from PIL import Image
image = Image.open(img_path).convert("RGB")
boxes = [line[0] for line in result[0]]
txts = [line[1][0] for line in result[0]]
scores = [line[1][1] for line in result[0]]
print("scores===")
print(scores)
im_show = draw_ocr(image, boxes, txts, scores, font_path="./simfang.ttf")
im_show = Image.fromarray(im_show)
im_show.show()
from pprint import pprint
from paddlenlp import Taskflow
docprompt = Taskflow("document_intelligence")
pprint(
docprompt(
[
{
"doc": "https://bj.bcebos.com/paddlenlp/taskflow/document_intelligence/images/invoice.jpg",
"prompt": ["发票号码是多少?", "校验码是多少?"],
}
]
)
)
from pprint import pprint
from paddlenlp import Taskflow
docprompt = Taskflow("document_intelligence")
pprint(
docprompt(
[
{
"doc": "https://user-images.githubusercontent.com/40840292/194748579-f9e8aa86-7f65-4827-bfae-824c037228b3.png",
"prompt": [
"五百丁本次想要担任的是什么职位?",
"五百丁是在哪里上的大学?",
"大学学的是什么专业?",
],
}
]
)
)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!