【问题标题】:OCR Preprocessing: Remove lines crossing charactersOCR 预处理:删除与字符交叉的行
【发布时间】:2019-06-04 21:56:07
【问题描述】:

我目前正在尝试提高GoogleCloud Vision的识别率,所以我正在构建一个预处理管道。

我目前可以创建一个覆盖图像中字符的蒙版,但正如您在下面的示例中看到的那样,它还显示了线条。现在由于这些线可以穿过字符,如果可能的话,我想在不破坏字符的情况下将它们从掩码中删除。

当前步骤:

线路检测: InputImage -> Grayscale -> Blackhat -> GaussianBlur -> Threshhold(OTSU) -> HoughLinesP

蒙版生成:InputImage -> Grayscale -> Blackhat -> GaussianBlur -> Threshhold(OTSU)-> ConnectedComponents

ImageExamples:(由于隐私保护,无法共享完整图像)

图像显示原始图像、蒙版和识别的线条。 以下代码用于生成掩码并查找行

Mat picture = Imgcodecs.imread(path);
Imgproc.cvtColor(picture, picture, Imgproc.COLOR_BGR2GRAY);
Imgcodecs.imwrite("/home/meik/Pictures/asdfGray.png", picture);
Mat blackhatElement = Imgproc.getStructuringElement(Imgproc.CV_SHAPE_RECT, new Size(7, 7));

Imgproc.morphologyEx(picture, picture, Imgproc.MORPH_BLACKHAT, blackhatElement);
Imgproc.GaussianBlur(picture, picture, new Size(5, 3), 0);
Imgproc.threshold(picture, picture, 0, 255, Imgproc.THRESH_BINARY | Imgproc.THRESH_OTSU);

/**
 * Line Detection with Canny and HoughLines(P)
 */
Mat lines = new Mat();
Mat linesResult = Mat.zeros(picture.rows(),picture.cols(), CvType.CV_8UC1);
Imgproc.HoughLinesP(picture, lines,1, Math.PI/180,100, 20, 0);
System.out.println("lines rows:" + lines.rows());
for (int x = 0; x < lines.rows(); x++) {
    double[] l = lines.get(x, 0);
    Imgproc.line(linesResult, new Point(l[0], l[1]), new Point(l[2], l[3]), new Scalar(255, 255, 255), 1, Imgproc.LINE_8, 0);
}
/**End of line detection*/
Mat kernel = Imgproc.getStructuringElement(Imgproc.CV_SHAPE_CROSS, new Size(3,3));
Imgproc.dilate(linesResult,linesResult,kernel);
Core.bitwise_not(linesResult,linesResult);

我发现 this paper 正在谈论这个问题,但我很难理解他们的方法。

我如何从这里开始删除行而不破坏字符?

【问题讨论】:

    标签: java opencv computer-vision


    【解决方案1】:

    我真的不认为你需要参考论文来做到这一点。

    只需使用颜色信息或霍夫线找出一条很长的直线

    使用该信息创建蒙版图像。

    然后使用 opencv inpaint 将其删除。

    https://docs.opencv.org/2.4/modules/photo/doc/inpainting.html

    例如你想要的类似于底部的图像。它要求拆除交通灯杆。并且您希望删除写作指南。本质上是一样的

    【讨论】:

      【解决方案2】:

      一些简单的图像预处理怎么样?
      例如使用阈值只维持一定的颜色范围(而不是直接将图像转换为灰度)。

      这样的东西集成在 GIMP 中,请参阅 https://docs.gimp.org/2.8/en/gimp-tool-threshold.html

      您可能想尝试各种阈值。

      【讨论】:

        猜你喜欢
        • 2018-10-22
        • 2020-01-11
        • 2015-03-15
        • 1970-01-01
        • 1970-01-01
        • 2016-03-10
        • 1970-01-01
        • 2015-06-14
        • 1970-01-01
        相关资源
        最近更新 更多