【问题标题】:Segmenting characters from a license plate with OpenCV使用 OpenCV 从车牌中分割字符
【发布时间】:2020-09-16 23:59:29
【问题描述】:

我清理了一块专利板来读取字符。现在,我陷入了必须分割字符的部分。

在清洁盘子的阶段,我这样做:

到这里:

现在的想法是能够分割字符,然后能够使用我开发的神经网络读取它,对于分割我带着这个但仍然不明白为什么它不起作用:

# 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)

我怎样才能使实现正确?欢迎任何帮助!

【问题讨论】:

    标签: python python-3.x image opencv image-processing


    【解决方案1】:

    如果您想通过神经网络标记它们,则不需要进行清理的第一步。如果你看一下区域建议神经网络(rnn、fast-rnn、faster-rnn、yolo、mask-rnn 等),它们将一次性完成分割和分类。

    如果您确实想进行细分,请先查看连接的组件。它将选择所有连接在一起的正像素。

    【讨论】:

    • 感谢您的建议,之前我使用 YOLO 来检测和分割字符但效果不佳,就我所做的范围而言,使用过滤器和掩码似乎很好。跨度>
    • 它在培训和验证/开发人员集上表现如何?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    • 2017-09-30
    • 1970-01-01
    • 2019-04-18
    • 2021-03-27
    • 2015-01-21
    相关资源
    最近更新 更多