畢業設計 python opencv實現車牌識別 形狀定位


主要代碼參考https://blog.csdn.net/wzh191920/article/details/79589506

GitHub:https://github.com/yinghualuowu

上文我們已經讓圖像變成了很多框框,根據原先版本,這種做法可以使用圖形定位,因為車牌有尺寸規定啦,這是原版本的代碼,還是別動了。

首先,我們設定一個最小的面積值:2000

先把矩形找到,把面積小的排除了,然后根據長寬比再排除一些,接下來保存合適的就行了

def img_findContours(img_contours,oldimg):
    img, contours, hierarchy = cv2.findContours(img_contours, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    contours = [cnt for cnt in contours if cv2.contourArea(cnt) > Min_Area]
    print("findContours len = ", len(contours))
    # 排除面積最小的點
    debug.img_show(img)
    car_contours = []
    for cnt in contours:

        ant = cv2.minAreaRect(cnt)
        width, height = ant[1]
        if width < height:
            width, height = height, width
        ration = width / height
        print(ration)
        if ration > 2 and ration < 5.5:
            car_contours.append(ant)
            box = cv2.boxPoints(ant)
            box = np.int0(box)
            debug.img_contours(oldimg,box)
    return  car_contours

會發現圈不全,是因為預處理的原因....以后會用其他方式去定位,我們換一個吧

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM