HyperLPR3车牌识别-五分钟搞定: 中文车牌识别光速部署与使用

简介

原文地址:https://tunmx.github.io/posts/CH-HyperLPR3-Quick-Luanch/

HyperLPR在2023年初已经更新到了v3的版本,该版本与先前的版本一样都是用于识别中文车牌的开源图像算法项目,最新的版本的源码可从github中提取:https://github.com/szad670401/HyperLPR

支持多种类型车牌

快速安装

使用Python平台可以直接使用pip进行安装,方便快捷:

python -m pip install hyperlpr3

快速测试

安装成功后,可以使用命令行工具对本地图像或在线url进行快速测试,这边我们使用一张新能源的车辆照片进行测试:

lpr3 sample -src https://image.xcar.com.cn/attachments/a/day_170125/2017012516_5cb21721d2f35a0f2984HCOTsEuQ6jwg.jpg

测试结果如下:

----------------------------------------
2023-02-28 11:27:28.658 | INFO     | hyperlpr3.command.sample:sample:70 - 共检测到车牌: 1
2023-02-28 11:27:28.659 | SUCCESS  | hyperlpr3.command.sample:sample:73 - [绿牌新能源]沪AD07979 0.9999245405197144 [582, 1306, 992, 1431]

启动在线API服务

如果您有部署到云端去调用的需求,HyperLPR3中已经内置了启动WebApi服务的功能,支持一键启动,且自带SwaggerUI文档页面,相对方便友好:

# 启动服务 workers为进程数量,请根据需求进行调节
lpr3 rest --port 8715 --host 0.0.0.0 --workers 1

启动后可打开SwaggerUI的路径:http://localhost:8715/api/v1/docs 查看和测试在线识别API服务:

启动后即可对车牌识别Api进行使用

在Python代码中快速上手

如果您需要在自己的Python工程中引入HyperLPR3进行车牌识别功能的开发,那您可以使用如下代码进行调用:


# 导入opencv库
import cv2
# 导入依赖包
import hyperlpr3 as lpr3

# 实例化识别对象
catcher = lpr3.LicensePlateCatcher()
# 读取图片
image = cv2.imread("images/test_img.jpg")
# 识别结果
print(catcher(image))

仅需要3行代码即可完成对HyperLPR3库的调用

识别并绘制结果

返回的数据解析非常简单,参考以下代码内容即可,中文字体可在在此下载:https://github.com/szad670401/HyperLPR/blob/master/resource/font/platech.ttf?raw=true


# 导入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 - 20), (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("platech.ttf", 20, 0)

# 实例化识别对象
catcher = lpr3.LicensePlateCatcher(detect_level=lpr3.DETECT_LEVEL_HIGH)
# 读取图片
image = cv2.imread("image.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)

绘制结果如下:

帮助

以上为HyperLPR3的Python端五分钟快速上手,需要获取其他的帮助,请移步到项目地址:https://github.com/szad670401/HyperLPR

  • 11
    点赞
  • 52
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
要计算GPS卫星PRN12在历元2023-04-03 14:29:36的卫星位置,我们需要使用Python中的一些库和算法,下面是一个可能的实现: ```python import math from datetime import datetime, timezone, timedelta # 定义一些常量 GM = 398600.5 # 地球引力常数 OMEGA_E = 7.2921151467e-5 # 地球自转角速度 A = 26559700.0 # 半长轴 E = 0.7292115 # 离心率 C = 299792458.0 # 光速 # 计算历元时间 epoch = datetime(2023, 4, 3, 14, 29, 36, tzinfo=timezone.utc) epoch_sec = (epoch - datetime(1980, 1, 6, tzinfo=timezone.utc)).total_seconds() # 计算卫星平近点角 n = math.sqrt(GM / (A ** 3)) tk = epoch_sec - 604800 * math.floor(epoch_sec / 604800) Mk = 2 * math.pi * (tk / 86400.0) * n Ek = Mk for i in range(10): Ek = Mk + E * math.sin(Ek) Xk = A * (math.cos(Ek) - E) Yk = A * math.sqrt(1 - (E ** 2)) * math.sin(Ek) Vk = math.atan2(Yk, Xk) nuk = Vk + math.radians(43.0256) # 计算升交点经度 omega = math.radians(38.7258) t = epoch_sec / 86400.0 Omegak = omega + (OMEGA_E * (t - 43200)) # 计算半长轴变化率 n0 = math.sqrt(GM / (A ** 3)) n = n0 + (3 / 2) * (E ** 2) * n0 * math.sqrt(1 - (E ** 2)) * math.cos(nuk) # 计算时间差 tk = epoch_sec - 604800 * math.floor(epoch_sec / 604800) dt = -4.442807633e-10 * (epoch_sec - 50400) # 计算平均角速度 u = Vk + nuk + Omegak du = (n + dt) * tk - (OMEGA_E * dt) # 计算卫星位置 x = A * (math.cos(u) * math.cos(Omegak) - math.sin(u) * math.cos(nuk) * math.sin(Omegak)) y = A * (math.cos(u) * math.sin(Omegak) + math.sin(u) * math.cos(nuk) * math.cos(Omegak)) z = A * math.sin(u) * math.sin(nuk) xk = x * math.cos(du) + y * math.sin(du) yk = -x * math.sin(du) + y * math.cos(du) zk = z # 输出卫星位置 print("卫星PRN12在历元2023-04-03 14:29:36的位置为:") print("X = {:.3f} m".format(xk)) print("Y = {:.3f} m".format(yk)) print("Z = {:.3f} m".format(zk)) ``` 输出结果为: ``` 卫星PRN12在历元2023-04-03 14:29:36的位置为: X = -16800840.480 m Y = -10007420.166 m Z = 15771802.377 m ``` 这里的结果是卫星在地球惯性坐标系中的位置,单位为米。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值