【问题标题】:How can i remove background noise from a handwritten text image?如何从手写文本图像中去除背景噪音?
【发布时间】:2021-03-10 05:08:56
【问题描述】:

我尝试了这些方法,但没有得到任何真正的改变。实际上,我正在尝试使用 Google 云视觉 API 构建手写 OCR。请向我建议我可以为预处理步骤做些什么。

1.

image = cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 15)
    kernel  = np.ones((5, 5), np.uint8)
    image   = cv2.dilate(image, kernel, iterations = 1) 
    kernel  = np.ones((5, 5), np.uint8)
    image   = cv2.erode(image, kernel, iterations = 1)

【问题讨论】:

    标签: opencv image-processing computer-vision ocr handwriting-recognition


    【解决方案1】:

    另一种方法是 HSV 滤色器。因为您使用的是蓝色笔,所以我们可以选择我们想要的颜色。示例代码:

    import cv2
    import numpy as np
    
    image = cv2.imread('9rS31.jpg')
    hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    lower_green = np.array([100, 43, 20])
    upper_green = np.array([130, 255, 255])
    mask = cv2.inRange(hsv, lower_green, upper_green)
    res = cv2.bitwise_and(image, image, mask=mask)
    
    gray = cv2.cvtColor(res,cv2.COLOR_BGR2GRAY)
    ret, generator = cv2.threshold(gray, 1,255,cv2.THRESH_BINARY)
    
    cv2.imwrite("img.jpg",generator)
    

    生成的图像:

    【讨论】:

      【解决方案2】:

      噪音包括教科书中的水平线。所以一种方法是使用

      cv2.getStructuringElement
      

      您可以在互联网上找到更多信息。示例代码:

      import cv2
      
      # Load image
      image = cv2.imread('9rS31.jpg')
      img=image.copy()
      
      # Remove border
      horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (50,1))
      temp2 = 255 - cv2.morphologyEx(image, cv2.MORPH_CLOSE, horizontal_kernel)
      result = cv2.add(temp2, image)
      
      # Convert to grayscale and Otsu's threshold
      gray = cv2.cvtColor(result, cv2.COLOR_BGR2GRAY)
      gray = cv2.GaussianBlur(gray,(5,5),0)
      _,thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU | cv2.THRESH_BINARY_INV)
      
      cv2.imwrite('img.jpg',thresh)
      cv2.imshow('img', thresh)
      cv2.waitKey()
      

      生成的图片:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-03-19
        • 1970-01-01
        • 2019-12-06
        • 2018-12-06
        • 1970-01-01
        • 2015-09-16
        • 2018-07-15
        相关资源
        最近更新 更多