如何填补7段字符的每个段之间的间隙

时间:2016-04-19 12:27:37

标签: android ios image-processing ocr tesseract

我想通过手机使用tesseract库识别里程表的数字。 来源图片:

enter image description here

下一步:

enter image description here

现在我需要填补每个细分之间的差距。 你能帮助我吗,我怎么做? (英语培训数据比https://github.com/arturaugusto/display_ocr更适合我)

image processing: 

func prepareImage(sourceImage: UIImage) -> UIImage {
    let avgLuminanceThresholdFilter = GPUImageAverageLuminanceThresholdFilter()
    avgLuminanceThresholdFilter.thresholdMultiplier = 0.67

    let adaptiveThresholdFilter = GPUImageAdaptiveThresholdFilter()
    adaptiveThresholdFilter.blurRadiusInPixels = 0.67

    let unsharpMaskFilter = GPUImageUnsharpMaskFilter()
    unsharpMaskFilter.blurRadiusInPixels = 4.0

    let stillImageFilter = GPUImageAdaptiveThresholdFilter()
    stillImageFilter.blurRadiusInPixels = 1.0

    let contrastFilter = GPUImageContrastFilter()
    contrastFilter.contrast = 0.75

    let brightnessFilter = GPUImageBrightnessFilter()
    brightnessFilter.brightness = -0.25

    //unsharpen
    var processingImage = unsharpMaskFilter.imageByFilteringImage(sourceImage)

    processingImage = contrastFilter.imageByFilteringImage(processingImage)
    processingImage = brightnessFilter.imageByFilteringImage(processingImage)

    //convert to binary black/white pixels
    processingImage = avgLuminanceThresholdFilter.imageByFilteringImage(processingImage)

    return processingImage

  }

OCR:

let tesseract_eng = G8Tesseract()
    tesseract_eng.language = "eng"
    tesseract_eng.engineMode = .TesseractOnly
    tesseract_eng.pageSegmentationMode = .Auto
    tesseract_eng.maximumRecognitionTime = 60.0
    tesseract_eng.setVariableValue("0123456789", forKey: "tessedit_char_whitelist")
    tesseract_eng.image = prepareImage(image)
    tesseract_eng.recognize()

1 个答案:

答案 0 :(得分:1)

OpenCV有一些形态学方法,白色填充黑色像素之间的间隙(如THISTHIS)。注意形态学开放方法,这应该是解决这个问题的主要方法,但如果只是这没有帮助,不要害怕将它与扩张相结合。我不确定你用什么软件进行图像处理,如果它有类似的方法,试试看,否则我会高度建议你安装OpenCV,它(当然是免费的)有很多图像处理操作,速度非常快。此外,您可以尝试一些实验阈值,并找出它切出多少角落和多少阴影之间的平衡(结合形态操作,这应该为您解决问题)。