繁体   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