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


车牌定位的原理: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()

 

结果:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM