目前,我正在从事一个 OCR 项目,我需要从标签中读取文本(请参见下面的示例图像)。我遇到了图像倾斜问题,我需要帮助修复图像倾斜,以便文本水平而不是倾斜。目前,我正在尝试从给定范围内对不同角度进行评分(下面包含代码)的过程,但这种方法不一致,有时过度校正图像歪斜或平坦无法识别歪斜并纠正它。请注意,在倾斜校正之前,我将所有图像旋转 270 度以使文本直立,然后我通过下面的代码传递图像。传递给函数的图像已经是二进制图像。
代码:
def findScore(img, angle):
"""
Generates a score for the binary image recieved dependent on the determined angle.\n
Vars:\n
- array <- numpy array of the label\n
- angle <- predicted angle at which the image is rotated by\n
Returns:\n
- histogram of the image
- score of potential angle
"""
data = inter.rotate(img, angle, reshape = False, order = 0)
hist = np.sum(data, axis = 1)
score = np.sum((hist[1:] - hist[:-1]) ** 2)
return …Run Code Online (Sandbox Code Playgroud)