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

  • 33 Views
  • Last Post 5 days ago
  • Topic Is Solved
Barry Choi posted this 2 weeks ago

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 5 days ago

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