public static function run($dataDir = null)
 {
     # Initialize an instance of OcrEngine
     $ocr_engine = new OcrEngine();
     # Set the Image property by loading the image from file path location
     $imageStream = new ImageStream();
     $ocr_engine->setImage($imageStream->fromFile($dataDir . 'ocr.png'));
     # Process the image
     if ($ocr_engine->process()) {
         # Retrieve the first block of the recognized text part
         $first_block = $ocr_engine->getText()->getPartsInfo()[0];
         # Get the children of the first block that will the the lines in the block
         $lines_of_first_block = $first_block->getChildren();
         # Retrieve the fist line from the collection of lines
         $first_line = $lines_of_first_block[0];
         # Display the level of line
         print $first_line->getLevel();
         # Retrieve the fist word from the collection of words
         $first_word = $first_line->getChildren()[0];
         # Display the level of word
         print $first_word->getLevel();
         # Retrieve the fist character from the collection of characters
         print $first_character = $first_word->getChildren()[0];
         # Display the level of character
         print $first_character->getLevel() . PHP_EOL;
     }
 }
 public static function run($dataDir = null)
 {
     # Initialize an instance of OcrEngine
     $ocr_engine = new OcrEngine();
     # 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
     $imageStream = new ImageStream();
     $ocr_engine->setImage($imageStream->fromFile($dataDir . 'ocr.png'));
     # Set the RemoveNonText to true
     $ocr_engine->getConfig()->setRemoveNonText(true);
     # Process the image
     if ($ocr_engine->process()) {
         $text = $ocr_engine->getText();
         print "Text: " . (string) $text;
         $expression = "(\\d+)";
         # Create a Pattern object
         $pattern = new Pattern();
         $pattern = $pattern->compile($expression);
         # Now create matcher object
         $matcher = $pattern->matcher((string) $text);
         if ($matcher->find()) {
             print "Found value: " . (string) $matcher . PHP_EOL;
             //->group(0);
         }
     }
 }
 public static function run($dataDir = null)
 {
     # Initialize an instance of OcrEngine
     $ocr_engine = new OcrEngine();
     # Set the Image property by loading the image from file path location
     $imageStream = new ImageStream();
     $ocr_engine->setImage($imageStream->fromFile($dataDir . 'ocr.png'));
     # Set filters
     # Create CorrectionFilters collection
     $filters = new CorrectionFilters();
     # Initialize Median filter
     $filter = new MedianFilter(5);
     $filters->add($filter);
     # Create Gaussian Blur filter
     $filter = new GaussBlurFilter();
     $filters->add($filter);
     # Create Noise Removal filter
     $filter = new RemoveNoiseFilter();
     $filters->add($filter);
     # Assign collection to OcrEngine
     $ocr_engine->getConfig()->setCorrectionFilters($filters);
     # Perform OCR operation
     $ocr_engine->process();
     print "Whole result is: " . (string) $ocr_engine->getText() . PHP_EOL;
 }
 public static function run($dataDir = null)
 {
     # Initialize an instance of OcrEngine
     $ocr_engine = new OcrEngine();
     # Clear notifier list
     $ocr_engine->clearNotifies();
     # Clear recognition blocks
     $ocr_engine->getConfig()->clearRecognitionBlocks();
     # Add 2 rectangle blocks to user defined recognition blocks
     $recognitionBlock = new RecognitionBlock();
     $ocr_engine->getConfig()->addRecognitionBlock($recognitionBlock->createTextBlock(52, 48, 67, 74));
     $ocr_engine->getConfig()->addRecognitionBlock($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
     $imageStream = new ImageStream();
     $ocr_engine->setImage($imageStream->fromFile($dataDir . '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 < sizeof($text)) {
             $info = $text[$i];
             # Display part information
             print "Block: " . (string) $info->getBox() . " Text: " . (string) $info->getText() . PHP_EOL;
             $i += 1;
         }
     }
 }
 public static function run($dataDir = null)
 {
     # Initialize an instance of OcrEngine
     $ocr_engine = new OcrEngine();
     # Set the Image property by loading the image from file path location
     $imageStream = new ImageStream();
     $ocr_engine->setImage($imageStream->fromFile($dataDir . 'ocr.png'));
     # Process the image
     if ($ocr_engine->process()) {
         # Display the recognized text
         print "Text: " . (string) $ocr_engine->getText();
         # Retrieve an array of recognized text by parts
         $text = $ocr_engine->getText()->getPartsInfo();
         # Iterate over the text parts
         $i = 0;
         while ($i < sizeof($text)) {
             $symbol = $text[$i];
             # Display part information
             print "isItalic : " . (string) $symbol->getItalic() . PHP_EOL;
             print "isUnderline : " . (string) $symbol->getUnderline() . PHP_EOL;
             print "isBold : " . (string) $symbol->getBold() . PHP_EOL;
             print "Text Color : " . (string) $symbol->getTextColor() . PHP_EOL;
             print "Quality : " . (string) $symbol->getCharactersQuality() . PHP_EOL;
             $i += 1;
         }
     }
 }
 public static function run($dataDir = null)
 {
     # Initialize an instance of OcrEngine
     $ocr_engine = new OcrEngine();
     # Set the Image property by loading the image from remote location
     $imageStream = new ImageStream();
     $ocr_engine->setImage($imageStream->fromUrl("http://cdn.aspose.com/tmp/ocr-sample.bmp"));
     # Process the image
     if ($ocr_engine->process()) {
         # Display the recognized text
         print "Text: " . (string) $ocr_engine->getText() . PHP_EOL;
     }
 }
 public static function run($dataDir = null)
 {
     # Initialize an instance of OcrEngine
     $ocr_engine = new OcrEngine();
     # Set the Image property by loading the image from file path location
     $imageStream = new ImageStream();
     $ocr_engine->setImage($imageStream->fromFile($dataDir . 'ocr.png'));
     # Process the image
     if ($ocr_engine->process()) {
         # Display the recognized text
         print "Text: " . (string) $ocr_engine->getText() . PHP_EOL;
     }
 }
示例#8
0
 public static function run($dataDir = null)
 {
     # Initialize an instance of OcrEngine
     $ocr_engine = new OcrEngine();
     # Set the Image property by loading the image from file path location
     $imageStream = new ImageStream();
     $ocr_engine->setImage($imageStream->fromFile($dataDir . 'multipage.tiff'));
     # Set OcrEngine.ProcessAllPages to true in order to process all pages of TIFF in single run
     $ocr_engine->setProcessAllPages(true);
     # Process the image
     if ($ocr_engine->process()) {
         # Retrieve the list of Pages
         $pages = $ocr_engine->getPages();
         foreach ($pages as $page) {
             print "Text: " . (string) $page->getPageText() . PHP_EOL;
         }
     }
 }
 public static function run($dataDir = null)
 {
     # Initialize an instance of OcrEngine
     $ocr_engine = new OcrEngine();
     # Set the Image property by loading the image from file path location
     $imageStream = new ImageStream();
     $ocr_engine->setImage($imageStream->fromFile($dataDir . 'spanish.png'));
     # Clear the default language (English)
     $ocr_engine->getLanguageContainer()->clear();
     # Load the resources of the language from file path location or an instance of InputStream
     $languageFactory = new LanguageFactory();
     $ocr_engine->getLanguageContainer()->addLanguage($languageFactory->load($dataDir . "SpanishLanguageResources.zip"));
     # Process the image
     if ($ocr_engine->process()) {
         # Display the recognized text
         print "Text: " . (string) $ocr_engine->getText() . PHP_EOL;
     }
 }