如何消除给定图像中的噪点,以使ocr输出完美? [英] How to remove the noise in the given image so that the ocr output be perfect?

查看:251
本文介绍了如何消除给定图像中的噪点,以使ocr输出完美?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经对该孟加拉文本图像进行了otsu阈值处理,并使用tesseract进行了OCR,但输出非常糟糕.我应该采用什么预处理来消除噪音?我也想对图像进行偏移校正,因为它略有倾斜. 我的代码在下面给出

I have done otsu thresholding on this bengali text image and use tesseract to OCR but the output is very bad. What preprocessing should I apply to remove the noise? I want to deskew the image as well, as it has slight skewed. My code is given below

import tesserocr
from PIL import Image
import cv2
import codecs
image = cv2.imread("crop2.bmp", 0)
(thresh, bw_img) = cv2.threshold(image, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)

img = Image.fromarray(bw_img)
text = tesserocr.image_to_text(img, lang='ben')
file = codecs.open("output_text", "w", "utf-8")
file.write(text)
file.close()

推荐答案

您可以通过移除可能会提高精度的较小的连接组件来消除噪声.您还需要获得噪声分量阈值的最佳值.

You can remove the noises by removing small connected components that might improve the accuracy. You would also need to get optimum value for noisy components threshold value.

import cv2 
import numpy as np

img = cv2.imread(r'D:\Image\st5.png',0)
ret, bw = cv2.threshold(img, 128,255,cv2.THRESH_BINARY_INV)

connectivity = 4
nb_components, output, stats, centroids = cv2.connectedComponentsWithStats(bw, connectivity, cv2.CV_32S)
sizes = stats[1:, -1]; nb_components = nb_components - 1
min_size = 50 #threshhold value for small noisy components
img2 = np.zeros((output.shape), np.uint8)

for i in range(0, nb_components):
    if sizes[i] >= min_size:
        img2[output == i + 1] = 255

res = cv2.bitwise_not(img2)

去噪的图像:

这篇关于如何消除给定图像中的噪点,以使ocr输出完美?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆