垂直投影和水平投影
Vertical projection and horizontal projection
我正在尝试为该论文中的 ocr 实现以下算法。
https://arxiv.org/ftp/arxiv/papers/1707/1707.00800.pdf
我对那部分感到困惑:
我构建了图像的垂直剖面:
env = np.sum(img, axis=1)
这就是我得到的
我正在寻找算法的清晰解释,也许是伪代码
根据我的理解,该算法旨在分离单个阿拉伯字母,这些字母在书写时通过水平线连接(我对阿拉伯字母的知识完全为零)。
因此该算法假定给定图像是水平对齐的(否则它将不起作用),并且它正在寻找具有相似黑色像素上键的区域。
构建图像的垂直剖面后,您只需找到单词中最常见的高度(图像中第二高的高度)。比起您只是将特定高度区域与其余区域之间的图像分开。
使用您的图片:
红线是您需要查找的第二个最常见的高度(可以使用直方图来完成)。
绿线表示各个字符之间的分隔(因此这里您将得到 4 个字符)。
顺便说一句,你的图像比论文中使用的图像更嘈杂和失真,所以你可能应该找到一些值范围来离散化你的高度值(例如使用直方图)。
伪代码(或未经证实的未经测试的代码):
# Discretize the y values to n_bins (noisier image will mean you can use less bins):
height_hist = np.histogram(y, bins=n_bins)
# Find bin with the second largest number of values:
bin = np.argsort(height_hist[0])[-2]
# Get the limit values of the bin:
y_low, y_high = height_hist[1][bin], height_hist[1][bin+1]
# Go over the vertical projection values and separate to characters:
zero = y[0] # Assuming the first projected value is outside of the word
char_list = []
i = 0
inside_char = False
while i < len(y):
if y[i] != zero:
start = i # start of char
# Find end of current char:
for j in range(i, len(y)):
if y_low<=y[i] and y[i]<=y_high:
end = j # end of char
char_list.append([start, end]) # add to char list
i = end
# Find the start of the next char:
for j in range(i, len(y)):
if y_low>y[i] or y[i]>y_high:
i = j
else:
i += 1
我正在尝试为该论文中的 ocr 实现以下算法。
https://arxiv.org/ftp/arxiv/papers/1707/1707.00800.pdf
我对那部分感到困惑:
我构建了图像的垂直剖面:
env = np.sum(img, axis=1)
这就是我得到的
我正在寻找算法的清晰解释,也许是伪代码
根据我的理解,该算法旨在分离单个阿拉伯字母,这些字母在书写时通过水平线连接(我对阿拉伯字母的知识完全为零)。
因此该算法假定给定图像是水平对齐的(否则它将不起作用),并且它正在寻找具有相似黑色像素上键的区域。
构建图像的垂直剖面后,您只需找到单词中最常见的高度(图像中第二高的高度)。比起您只是将特定高度区域与其余区域之间的图像分开。
使用您的图片:
红线是您需要查找的第二个最常见的高度(可以使用直方图来完成)。
绿线表示各个字符之间的分隔(因此这里您将得到 4 个字符)。
顺便说一句,你的图像比论文中使用的图像更嘈杂和失真,所以你可能应该找到一些值范围来离散化你的高度值(例如使用直方图)。
伪代码(或未经证实的未经测试的代码):
# Discretize the y values to n_bins (noisier image will mean you can use less bins):
height_hist = np.histogram(y, bins=n_bins)
# Find bin with the second largest number of values:
bin = np.argsort(height_hist[0])[-2]
# Get the limit values of the bin:
y_low, y_high = height_hist[1][bin], height_hist[1][bin+1]
# Go over the vertical projection values and separate to characters:
zero = y[0] # Assuming the first projected value is outside of the word
char_list = []
i = 0
inside_char = False
while i < len(y):
if y[i] != zero:
start = i # start of char
# Find end of current char:
for j in range(i, len(y)):
if y_low<=y[i] and y[i]<=y_high:
end = j # end of char
char_list.append([start, end]) # add to char list
i = end
# Find the start of the next char:
for j in range(i, len(y)):
if y_low>y[i] or y[i]>y_high:
i = j
else:
i += 1