LEADTOOLS WCF OCR (Leadtools.Services.Forms.ServiceContracts assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.30
Recognize(String,String,String,OcrDocumentFormatType) Method
See Also 
Leadtools.Services.Forms.ServiceContracts Namespace > IOcrService Interface > Recognize Method : Recognize(String,String,String,OcrDocumentFormatType) Method



uri
The URI of image.
username
The username who has privileges on the the specified URI. Must be passed as (domain/username).
password
The password for the specified user.
format
The output document format.

The Recognize(String,String,String,OcrDocumentFormatType) Method is available in LEADTOOLS Document and Medical Imaging toolkits.

uri
The URI of image.
username
The username who has privileges on the the specified URI. Must be passed as (domain/username).
password
The password for the specified user.
format
The output document format.
Converts an image to a document in the specified document format.

Syntax

Visual Basic (Declaration) 
<WebGetAttribute()>
<FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=False)>
<OperationContractAttribute(Name="RecognizeImage", Action="RecognizeImage")>
Overloads Function Recognize( _
   ByVal uri As String, _
   ByVal username As String, _
   ByVal password As String, _
   ByVal format As OcrDocumentFormatType _
) As Stream
Visual Basic (Usage)Copy Code
Dim instance As IOcrService
Dim uri As String
Dim username As String
Dim password As String
Dim format As OcrDocumentFormatType
Dim value As Stream
 
value = instance.Recognize(uri, username, password, format)
C# 
[WebGetAttribute()]
[FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=false)]
[OperationContractAttribute(Name="RecognizeImage", Action="RecognizeImage")]
Stream Recognize( 
   string uri,
   string username,
   string password,
   OcrDocumentFormatType format
)
C++/CLI 
[WebGetAttribute()]
[FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=false)]
[OperationContractAttribute(Name="RecognizeImage", Action="RecognizeImage")]
Stream^ Recognize( 
   String^ uri,
   String^ username,
   String^ password,
   OcrDocumentFormatType format
) 

Parameters

uri
The URI of image.
username
The username who has privileges on the the specified URI. Must be passed as (domain/username).
password
The password for the specified user.
format
The output document format.

Return Value

A stream that contains the document data.

Example

This example will convert a TIF file in a sharepoint to text and save it to disk.

Visual BasicCopy Code
Public Sub RecognizeImageExample()
      Dim buffer As Byte() = New Byte(1024 * 64 - 1) {}
      Dim totalBytesRead As Integer = 0
      Dim memoryStream As MemoryStream = New MemoryStream()
      Dim client As OcrServiceClient = New OcrServiceClient()

      Dim stream As Stream = client.RecognizeImage("http://sp2007ep/Ocr/Shared%20Documents/OCR.TIF", "username", "password", OcrDocumentFormatType.TextAnsi)

      Dim bytesRead As Integer
      'TODO: INSTANT VB TODO TASK: Assignments within expressions are not supported in VB.NET
      'ORIGINAL LINE: while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
      Do While (bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0
         totalBytesRead += bytesRead
         memoryStream.Write(buffer, 0, bytesRead)
      Loop

      File.WriteAllBytes(Path.Combine(LEAD_VARS.ImagesDir, "ocr.txt"), memoryStream.ToArray())

      client.Close()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
public void RecognizeImageExample()
   {
      byte[] buffer = new byte[1024 * 64];
      int totalBytesRead = 0;
      MemoryStream memoryStream = new MemoryStream();
      OcrServiceClient client = new OcrServiceClient();

      Stream stream = client.RecognizeImage(@"http://sp2007ep/Ocr/Shared%20Documents/OCR.TIF", "username", "password", OcrDocumentFormatType.TextAnsi);

      int bytesRead;
      while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
      {
         totalBytesRead += bytesRead;
         memoryStream.Write(buffer, 0, bytesRead);
      }

      File.WriteAllBytes(Path.Combine(LEAD_VARS.ImagesDir,"ocr.txt"), memoryStream.ToArray());

      client.Close();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}

Remarks

This method is designed to be used as a WebGet method, so you can access this method using a browser. For example, you can pass the following query string to IE.

"http://Localhost/LeadtoolsServicesHost/OcrService.svc/recognizeimage?uri=\\computername\Ocr1.tif&format=AsciiText&engineType=plus".

This method is supported when hosting is performed using WebHttpBinding.

The LEADTOOLS OCR engines provide support for recognizing document zones in separate threads. This can improve the performance of the recognition process. Control the number of threads through Leadtools.Services.Forms.ServiceImplementations.dll.config by setting the value for MaximumRecognitionThreads to one of the following:

  • A value of 0 (zero) instructs LEADTOOLS to use the maximum number of threads equal to the number of cores available in the current machine.
  • A value of 1, 2, 3, 4, etc. instructs LEADTOOLS to use that maximum number of threads equal to that number.
  • A value of 1 instructs LEADTOOLS not to use multi-threading
  • Leave the value of this property at the default value of 1 in WCF applications.

Also, LEADTOOLS OCR engines provide support for auto-zoning in separate threads. This can improve the performance of the recognition process. Disable and enable this option through Leadtools.Services.Forms.ServiceImplementations.dll.config by setting the value for EnableMultiThreadingZoning to one of the following:

  • use multi-threading when performing auto-zoning
  • don't use multi-threading when performing auto-zoning
  • Leave the value of this property to the default of false in WCF applications.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also

Applications developed with LEADTOOLS WCF components require runtime licenses. Server licensing is required for applications on a server. For more information, refer to: Imaging Pro/Document/Medical Features