OpenVINO™2025部署PaddleOCR模型

PaddleOCR模型下载

OpenVINO™2025支持直接加载paddle的模型。

图片

所以可以直接先从官网直接下载PaddleOCRv5.0的模型:

文本检测模型下载地址

# Download and unzip PP-OCRv5_server_det pre-trained modelhttps://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0.0/PP-OCRv5_server_det_infer.tar

文本识别模型下载地址

# Download and upzip PP-OCRv5_server_rec pre-trained modelhttps://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0.0/PP-OCRv5_server_rec_infer.tar

推理流程与SDK支持

OpenVINO™的推理流程

图片

SDK支持直接加载模型并实现输入与输出层数据读取,代码如下:

core = Core()det_model = core.read_model(model="./models/ch_PP-OCRv5_det_infer.pdmodel")det_compiled_model = core.compile_model(model=det_model, device_name="CPU")# Get input and output nodes for text detection.det_input_layer = det_compiled_model.input(0)det_output_layer = det_compiled_model.output(0)rec_compiled_model = core.compile_model(model="./models/ch_PP-OCRv5_rec_infer.pdmodel", device_name="AUTO")# Get input and output nodes.rec_input_layer = rec_compiled_model.input(0)rec_output_layer = rec_compiled_model.output(0)

代码演示

OpenVINO™2025官方给出的代码依然依赖Paddle框架,没有做大完全部署解耦,所以我这里在官方的代码基础上做了修改,把预处理跟后处理还有decode输出放到一个单独的python文件中,取名为:

paddle_dettext_prepost_process.y

使用时候直接导入即可,这样就完全不需要依赖paddle相关的包,只需要依赖OpenVINO™跟OpenCV即可。

import paddle_dettext_prepost_process as processing

推理OCR识别部分的代码如下:

start = time.time()frame = cv.imread("D:/1725.jpg")cv.imshow("input", frame)scale = 1280 / max(frame.shape)if scale < 1:	frame = cv.resize(		src=frame,		dsize=None,		fx=scale,		fy=scale,		interpolation=cv.INTER_AREA,	)# Preprocess the image for text detection.test_image = image_preprocess(frame, 640)# Measure processing time for text detection.det_results = det_compiled_model([test_image])[det_output_layer]# Postprocessing for Paddle Detection.dt_boxes = post_processing_detection(frame, det_results)# Preprocess detection results for recognition.dt_boxes = processing.sorted_boxes(dt_boxes)batch_num = 6img_crop_list, img_num, indices = prep_for_rec(dt_boxes, frame)# For storing recognition results, include two parts:# txts are the recognized text results, scores are the recognition confidence level.rec_res = [["", 0.0]] * img_numtxts = []scores = []for beg_img_no in range(0, img_num, batch_num):# Recognition starts from here.	norm_img_batch = batch_text_box(img_crop_list, img_num, indices, beg_img_no, batch_num)# Run inference for text recognition.	rec_results = rec_compiled_model([norm_img_batch])[rec_output_layer]# Postprocessing recognition results.	postprocess_op = processing.build_post_process(processing.postprocess_params)	rec_result = postprocess_op(rec_results)	for rno in range(len(rec_result)):		rec_res[indices[beg_img_no + rno]] = rec_result[rno]	if rec_res:		txts = [rec_res[i][0] for i in range(len(rec_res))]		scores = [rec_res[i][1] for i in range(len(rec_res))]image = Image.fromarray(cv.cvtColor(frame, cv.COLOR_BGR2RGB))boxes = dt_boxes# Draw text recognition results beside the image.draw_img = processing.draw_ocr_box_txt(image, boxes, txts, scores, drop_score=0.5)# Visualize the PaddleOCR results.end = time.time()inf_end = end - startfps = 1 / inf_endfps_label = "FPS: %.2f" % fpsf_height, f_width = draw_img.shape[:2]cv.putText(	img=draw_img,	text=fps_label,	org=(20, 40),	fontFace=cv.FONT_HERSHEY_COMPLEX,	fontScale=f_width / 1000,	color=(0, 0, 255),	thickness=1,	lineType=cv.LINE_AA,)draw_img = cv.cvtColor(draw_img, cv.COLOR_RGB2BGR)cv.imshow("OpenVINO2025 PaddleOCR", draw_img)cv.waitKey(0)cv.destroyAllWindows()

运行测试结果如下(左侧是原图,右侧是识别结果):

图片

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值