题目:如何利用HyperLPR车牌识别项目测试视频文件
一.下载项目,也可以Git clone。
HyperLPR项目下载链接:https://github.com/zeusees/HyperLPR
二.测试图片效果
下载HyperLPR项目后,用pycharm打开工程,界面如下所示:
新建python.file文件,命名为test_image.py。编写test_image.py,如下图所示:
import HyperLPRLite as pr
import cv2
import demo
demo.drawRectBox(image,rect,addText)
grr = cv2.imread("images_rec/8.jpg")
model = pr.LPR("model/cascade.xml","model/model12.h5","model/ocr_plate_all_gru.h5")
for pstr,confidence,rect in model.SimpleRecognizePlateByE2E(grr):
if confidence>0.7:
image = drawRectBox(grr, rect, pstr+" "+str(round(confidence,3)))
print ("plate_str:")
print (pstr)
print ("plate_confidence")
print (confidence)
cv2.namedWindow("image",0)
cv2.imshow("image",image)
cv2.waitKey(0)
其中,cv.imread( )为读取测试图片,根据需要可以自行修改路径。确认路径无误后,run,结果如下所示:
三.测试视频文件
新建python.file文件,命名为test_video.py。编写test_video.py,如下图所示:
# -*- coding: utf-8 -*-
import time
import cv2
from hyperlpr_py3 import pipline as pp
import click
@click.command()
@click.option('--video', help = 'input video file')
def main(video):
print("[INFO] starting video stream...")
# vs = VideoStream(src=0).start()
#修改测试视频路径
stream = cv2.VideoCapture("E:/HyperLPR/demo_images/video.mp4")
time.sleep(2.0)
while True:
# grab the frame from the threaded video stream
grabbed, frame = stream.read()
if not grabbed:
print('No data, break.')
break
_, res = pp.SimpleRecognizePlate(frame)
# convert the input frame from BGR to RGB then resize it to have
# a width of 750px (to speedup processing)
# rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# rgb = imutils.resize(frame, width = 750)
# r = frame.shape[1] / float(rgb.shape[1])
cv2.putText(frame, str(res), (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 255, 255), 2)
cv2.imshow("Frame", frame)
key = cv2.waitKey(1) & 0xFF
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
# do a bit of cleanup
cv2.destroyAllWindows()
stream.release()
if __name__ == '__main__':
main()
其中,cv.VideoCapture( )为读取测试视频,根据需要可以自行修改路径。确认路径无误后,run。检测速度较慢,不再展示run结果。
注:
本文参考文献:[https://blog.csdn.net/yang1159/article/details/89492368
配置环境可以参考:
https://www.cnblogs.com/zhupengfei/p/12104504.html
亲测好用!
如还有其他问题可以评论留言,大家一起解决难题。