使用车牌识别hyperlpr库,报AttributeError: module ‘cv2.cv2‘ has no attribute ‘estimateRigidTransform‘错误问题

车牌检测算法安装:第一步:输入python -m pip install --upgrade pip升级pip
第二步:输入pip install hyperlpr -i https://pypi.tuna.tsinghua.edu.cn/simple,下载清华镜像源

HyperLPR 地址

安装hyperlpr库后,运行示例发现报了如下错误

#导入包
from hyperlpr import *
#导入OpenCV库
import cv2
#读入图片
image = cv2.imread("demo.jpg")
#识别结果
print(HyperLPR_plate_recognition(image))
Traceback (most recent call last):
  File "readlicensePlate.py", line 7, in <module>
    print(HyperLPR_plate_recognition(image))
  File "/usr/local/lib/python3.7/dist-packages/hyperlpr/__init__.py", line 8, in HyperLPR_plate_recognition
    return PR.plate_recognition(Input_BGR,minSize,charSelectionDeskew)
  File "/usr/local/lib/python3.7/dist-packages/hyperlpr/hyperlpr.py", line 311, in plate_recognition
    cropped_finetuned = self.finetune(cropped)
  File "/usr/local/lib/python3.7/dist-packages/hyperlpr/hyperlpr.py", line 263, in finetune
    g = self.to_refine(image_, pts)
  File "/usr/local/lib/python3.7/dist-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'
使用Opencv 3.4.12 opencv3.5 opencv 4.5.0 均报了以上错误

查看资料发现,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 231, in to_refine,

将函数改写为

mat_, _ = cv2.estimateAffinePartial2D(org_pts, target_pts, True)
注意,cv2.estimateAffinePartial2D(),函数有两个返回值,第一个返回值等于cv2.estimateRigidTransform()函数的返回值。如果不写第二个返回值会报TypeError: Expected Ptr<cv::UMat> for argument 'M'错误
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值