com.aspose.ocr

Interface IRecognitionBlock



  • public interface IRecognitionBlock

    This interface represents a block.

    Block is a rectangular region that may contain text, picture or any other data. OCR Engine will recognize whole image and will try to find text blocks by itself, if blocks are not specified by user.


     
     OcrEngine ocr = new OcrEngine();
     ocr.Image = ImageStream.fromFile(@"image.tiff");
     ocr.getLanguageContainer().addLanguage(LanguageFactory.load("Portuguese-RSC-HS-PB-ResourcesAllCharsNet.zip")); // Resource file name
    
     IRecognitionBlock pictureBlock = RecognitionBlock.createPictureBlock(0, 0, 100, 200);
     ocr.getConfig().addRecognitionBlock(pictureBlock);
     IRecognitionBlock textBlock = RecognitionBlock.createTextBlock(110, 210, 100, 100);
     ocr.getConfig().addRecognitionBlock(textBlock);
    
     if (ocr.process())
     {
        if (textBlock.getRecognitionData() instanceof IRecognizedTextPartInfo)
           System.out.println(((IRecognizedTextPartInfo)textBlock.isRecognitionData()).getText());
     }
     

    • Method Detail

      • getBlockId

        UUID getBlockId()
        Sets when the block is created.
        Returns:
        Returns the block's ID. Each block has unique ID.
      • getRecognitionData

        IRecognizedPartInfo getRecognitionData()
        Gets the recognition data.
        Returns:
        The recognition data.
      • getRectangle

        Rectangle getRectangle()
        Returns the rectangle that defines recognition block inside specified image
        Returns:
        Returns the recognized text
      • getToRecognize

        boolean getToRecognize()
        Shows if block needs to be processed by OCR Engine
        Returns:
      • getWhitelist

        char[] getWhitelist()
        Gets a white list of characters for the recognition block. This property allows to specify a new recognition alphabet (in other words - to restrict recognition alphabet). This feature may be useful when, for example, images you need to process contain only digits. Whitelist may guarantee that recognition result will contain only digits without any characters (e.g. digit '0' may be recognized as char 'O', or '1' as 'I').
        Returns:
        *


         
         OcrEngine ocr = new OcrEngine();
         IRecognitionBlock block = RecognitionBlock.createTextBlock(x, y, width, height);
         block.setWhitelist(new char[] {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'});
         ocr.getConfig().addRecognitionBlock(block);
         ocr.getConfig().setDetectTextRegions(false);
         ocr.setImage(ImageStream.fromFile("numbers.png"));
         ocr.process();
         

      • setWhitelist

        void setWhitelist(char[] value)
        Sets a white list of characters for the recognition block. This property allows to specify a new recognition alphabet (in other words - to restrict recognition alphabet). This feature may be useful when, for example, images you need to process contain only digits. Whitelist may guarantee that recognition result will contain only digits without any characters (e.g. digit '0' may be recognized as char 'O', or '1' as 'I').