How to only recognize specified region of the image in JAVA?

  • 97 Views
  • Last Post 20 February 2018
  • Topic Is Solved
Barry Choi posted this 14 February 2018

Hi,

I'm trying to define a region to be recognized using the Hello sample and the C# version in https://forum.ocrsdk.com/thread/1498-fr10-engine-how-to-only-recognize-specified-region-of-the-image/

------------------------------------------

// // Remove all the blocks from the collection

document.Pages[0].Layout.Blocks.RemoveAll();

// // Create region and specify its coordinates

IRegion region = engine.CreateRegion(); 

region.AddRect(0, 100, 500, 125); // Left,Top,Right,Bottom

// // Add blocks of required type to the layout

document.Pages[0].Layout.AddBlock(IBlock.IBlockTypeEnum.BT_Text, region);

------------------------------------------

However, I'm getting errors for the Pages and IBlockEnum symbols, as follows:

Hello.java:172: error: cannot find symbol

document.Pages[0].Layout.Blocks.RemoveAll();

        ^

  symbol:   variable Pages

  location: variable document of type IFRDocument

Hello.java:179: error: cannot find symbol

document.Pages[0].Layout.AddBlock(IBlock.IBlockTypeEnum.BT_Text, region);

                                        ^

  symbol:   variable IBlockTypeEnum

  location: class IBlock

Hello.java:179: error: cannot find symbol

document.Pages[0].Layout.AddBlock(IBlock.IBlockTypeEnum.BT_Text, region);

        ^

  symbol:   variable Pages

  location: variable document of type IFRDocument

3 errors

------------------------------------------

May I know the correct syntax in Java? 

FYI, I'm using FRE11 for Linux (Trial version) and Java 1.8. 

Thanks very much.

Denis Gusak posted this 20 February 2018

Hi!

Java syntax is slightly different from the C# syntax:

document.getPages().getElement(0).getLayout().getBlocks().DeleteAll();
IRegion region = engine.CreateRegion();
region.AddRect(0,100,500,125);
document.getPages().getElement(0).getLayout().getBlocks().AddNew(BlockTypeEnum.BT_Text, region, 0);

Close