[FR11 Engine] How to only recognize specified region of a document?

  • Last Post 05 September 2014
johan posted this 03 September 2014


I've been asked to evaulate the FR11 Engine if it will work with our requirements? Now I need to know if it possible to only recognize a specific region of a PDF document? I have the coordinates for the region.

Someone has asked a similar question at http://forum.ocrsdk.com/questions/1498/fr10-engine-how-to-only-recognize-specified-region-of-the-image, but that applies for images and c#. I need to know if it works with PDF documents as well and for C++.

My attempts to port the answer to C++ for the above question has failed so possible solutions are welcomed. I have tried to incorporate the changes in the Hello sample provided with FR11 Enginge.

TIA Johan

  • Liked by
  • sashoalm
Natalia Karaseva posted this 05 September 2014

Hi Johan,

Hope the code snippet below will help you.

C++ sample:

// Add image file to document
frDocument->AddImageFile( imagePath, 0, 0 );

// Remove all the blocks from the collection
FREngine::IFRPagesPtr frPages;
frDocument->get_Pages( &frPages );
// Select the first page of your input pdf document
FREngine::IFRPagePtr frPage = frPages->Item( 0 ); 
FREngine::ILayoutPtr layout;
frPage->get_Layout( &layout );
FREngine::ILayoutBlocksPtr  blocks;
layout->get_Blocks( &blocks );

// Create region and specify its coordinates
FREngine::IRegionPtr region = Engine->CreateRegion();
region->AddRect( Left, Top, Right, Bottom );

// Add blocks of required type to the layout
FREngine::IBlockPtr block = blocks->AddNew( FREngine::BT_Text, region, 0 );

// Set the required parameters of the block
FREngine::IRecognizerParamsPtr recognizerParams = Engine->CreateRecognizerParams();
recognizerParams->SetPredefinedTextLanguage( L"English" );
FREngine::ITextBlockPtr textBlock = block->GetAsTextBlock();
textBlock->put_RecognizerParams( recognizerParams );

//Recognize document
frDocument->Recognize( 0, 0 );