Return >  Addon.OCR.RecognizeRect

Addon.OCR.RecognizeRect()

Description

Peforms OCR on the given rectangle on a specified image.

Syntax

.Addon.OCR.RecognizeRect(sImageIndex, Left, Top, Right, Bottom, asyncSuccessFunc, asyncFailureFunc);

Parameters

<short> sImageIndex: specifies the index of image in buffer. The index is 0-based.
<int> left: specifies the x-coordinate of the upper-left corner of the rectangle.
<int> top: specifies the y-coordinate of the upper-left corner of the rectangle.
<int> right: specifies the x-coordinate of the lower-right corner of the rectangle.
<int> bottom: specifies the y-coordinate of the lower-right corner of the rectangle.

<OnOCRSuccess function> AsyncSuccessFunc: callback function triggered when OCR is executed successfully. This function can acquire the OCR'd image's index and the OCR result. For details, please refer to result.
<OnOCRFailure function> AsyncFailureFunc: callback function triggered when executing OCR fails.

Please refer to the function prototype OnOCRSuccess or OnOCRFailure.

Return value

bool

true indicates success. false indicates failure.

When false is returned or an exception is thrown, please check the methods result.GetErrorCode and the result.GetErrorString for error information.

Example

function Dynamsoft_OnReady() {
    DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');
    DWObject.RegisterEvent('OnImageAreaSelected', function (sImageIndex, left, top, right, bottom) {
        iIndex = sImageIndex; iLeft = left; iTop = top; iRight = right; iBottom = bottom;
    });
}

function btnOCR_onclick() {
 var filePath = "D:\\OCRResult\\OCResult.pdf";
 var strHTTPServer = location.hostname;
 var CurrentPathName = unescape(location.pathname);
 var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);
 var appPath = "http://" + strHTTPServer + ":" + location.port + CurrentPath;
 
 DWObject.Addon.OCR.DownloadLangData(appPath +"Resources/addon/English.zip", function(){
  DWObject.Addon.OCR.Download(appPath +"Resources/addon/OCR.zip", 
   function () {
    DWObject.Addon.OCR.RecognizeRect(iIndex, iLeft, iTop, iRight, iBottom, 
     function (index, left, top, right, bottom, result) {
      console.log("The OCR'd images index: " + index);
      result.Save(filePath);       
     },        
     function (errorCode, errorString) {alert(errorString);}
    );
   }, 
   function (errorCode, errorString) {alert(errorString); }
  );},
  function (errorCode, errorString) {alert(errorString); }
 );
}

See Also

result.Save
OnImageAreaSelected
Addon.OCR.RecognizeSelectedImages