Recognize Pages (Delphi 6.0)

Take the following steps to add code to the existing project that will let you recognize pages:

1.

Start with the program you created in Working with Zones

2.

Add 2 buttons to your form and name them as follows:

 

Name

Caption

 

btnRecognize

Recognize

 

btnGetStatus

Get Status

3.

Handle the LEADRasterDocument1 OnRecognitionStatus event, and code the LEADRasterDocument1RecognitionStatus procedure as follows:

procedure TForm1.LEADRasterDocument1RecognitionStatus(ASender: TObject; 
  iRecogPage, iError: Smallint); 
begin
 ShowMessage ( 'The page # ' + IntToStr(iRecogPage) + 'is finished its recognition' + Chr(13) +
           'The recognition return code = ' + IntToStr(iError) ); 
   //continue to recognize next page'
   LEADRasterDocument1.EnableStopRecognizeStatus:= False; 
end;

4.

Code the btnRecognize button's click procedure as follows:

procedure TForm1.btnRecognizeClick(Sender: TObject); 
var
 nRet: Integer; 
begin
   LEADRasterDocument1.SpellLanguageID:= LANGID_ENGLISH; 
   LEADRasterDocument1.EnableSubSystem:= True; 
   LEADRasterDocument1.EnableCorrection:= True; 

   LEADRasterDocument1.RecognitionDataFileName:= 'c:\testrdf.rdf'; 

   nRet:= LEADRasterDocument1.Recognize ( 0, 1 ); 
   if ( nRet = 0 ) then
    ShowMessage ( 'The engine finished recognizing the specified pages successfully' ) 
   else
    ShowMessage ( 'Error' + IntToStr(nRet) + 'in recognized specified pages' ); 
end;

5.

Code the btnGetStatus button's click procedure as follows:

procedure TForm1.btnGetStatusClick(Sender: TObject); 
var
 nRet: Integer; 
begin
 nRet:= LEADRasterDocument1.GetStatus ( ); 
 if ( nRet = 0 ) then
   begin
    ShowMessage ( 'Recognition Time = ' + IntToStr(LEADRasterDocument1.RecognizeStatus.RecognizedTime) + Chr(13) +
            'Total Recognized Characters = ' + IntToStr(LEADRasterDocument1.RecognizeStatus.RecognizedCharacterCount) + Chr(13) +
            'Total Recognized Words = ' + IntToStr(LEADRasterDocument1.RecognizeStatus.RecognizedWordCount) + Chr(13) +
            'Total Rejected Characters = ' + IntToStr(LEADRasterDocument1.RecognizeStatus.RejectCharacterCount) + Chr(13) +
            'Total Rejected Words = ' + IntToStr(LEADRasterDocument1.RecognizeStatus.RejectWordCount) ); 
   end; 
end;

6.

Run your program to test it.

7.

Save the project to use as a starting point for other tasks in this tutorial.