opencv入门——车牌提取

利用训练好的ascadeClassifier对车辆车牌做简单的识别

效果:

 

 

 

 

代码:

#day06
import os

x=0
for root,dirs,files in os.walk("C:/Users/31132/Desktop/chepai"):
    for d in dirs:
        print(d)
    for file in files:
        imgPath=root+'/'+file

        img=cv2.imread(imgPath)
        faceCascade=cv2.CascadeClassifier("Resources/haarcascade_russian_plate_number.xml")
        imgGray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
        faces=faceCascade.detectMultiScale(imgGray,1.1,2)
        x,y,w,h=0,0,0,0
        for face in faces:
            x,y,w,h=face
            cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        imgRes=img[y:y+h,x:x+w]
        cv2.imshow("res",img)
        cv2.imshow("ress",imgRes)
        cv2.imwrite(file,imgRes)

 

posted @ 2020-11-11 16:41  XiaoGao128  阅读(509)  评论(0编辑  收藏  举报