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