PaddleOCR——DEMO 秒速五厘米 2022-10-24 10:30 143阅读 0赞 # 项目地址 # [https://github.com/PaddlePaddle/PaddleOCR][https_github.com_PaddlePaddle_PaddleOCR] [https://gitee.com/paddlepaddle/PaddleOCR][https_gitee.com_paddlepaddle_PaddleOCR] # DEMO # #!usr/bin/env python # -*- coding:utf-8 _*- """ @version: 0.0.1 @author: ShenTuZhiGang @time: 2021/01/29 10:46 @file: paddleocrdemo.py @function: @last modified by: ShenTuZhiGang @last modified time: 2021/01/29 10:46 """ import cv2 import paddleocr from PIL import Image, ImageDraw, ImageFont import numpy as np res = paddleocr.PaddleOCR(use_gpu=False).ocr(img=r'test.png') img = Image.open(r'test.png') im = np.array(img) for i in range(len(res)): cv2.rectangle(im, (int(res[i][0][0][0]), int(res[i][0][0][1])), (int(res[i][0][2][0]), int(res[i][0][2][1])), (255, 0, 0), 1) # 使用cv2.putText不能显示中文,需要使用下面的代码代替 # cv2.putText(im, d['text'][i], (x, y-8), cv2.FONT_HERSHEY_SIMPLEX, 0.3, (255, 0, 0), 1) pilimg = Image.fromarray(im) pilimg.resize((800, 600),Image.ANTIALIAS) draw = ImageDraw.Draw(pilimg) # 参数1:字体文件路径,参数2:字体大小 font = ImageFont.truetype("simhei.ttf", 15, encoding="utf-8") # 参数1:打印坐标,参数2:文本,参数3:字体颜色,参数4:字体 text, sroce = res[i][1] draw.text((res[i][0][0][0], res[i][0][0][1]), text, (255, 0, 0), font=font) im = cv2.cvtColor(np.array(pilimg), cv2.COLOR_RGB2BGR) cv2.imshow("recoText", im) cv2.waitKey(0) cv2.destroyAllWindows() # 参考文章 # [anaconda3+ paddleOCR安装使用][anaconda3_ paddleOCR] [https_github.com_PaddlePaddle_PaddleOCR]: https://github.com/PaddlePaddle/PaddleOCR [https_gitee.com_paddlepaddle_PaddleOCR]: https://gitee.com/paddlepaddle/PaddleOCR [anaconda3_ paddleOCR]: https://www.cnblogs.com/xuanmanstein/p/13840670.html
还没有评论,来说两句吧...