phnmnn
phnmnn

Reputation: 13260

How to fill gaps between each segment of the 7-segment character

I want to recognize digits from odometer by mobile using tesseract library. Source image:

enter image description here

Next step:

enter image description here

Now i need to fill gaps between each segment. Can you help me, how i do it? (english training data work better for me than 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()

Upvotes: 2

Views: 947

Answers (1)

Dainius Šaltenis
Dainius Šaltenis

Reputation: 1734

OpenCV has some morphology methods, which white fill the gaps between black pixels (like THIS or THIS). Pay attention to morphology opening method, this should be the primary method for solving this, but do not be afraid to combine it with dilating if only this does not help. I am not sure what software do you use for image processing, if it does have similar methods, try them out, otherwise I would highly recomend you installing OpenCV, which (is free of course) has many image-processing operations with very high speed. Also, you could try a bit to experiment with threshold values and find the balance between how much corners it cuts out and how much shadows it takes off (combined with morphological operations this should solve the issue for you).

Upvotes: 1

Related Questions