add demo.py

master
tunmx 2 years ago
parent cf44359e69
commit f3d73cbff7

@ -12,11 +12,9 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="4be586f9-7a61-4585-994f-eaa32375497d" name="Changes" comment="Changes"> <list default="true" id="4be586f9-7a61-4585-994f-eaa32375497d" name="Changes" comment="Changes">
<change afterPath="$PROJECT_DIR$/Prj-Python/demo.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/resource/font/platech.ttf" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Prj-Python/hyperlpr3/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/Prj-Python/hyperlpr3/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Prj-Python/hyperlpr3/config/configuration.py" beforeDir="false" afterPath="$PROJECT_DIR$/Prj-Python/hyperlpr3/config/configuration.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Prj-Python/hyperlpr3/config/settings.py" beforeDir="false" afterPath="$PROJECT_DIR$/Prj-Python/hyperlpr3/config/settings.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Prj-Python/hyperlpr3/hyperlpr3.py" beforeDir="false" afterPath="$PROJECT_DIR$/Prj-Python/hyperlpr3/hyperlpr3.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -63,17 +61,17 @@
<property name="cf.first.check.clang-format" value="false" /> <property name="cf.first.check.clang-format" value="false" />
<property name="cidr.known.project.marker" value="true" /> <property name="cidr.known.project.marker" value="true" />
<property name="cmake.loaded.for.project" value="true" /> <property name="cmake.loaded.for.project" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" /> <property name="last_opened_file_path" value="$PROJECT_DIR$/resource/font" />
<property name="nodejs_package_manager_path" value="npm" /> <property name="nodejs_package_manager_path" value="npm" />
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" /> <property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
</component> </component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/resource/font" />
<recent name="$PROJECT_DIR$/images" /> <recent name="$PROJECT_DIR$/images" />
<recent name="$PROJECT_DIR$/resource/models" /> <recent name="$PROJECT_DIR$/resource/models" />
<recent name="$PROJECT_DIR$/resource/models/r2_mobile" /> <recent name="$PROJECT_DIR$/resource/models/r2_mobile" />
<recent name="$PROJECT_DIR$/command" /> <recent name="$PROJECT_DIR$/command" />
<recent name="$PROJECT_DIR$/cpp/samples" />
</key> </key>
<key name="MoveFile.RECENT_KEYS"> <key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/Prj-Python" /> <recent name="$PROJECT_DIR$/Prj-Python" />
@ -125,7 +123,7 @@
<workItem from="1677220611638" duration="33000" /> <workItem from="1677220611638" duration="33000" />
<workItem from="1677457111481" duration="10241000" /> <workItem from="1677457111481" duration="10241000" />
<workItem from="1677496149958" duration="6514000" /> <workItem from="1677496149958" duration="6514000" />
<workItem from="1677562836387" duration="1469000" /> <workItem from="1677562836387" duration="5926000" />
</task> </task>
<servers /> <servers />
</component> </component>

@ -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)

Binary file not shown.
Loading…
Cancel
Save