Nobleheart-Labs / Theia

MIT License
0 stars 0 forks source link

Tesseract OCR LED/LCD display text recognition #26

Closed NandhiniYeganathan closed 4 months ago

NandhiniYeganathan commented 4 months ago

Hi All,

I am trying to detect the numeric values from the digital display LED/LCD(Remote and other devices). Integrated the tesseract along with GPUImage and used the trained data. But it's not giving a proper result.

Here is the code:

let tesseract: G8Tesseract = G8Tesseract(language: "eng")! tesseract.delegate = self tesseract.charWhitelist = "0123456789:" tesseract.charBlacklist = "abcdefghijklmnopqrstuvwxyz_+-=/?.,><()*&^%$#@!:;" let imageCheck = UIImage(named: "remote1.jpg")//Sample image, but we need to capture the image from camera then used it let scaledImage = newImage?.scaledImage(1000) let preprocessedImage = scaledImage?.preprocessedImage() ?? scaledImage if let tesseract = G8Tesseract(language: "eng") { tesseract.engineMode = .tesseractOnly tesseract.pageSegmentationMode = .auto

        //Auto Adjustment to Input Image
        var inputImage = CIImage(image: preprocessedImage!)
        let options:[CIImageAutoAdjustmentOption : AnyObject] = [.enhance:1 as AnyObject]
        let filters = inputImage!.autoAdjustmentFilters(options: options)

        for filter: CIFilter in filters {
           filter.setValue(inputImage, forKey: kCIInputImageKey)
       inputImage =  filter.outputImage
          }
        let cgImage = context.createCGImage(inputImage!, from: inputImage!.extent)
        tesseract.image =  UIImage(cgImage: cgImage!)

        //Apply noir Filter
        let currentFilter = CIFilter(name: "CIPhotoEffectTonal")
        currentFilter!.setValue(CIImage(image: UIImage(cgImage: cgImage!)), forKey: kCIInputImageKey)

        let output = currentFilter!.outputImage
        let cgimg = context.createCGImage(output!, from: output!.extent)
        let processedImage = UIImage(cgImage: cgimg!)
        tesseract.image = processedImage
       // tesseract.image = preprocessedImage!
       tesseract.recognize()
        debugPrint("Text: \(String(describing: tesseract.recognizedText))")

}

Scaled image reference get from: https://www.kodeco.com/2010498-tesseract-ocr-tutorial-for-ios

O/P which is am getting:

Optional(\" 9 9\n 11593 7\n 1 80\n \n0\n5533\n\n\")"

remote1

Here is the files which am using for trained data:

Screenshot 2024-06-26 at 5 38 32 PM

Tried ssd.trained data but that also not working

Expected O/P: 25 and 5:21

Could you anyone guide me to resolve this.

Thanks!

NandhiniYeganathan commented 4 months ago

Query posted in respective GitHub.