python - 使用 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)
我怎样才能使实施正确?欢迎任何帮助!
解决方案
如果您想通过神经网络标记它们,则不需要清理的第一步。如果您查看区域建议神经网络(rnn、fast-rnn、faster-rnn、yolo、mask-rnn 等),它们将一次性完成分割和分类。
如果您确实想进行细分,请先查看连接的组件。它将选择所有连接在一起的正像素。
推荐阅读
- angular - Angular Firebase 未获取实时结果,console.log 显示未定义
- python - 如果 sys.stdout.write("\b\b") 在 Jupyter Notebook 中擦除两个字符,为什么 sys.stdout.write("\b\b\b") 只擦除一个字符?
- python - 具有多个输入和多个输出列的 Pandas 应用、滚动、分组
- javascript - 为什么我在javascript中的队列数据结构表现得不应该
- android - Android 如何使用数字创建分页
- tensorflow - 用于 tfjs 的预训练模型策略
- c# - LINQ 为 SQL 提供不同的结果
- android - 无法在 Windows 10 上下载 Android Studio
- go - 使用 go get 从 WSL 2 上的私有 github 存储库中获取依赖项
- mysql - 聚合后Django ORM加入自我