Code for recognizing only part of image doesn't work.

  • Last Post 06 October 2014
  • Topic Is Solved
kirill posted this 03 October 2014

Hi, I try to recognize only one region on an image(actually many regions, but I simplified the code sample). Code below tries to remove all blocks from page before processing, adds block with defined coordinates and then performs processing. It writes to console a number of blocks on the first page before and after processing. I expect that after processing it outputs 1, but when I run the code, I get 1 and 22. So why do I get all blocks after processing instead of only one? I hope the question is clear.

var engineLoader = new FREngine.OutprocLoader();

var processControl = (FREngine.IHostProcessControl) engineLoader; processControl.SetClientProcessId(Process.GetCurrentProcess().Id);

var engine = engineLoader.GetEngineObjectEx("SWAT-XXXX-XXXX-XXXX-XXXX-XXXX", null, null, true);

var frDocument = engine.CreateFRDocument(); frDocument.AddImageFile(Environment.CurrentDirectory + @"/Images/Test.jpg");

// Remove all the blocks from the collection
var pages = frDocument.Pages; // Select the first page of your input pdf document var frPage = pages[0]; var layout = frPage.Layout; var blocks = layout.Blocks; blocks.DeleteAll();

var region = engine.CreateRegion();
region.AddRect(1423, 740, 2175, 867);

// Add blocks of required type to the layout var block = blocks.AddNew(BlockTypeEnum.BT_Text, region, 0); var recognizerParams = engine.CreateRecognizerParams(); recognizerParams.SetPredefinedTextLanguage("English");

// Set the required parameters of the block var textBlock = block.GetAsTextBlock(); textBlock.RecognizerParams = recognizerParams;

block.Name = "test";




Thanks in advance, Kirill

Anastasiya Medvedeva posted this 06 October 2014

You are doing practically everything correct, except one moment: IFRDocument::Process method includes Preprocess, Analyze, Recognize and Synthesize methods calls. So in case your intend is to add block or blocks manually you do not need to call after adding blocks Analyze method included into IFRDocument::Process - while automatic analysis your blocks will be deleted.

So all that you need after adding blocks is to call IFRDocument::Recognize method.

  • Liked by
  • kirill