车牌检测算法安装:第一步:输入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'错误