Sha256: 3aa0b6ca59e791f6b5a3d6501e1cad9bd3af1309099e895cb955d2a5b773c1b5

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

module Asposeocrjava
  module RecognizeWhiteListedCharacters
    def initialize()
        data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
                
        # Initialize an instance of OcrEngine
        ocr_engine = Rjb::import('com.aspose.ocr.OcrEngine').new

        # Retrieve the OcrConfig of the OcrEngine object
        ocr_config = ocr_engine.getConfig()

        # Set the Whitelist property to recognize numbers only
        #ocr_config.setWhitelist(['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'])

        # Set the Image property by loading the image from file path location
        ocr_engine.setImage(Rjb::import('com.aspose.ocr.ImageStream').fromFile(data_dir + 'ocr.png'))

        # Set the RemoveNonText to true
        ocr_engine.getConfig().setRemoveNonText(true)

        # Process the image
        if ocr_engine.process()
            text = ocr_engine.getText()
            puts "Text: " + text.to_string
             
            expression = "(\\d+)"
            # Create a Pattern object
            pattern = Rjb::import('java.util.regex.Pattern').compile(expression)

            # Now create matcher object
            matcher = pattern.matcher(text.toString())
            if matcher.find()
                puts "Found value: " + matcher.group(0).to_string
            end
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
asposeocrjava-0.0.1 lib/asposeocrjava/OCR/recognizewhitelistedcharacters.rb