HyperLPR 车牌识别的几个问题

最近要做一个车牌识别的模块,查了网发现python有个现成的库HyperLPR,可以很简单实现,就几行代码。
但在使用过程,却发现好多坑,也许是有些文章一直没更新也许是有些人根本是想当然。
所以内容虽然简单,还是做了记录。希望以后大家可以少走弯路。

一、安装容易出错。
我是用anaconda环境(Python 3.8),安装本来很容易,但发现一不小心还是出错,建议用国内的镜像。

pip install hyperlpr -i https://pypi.tuna.tsinghua.edu.cn/simple

如果第一次安装还不成功,就重新来一次

二、网上的介绍大多是互相转抄,不仅内容一样,错误也一样。

最原始代码来自如下(至于谁是始祖,无法深究了):

from hyperlpr import pipline as  pp
import cv2
# 自行修改文件名
image = cv2.imread("./car/3.jpg")
image,res  = pp.SimpleRecognizePlate(image)
print(res)

还号称源码在GitHub 可以获得,有一大堆的目录
https://github.com/zeusees/HyperLPR

但发现每个谱,根本无法运行。

一是运行出现错误,根本没有pipline(是不是最近版本不对了,没去深究)
在这里插入图片描述
二是 github 上面根本没有代码,只有一个readme,md 和license(难道是偏点击的?)
在这里插入图片描述
经过研究,可用的方式如下代码只要几行:

from hyperlpr import *
import cv2
print(cv2.__version__)  # 看看OpenCV的版本,此行代码可以不用
image = cv2.imread("car1.png")
print(HyperLPR_plate_recognition(image))

图片如下(其他的请自己测试)

在这里插入图片描述

不过很可惜运行还是出错:
在这里插入图片描述

4.5.1
(1, 3, 534, 1099)
620 230 916 371
Traceback (most recent call last):
  File "car.py", line 9, in <module>
    print(HyperLPR_plate_recognition(image))
  File "C:\ProgramData\Anaconda3\lib\site-packages\hyperlpr\__init__.py", line 8, in HyperLPR_plate_recognition
    return PR.plate_recognition(Input_BGR,minSize,charSelectionDeskew)
  File "C:\ProgramData\Anaconda3\lib\site-packages\hyperlpr\hyperlpr.py", line 311, in plate_recognition
    cropped_finetuned = self.finetune(cropped)
  File "C:\ProgramData\Anaconda3\lib\site-packages\hyperlpr\hyperlpr.py", line 263, in finetune
    g = self.to_refine(image_, pts)
  File "C:\ProgramData\Anaconda3\lib\site-packages\hyperlpr\hyperlpr.py", line 231, in to_refine
    mat_ = cv2.estimateRigidTransform(org_pts, target_pts, True)
AttributeError: module 'cv2.cv2' has no attribute 'estimateRigidTransform'

关键的错误就是这个:
AttributeError: module ‘cv2.cv2’ has no attribute 'estimateRigidTransform

经过查询,发现 opencv 4.5 中 cv2.estimateRigidTransform()方法已经停用,可以使用cv2.estimateAffine2D(),cv2.estimateAffinePartial2D()来替代。

这两个方法原始定义如下:

def estimateAffine2D(from_, to, inliers=None, method=None, ransacReprojThreshold=None, maxIters=None, confidence=None, refineIters=None):
    pass

def estimateAffinePartial2D(from_, to, inliers=None, method=None, ransacReprojThreshold=None, maxIters=None, confidence=None, refineIters=None):
    pass

我们就不用专门去研究了,进入 File “/usr/local/lib/python3.7/dist-packages/hyperlpr/hyperlpr.py”, line 2, in to_refine,

将函数改写为

mat_, _ = cv2.estimateAffinePartial2D(org_pts, target_pts, True)

注意,cv2.estimateAffinePartial2D(),函数有两个返回值,第一个返回值等于cv2.estimateRigidTransform()函数的返回值。

好了,现在运行,结果如下

(base) E:\python>python car.py
4.5.1
(1, 3, 281, 500)
189 199 299 229
[['渝H11557', 0.980111471244267, [189, 199, 299, 229]]]
  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二粒米

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值