检测带有OpenCV框的手写字符

问题描述 投票:2回答:2

我正在尝试阅读一个盒装输入的手写表单。

我在图像上运行了tesseract但得到了奇怪的结果。根据我的理解,我认为最好的办法是检测边界框并减去图像中的边界框。检测盒子的最佳方法是什么(角色周围的半盒子)。我尝试了cv2.HoughLines(),但没有结果。

我是OpenCV的新手。如果有人可以帮助我,这将是非常有帮助的。

opencv computer-vision python-tesseract
2个回答
0
投票

您的输入格式似乎非常干净且一致。您可以简单地硬编码每个框的宽度(以像素为单位)并裁剪出字符。但是,如果输入格式没有修复,那么我们可以扩展这个答案来处理它(它会有点贵),所以作为第一次尝试,我们只需要硬编码盒子的宽度(以像素为单位)。

def get_image_chunks(img, size):
    chunks = []
    # To remove black borders
    padding = 2
    for i in xrange(0, img.shape[1], size):
        col_start = i + padding
        col_end = i + size - padding

        # Slicing the numpy array.
        chunks.append(img[:-padding, col_start:col_end])

    return chunks

img = cv2.imread("/Users/anmoluppal/Downloads/GLUmJ.jpg", 0)
chunks = get_image_chunks(img, 42)

输出:

enter image description here; enter image description here; enter image description here


0
投票

谢谢你的想法。我刚刚意识到我可以看看计算垂直像素和大于某个阈值

def get_pixel_count_in_col(img,col):
        count=0
        for j in range(img.shape[0]):
                if(img[j,col]<255):
                        count=count+1
        return count
def cleanup_img(img):
        foundlines=[]
        for i in range(img.shape[1]):
                if(get_pixel_count_in_col(img,i)>img.shape[0]*0.7):
                        foundlines.append(i)
                        if(get_pixel_count_in_col(img,i-1)>img.shape[0]*0.25):
                                foundlines.append(i-1)
                        if(get_pixel_count_in_col(img,i+1)>img.shape[0]*0.25):
                                foundlines.append(i+1)
        return np.delete(img,foundlines,1)

生成的图像更有意义。但有没有其他简单的方法来做到这一点?

enter image description here

提前致谢

© www.soinside.com 2019 - 2024. All rights reserved.