簡體   English   中英

使用 OpenCV 從車牌中分割字符

[英]Segmenting characters from a license plate with OpenCV

我清理了一塊專利板來讀取字符。 現在,我陷入了必須分割字符的部分。

對於清潔盤子的階段,我這樣做:

在此處輸入圖像描述

對此:

在此處輸入圖像描述

現在的想法是能夠分割字符,然后能夠使用我開發的神經網絡讀取它,對於分割我攜帶這個但仍然不明白為什么它不起作用:

# Create sort_contours() function to grab the contour of each digit from left to right
def sort_contours(cnts,reverse = False):
    i = 0
    boundingBoxes = [cv2.boundingRect(c) for c in cnts]
    (cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes),
                                        key=lambda b: b[1][i], reverse=reverse))
    return cnts

cont, _  = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

# creat a copy version "test_roi" of plat_image to draw bounding box
test_roi = plate_image.copy()

# Initialize a list which will be used to append charater image
crop_characters = []

# define standard width and height of character
digit_w, digit_h = 40, 80

for c in sort_contours(cont):
    (x, y, w, h) = cv2.boundingRect(c)
    ratio = h/w
    if 1<=ratio<=3.5: # Only select contour with defined ratio
        if h/plate_image.shape[0]>=0.1: # Select contour which has the height larger than 50% of the plate
            # Draw bounding box arroung digit number
            cv2.rectangle(test_roi, (x, y), (x + w, y + h), (0, 255,0), 2)

            # Sperate number and gibe prediction
            curr_num = thre_mor[y:y+h,x:x+w]
            curr_num = cv2.resize(curr_num, dsize=(digit_w, digit_h))
            _, curr_num = cv2.threshold(curr_num, 220, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
            crop_characters.append(curr_num)

print("Detect {} letters...".format(len(crop_characters)))
fig = plt.figure(figsize=(10,6))
plt.axis(False)
plt.imshow(test_roi)

我怎樣才能使實施正確? 歡迎任何幫助!

如果您想通過神經網絡對 label 它們進行清理,則不需要進行第一步清理。 如果您查看區域建議神經網絡(rnn、fast-rnn、faster-rnn、yolo、mask-rnn 等),他們將在一個 go 中進行分割和分類。

如果您確實想要 go 進行分割,請先查看連接的組件。 它將 select 連接在一起的所有正像素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM