python-opencv实现简单的车牌定位

时间:2018-03-28 22:01:57   收藏:0   阅读:1973

车牌定位的原理:https://blog.csdn.net/relocy/article/details/78705662

训练好的分类器:https://github.com/zeusees/HyperLPR/tree/master/model

这个开源项目中还有完整的车牌识别代码。

这里只是简单地根据这个项目训练好的分类器来实现了一下车牌定位,核心代码也是参考的这个项目。

代码:

import cv2

# 使用的是HyperLPR已经训练好了的分类器
watch_cascade = cv2.CascadeClassifier(./cascade.xml)

# 先读取图片
image = cv2.imread("1.jpg")

resize_h = 1000
height = image.shape[0]
scale = image.shape[1]/float(image.shape[0])
image = cv2.resize(image, (int(scale*resize_h), resize_h))

image_gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
watches = watch_cascade.detectMultiScale(image_gray, 1.1, 2, minSize=(36, 9), maxSize=(36*40, 9*40))

print("检测到车牌数", len(watches))
for (x, y, w, h) in watches:
    cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 1)

cv2.imshow("image", image)
cv2.waitKey(0)
cv2.destroyAllWindows()

 

结果:

技术分享图片

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!