diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4de56f6..69c7876 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -12,11 +12,9 @@ + + - - - - + - @@ -125,7 +123,7 @@ - + diff --git a/Prj-Python/demo.py b/Prj-Python/demo.py new file mode 100644 index 0000000..ced0dbe --- /dev/null +++ b/Prj-Python/demo.py @@ -0,0 +1,38 @@ +# 导入cv相关库 +import cv2 +import numpy as np +from PIL import ImageFont +from PIL import Image +from PIL import ImageDraw +# 导入依赖包 +import hyperlpr3 as lpr3 + +def draw_plate_on_image(img, box, text, font): + x1, y1, x2, y2 = box + cv2.rectangle(img, (x1, y1), (x2, y2), (139, 139, 102), 2, cv2.LINE_AA) + cv2.rectangle(img, (x1, y1 - 18), (x2, y1), (139, 139, 102), -1) + data = Image.fromarray(img) + draw = ImageDraw.Draw(data) + draw.text((x1 + 1, y1 - 18), text, (255, 255, 255), font=font) + res = np.asarray(data) + + return res + + +# 中文字体加载 +font_ch = ImageFont.truetype("../resource/font/platech.ttf", 14, 0) + +# 实例化识别对象 +catcher = lpr3.LicensePlateCatcher() +# 读取图片 +image = cv2.imread("../resource/images/test_img.jpg") + +# 执行识别算法 +results = catcher(image) +for code, confidence, type_idx, box in results: + # 解析数据并绘制 + text = f"{code} - {confidence:.2f}" + image = draw_plate_on_image(image, box, text, font=font_ch) + +cv2.imshow("w", image) +cv2.waitKey(0) \ No newline at end of file diff --git a/resource/font/platech.ttf b/resource/font/platech.ttf new file mode 100644 index 0000000..d66a970 Binary files /dev/null and b/resource/font/platech.ttf differ