if an image has different lighting conditions in different areas. In that case, adaptive thresholding can help. Here, the algorithm determines the threshold for a pixel based on a small region around it. So we get different thresholds for different regions of the same image which gives better results for images with varying illumination.
It needs two inputs, one is our original image, second one is called structuring element or kernel which decides the nature of operation
我们需要定义一个内核(过滤器)来处理图像
krn = np.ones((3, 3), np.uint8)
我们将使用opening和closing:
Opening is just another name of erosion followed by dilation. It is useful in removing noise
Closing is reverse of Opening, Dilation followed by Erosion. It is useful in closing small holes inside the foreground objects, or small black points on the object.
我解决这个问题的方法是:
1-应用自适应阈值
2-应用形态变换
3-应用位运算
步骤1:自适应阈值
从documentation开始:
总而言之:当用作阈值的全局值表现不佳时,将使用自适应阈值
结果:
第二步:形态变换
从documentation开始:
我们需要定义一个内核(过滤器)来处理图像
我们将使用
opening
和closing
:步骤3:按位操作
从documentation
结果:
现在,如果我们使用
pytesseract
来提取文本结果:
可选
对于您未来的OCR问题,您可以尝试提高图像分辨率。例如:
对于这个问题,它没有效果,但它可能会在将来帮助你
问题代码:
相关问题 更多 >
编程相关推荐