Sha256: fdbd237d1f2ba8a193086485d8cdb0d5f8d082eef6ee44390198d51e5fc1816a

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

module Asposeocrjava
  module ExtractTextFromPartOfImage
    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

        # Clear notifier list
        ocr_engine.clearNotifies()

        # Clear recognition blocks
        ocr_engine.getConfig().clearRecognitionBlocks()

        # Add 2 rectangle blocks to user defined recognition blocks
        ocr_engine.getConfig().addRecognitionBlock(Rjb::import('com.aspose.ocr.RecognitionBlock').createTextBlock(52, 48, 67, 74))
        ocr_engine.getConfig().addRecognitionBlock(Rjb::import('com.aspose.ocr.RecognitionBlock').createTextBlock(100, 46, 38, 46))

        # Ignore everything else on the image other than the user defined recognition blocks
        ocr_engine.getConfig().setDetectTextRegions(false)

        # Set Image property by loading an image from file path
        ocr_engine.setImage(Rjb::import('com.aspose.ocr.ImageStream').fromFile(data_dir + 'ocr.png'))
                    
        # Run recognition process
        if ocr_engine.process()
            # Retrieve an array of recognized text by parts
            text = ocr_engine.getText().getPartsInfo()
            # Iterate over the text parts
            i = 0
            while i < text.length
                info = text[i]
                # Display part information
                puts "Block: " + info.getBox().to_string + " Text: " + info.getText().to_s
                i +=1
            end
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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