I'm trying to use flexicapture SDK for verification step. when i'm trying to obtain Recognized word count from IText object it returns 0 (zero). int wordCount = text.getRecognizedWordsCount() ; wordCount is zero here ...

Work flow as below:
    1.Load the engine
    2.create project 
    3.creating and adding images in batch obtained from project ( project.getBatches().AddNew("TestBatch") )
    4.Recognize batch using batch object (batch.Recognize(null, RecognitionModeEnum.RM_ReRecognizeAll,null) ) 
    5. Start verification session 
    6. enable context verification and disable group verification 
    7. Get work set from session 
    8. FOR ALL Work Set: get verification group 
    9. FOR ALL Verification group: get verification object 
    10. FOR each verification object: Get Fields ( under context verification ) 
    11. obtained IField object 
    12. get IFieldValue object from Field object 
    13. Get IText object ( IText text = fieldValue.getAsText()  ) 
    14. get recognized word count ( int wordCount = text.getRecognizedWordsCount() )
                 here i'm getting 0 as result ( wordCount = 0 )

Pls suggest some solution; My main task to get Every fieldValue, for each word or each character we need to confidence level.

import java.io.File; import java.io.IOException; import java.sql.BatchUpdateException;

import com.abbyy.FCEngine.*;

public class VerificationStep {

private static Object verificationWorkSet(Object object) {
    // TODO Auto-generated method stub
    return null;
}

private static void trace( String txt ) 
{
    System.out.println( txt );
}

static private String samplesFolder;
static private String projectFolder;
static private String serialNumber;
static private String dllPath;

static {

    samplesFolder = "C:\\ProgramData\\ABBYY\\SDK\\10\\FlexiCapture Engine\\Samples\\";
    projectFolder = "C:\\Users\\Nitin\\FlexicaptureTest\\flexiverificationtest" ;

    try {

        java.io.FileInputStream file = new java.io.FileInputStream( samplesFolder + "SampleConfig\\SamplesConfig.txt" );

        java.io.BufferedReader reader = new java.io.BufferedReader( new java.io.InputStreamReader( file ) );

        serialNumber = reader.readLine();

        dllPath = reader.readLine();

        file.close();

    } catch( java.io.IOException e ) {
         System.out.println( e.getMessage() );
         e.printStackTrace();
    }
}

public static void main( String[] args ) 
{
    // Load Engine 
    try {
            trace("Loading engine");
            IEngineLoader engineLoader= Engine.CreateEngineOutprocLoader();
            IEngine engine = engineLoader.Load(serialNumber,dllPath);

            try{
                IProject project = engine.OpenProject( projectFolder + "\\flexitest.fcproj" );

                try {
                    IBatch batch = null ; 
                    trace( "Creating Batch..." );
                    IBatches batchs = project.getBatches(); 
                    if (batchs == null || batchs.getCount() == 0){
                        batch = project.getBatches().AddNew("TestBatch");
                    }
                    batch = batchs.getElement(0);
                    assert(batch == null);

                    try{
                        trace("opening batch");
                        batch.Open();

                        trace( "Adding pdfs..." );
                    //  batch.AddImage( projectFolder + "\\test1.jpg" );
                        batch.AddImage(projectFolder + "\\13-2-600MP0053-02012-DR-ME-0004_A_2.pdf");
                        //batch.AddImage(projectFolder + "\\15-2-600MP0053-02012-DR-ME-0006_A_2.pdf");
                        /*batch.AddImage( projectFolder + "\\16-2-600MP0053-02012-DR-ME-0017_A_2.pdf" );
                        batch.AddImage(projectFolder + "\\17-2-600MP0053-02012-DR-ME-0018_A_21.pdf");
                        batch.AddImage( projectFolder + "\\18-2-600MP0053-02012-DR-ME-0019_A_2.pdf" );
                        */
                        /*batch.AddImage(projectFolder + "\\02.tif");

                        batch.AddImage(projectFolder + "\\01.tif");*/
                        //batch.AddImage(projectFolder + "\\03.tif");
                        //batch.AddImage(projectFolder + "\\04.tif");

                        trace( "Reconizing pdfs..." );
                        batch.Recognize(null, RecognitionModeEnum.RM_ReRecognizeAll,null);

                        trace("Creating Verification object");
                        try {   
                            IVerificationSession verificationSession = project.StartVerification(null);

                            try {

                                //enabling context verification
                                verificationSession.getOptions().setVerifyFields(true);

                                //disabling group verification 
                                verificationSession.getOptions().setVerifyBaseSymbols(false);
                                verificationSession.getOptions().setVerifyExtraSymbols(false);

                                try {
                                    trace("Get NextWork Set");
                                    IVerificationWorkSet verificationWorkSet =  verificationSession.NextWorkSet();

                                    if ( verificationWorkSet == null){
                                        trace("first verificationWork set is null");
                                    }else {

                                        //process each work set in Verification session
                                        trace("Processing Work Set");
                                        while ( verificationWorkSet != null ){

                                            try{
                                                trace("Geting Verification group");
                                                //get next group for verification 
                                                IVerificationGroup verificationGroup = verificationWorkSet.NextGroup();

                                                if ( verificationGroup == null ){
                                                    trace("First verification group is null");
                                                }else {
                                                    trace("processing each group of a workset");
                                                    //processing each group of a work set
                                                    while ( verificationGroup!= null){
                                                        int verificationObjectInAGroupCount =  verificationGroup.getCount(); 
                                                        trace("Total number of verification object: " +verificationObjectInAGroupCount);

                                                        for ( int iterator = 0; iterator<verificationObjectInAGroupCount; iterator++){
                                                            trace ( "getting and Processing "+(iterator +1 ) + " verification object of A group");

                                                            //getting verification object 
                                                            IVerificationObject verificationObject = verificationGroup.getElement(iterator);
                                                            if ( verificationObject == null){
                                                                trace("verification object is null");
                                                            }else {
                                                                if ( verificationObject.getType() == VerificationObjectTypeEnum.VOT_Group ) {
                                                                    IGroupVerificationObject groupVerificationObject = verificationObject.AsGroupVerificationObject();

                                                                    if ( groupVerificationObject == null){
                                                                        System.out.println("group verification object is null ");
                                                                    }

                                                                }else if ( verificationObject.getType() == VerificationObjectTypeEnum.VOT_Context) {
                                                                    IContextVerificationObject  contextVerificationObject = verificationObject.AsContextVerificationObject();

                                                                    if ( contextVerificationObject == null){
                                                                        trace("ContextVerification object is null");
                                                                    }else {
                                                                        IField field = contextVerificationObject.getField(); 
                                                                        if ( field == null){
                                                                            trace("field getting null");
                                                                        }else {
                                                                            System.out.println(" field full name: " +field.getFullName() + "\n Name: " +field.getName());

                                                                            IFieldValue fieldValue = field.getValue();
                                                                            if ( fieldValue == null){
                                                                                trace("Field Value is Null");
                                                                                }else {

                                                                                System.out.println("suspicious: " +fieldValue.getIsSuspicious());
                                                                                System.out.println("need valid: " +fieldValue.getIsValid());
                                                                                System.out.println("is verifi: " +fieldValue.getIsVerified());
                                                                                System.out.println("need verifi: " +fieldValue.getNeedsVerification());

                                                                                trace ( "getting text from field value");
                                                                                IText text = fieldValue.getAsText() ; 
                                                                                if ( text == null){
                                                                                    trace("text getting null in field value");
                                                                                }else {

                                                                                    int wordCount = text.getRecognizedWordsCount() ; 
                                                                                    trace("recognized word count: "+wordCount);

                                                                                    //getting words from text 
                                                                                    for ( int wordIndex = 0 ; wordIndex<wordCount; wordIndex++ ){
                                                                                        trace ("processing word number :" +wordIndex);

                                                                                        IRecognizedWordInfo recognizedWordInfo = engine.CreateRecognizedWordInfo()  ;

                                                                                        if ( recognizedWordInfo == null){
                                                                                            trace("Can't create recognizedWordInfo object using engine");
                                                                                        }else {
                                                                                            text.GetRecognizedWord(wordIndex, -1, recognizedWordInfo);

                                                                                            //getting characters from word
                                                                                            for (int characterIndex = 0 ; characterIndex<recognizedWordInfo.getText().length(); characterIndex++ ){
                                                                                                trace("processing character number : " +characterIndex);

                                                                                                IRecognizedCharacterInfo recognizedCharacterInfo = engine.CreateRecognizedCharacterInfo(); 
                                                                                                if ( recognizedCharacterInfo == null) {
                                                                                                    trace("can't create recognizedCharacterInfo object");
                                                                                                }else {
                                                                                                    recognizedWordInfo.GetRecognizedCharacter(characterIndex, -1, recognizedCharacterInfo);

                                                                                                    System.out.println(" Character: " + recognizedCharacterInfo.getCharacter());
                                                                                                    System.out.println(" Confidence level : " +recognizedCharacterInfo.getCharConfidence());
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                                System.out.println(" Field Value : " +fieldValue.getAsString());
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }

                                                        trace("Geting next Verification group");
                                                        verificationGroup = verificationWorkSet.NextGroup();
                                                    }

                                                }

                                            }catch (Exception e){
                                                trace("Exception occured in getting next work group");
                                                e.printStackTrace();
                                            }

                                            trace("Get next worksets");
                                            //get next work set
                                            verificationWorkSet =  verificationSession.NextWorkSet();

                                        }
                                    }

                                }catch (Exception e){
                                    System.out.println("Exception durring getting next Work Set");
                                    e.printStackTrace();
                                }

                            }finally {
                                trace("closing Verification object");
                                verificationSession.Close();
                            }
                        }catch (Exception e){
                            System.out.println("Excepton occured in Creating Verification object");
                            e.printStackTrace();
                        }

                        trace ("Getting Documents");
                        IDocuments documents = batch.getDocuments();

                        trace ("Getting Fields and printing");
                        for ( int j = 0 ; j < documents.getCount(); j++){
                            trace ("Getting documnets:" +(j+1));

                            IDocument document = documents.getElement(j);
                            IDocumentDefinition definition = document.getDocumentDefinition();
                            assert( definition != null );
                            assert( document.getPages().getCount() == 1 );

                            trace( "====================================" );
                            trace( "DocumentType: " + document.getDocumentDefinition().getName() );
                            trace( "====================================" );

                            try {
                                trace("opening document");
                                document.Open(true);
                                IFields fields = document.getSections().Item( 0 ).getChildren();

                                for( int i = 0; i < fields.getCount(); i++ ) {
                                    IField field = fields.getElement( i );
                                    trace( field.getName() + ": " + 
                                                            ( field.getValue() != null ? field.getValue().getAsString() : "." ) );
                                }
                            }finally {
                                trace("closing document");
                                document.Close(true);
                            }
                        }
                    }finally {
                            trace("Closing Batch");
                            batch.Close();
                    }

            }catch (Exception e){
                    System.out.println("Exception in creating Batch");
                    e.printStackTrace();
            }
            finally {
                trace("closing project");

                project.Close();
            }

            }catch (Exception e){
                System.out.println("Exception occured while loading project");
                e.printStackTrace();
            }

    }catch (Exception e) {
            // TODO: handle exception
            System.out.println("Exception occured while loading engine");
            e.printStackTrace();
    }
    finally {
            trace("unloading Engine");
            Engine.Unload();
            DeleteDirectoryOrFileIntializer("C:\\Users\\Nitin\\FlexicaptureTest\\flexiverificationtest\\TestBatch");
            DeleteDirectoryOrFileIntializer("C:\\Users\\Nitin\\FlexicaptureTest\\flexiverificationtest\\BatchTypes");
            DeleteDirectoryOrFileIntializer("C:\\Users\\Nitin\\FlexicaptureTest\\flexiverificationtest\\ProjectIsOpen");
            DeleteDirectoryOrFileIntializer("C:\\Users\\Nitin\\FlexicaptureTest\\flexiverificationtest\\flexitest.fcproj.sync");

        }

}

   public static void DeleteDirectoryOrFileIntializer(String args)
    {

        File directory = new File(args);

        //make sure directory exists
        if(!directory.exists()){

           System.exit(0);

        }else{

           try{

               delete(directory);

           }catch(IOException e){
               e.printStackTrace();
               System.exit(0);
           }
        }

        System.out.println("Deleteing files/Director : " +args+ " successfully Done");
    }

    public static void delete(File file)
        throws IOException{

        if(file.isDirectory()){

            //directory is empty, then delete it
            if(file.list().length==0){

               file.delete();

            }else{

               //list all the directory contents
               String files[] = file.list();

               for (String temp : files) {
                  //construct the file structure
                  File fileDelete = new File(file, temp);

                  //recursive delete
                 delete(fileDelete);
               }

               //check the directory again, if empty then delete it
               if(file.list().length==0){
                 file.delete();
               }
            }

        }else{
            //if file, then delete it
            file.delete();
        }
    }

}

asked 17 Jan '14, 16:07

nits's gravatar image

nits
115

edited 17 Jan '14, 16:10


We have received your letter sent to SDK_Support@abbyy.com and investigate your issue. In order we were able to have a better look on it, can you please send to SDK_Support@abbyy.com additionally your *.fcproj project (with all used templates) and input PDF files.

link

answered 17 Jan '14, 18:26

SDK_support's gravatar image

SDK_support ♦♦
2763

yes sure, sending u a mail, pls check

(20 Jan '14, 09:07) nits
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×22
×18
×5
×4

Asked: 17 Jan '14, 16:07

Seen: 1,571 times

Last updated: 26 Jan '14, 23:14

© 2016 ABBYY. All rights Reserved. www.ABBYY.com | Privacy Policy | Legal