GdPicture.NET.14
GdPicture14 Namespace / GdPictureOCR Class / RunOCR Method / RunOCR(String) Method
A unique result identifier of the executed OCR process, that is used to identify the OCR result. You can define your preferable value. If you leave this parameter null or empty, a new identifier is automatically generated.
Example





In This Topic
RunOCR(String) Method
In This Topic
Runs the OCR on the image previously set by the SetImage method and using the available parameters you have previously specified within the current GdPictureOCR object. You are allowed to set the custom result identifier you prefer using this method. The result of this process, identifiable by this custom ID, is internally attached to the current GdPictureOCR object as well.

Please note, that the accuracy and the speed depend on the selected OCR mode (balance between speed and accuracy).

Syntax
'Declaration
 
Public Overloads Function RunOCR( _
   ByVal OCRResultID As String _
) As String
public string RunOCR( 
   string OCRResultID
)
public function RunOCR( 
    OCRResultID: String
): String; 
public function RunOCR( 
   OCRResultID : String
) : String;
public: string* RunOCR( 
   string* OCRResultID
) 
public:
String^ RunOCR( 
   String^ OCRResultID
) 

Parameters

OCRResultID
A unique result identifier of the executed OCR process, that is used to identify the OCR result. You can define your preferable value. If you leave this parameter null or empty, a new identifier is automatically generated.

Return Value

A unique result identifier of the executed OCR process. If the method has been successfully followed, then the custom identifier passed as a parameter is returned, if it is properly defined.

Please always use the GetStat method to determine if this method has been successful.

Remarks
It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any.

Please ensure that you have set all required parameters, first of all the image, before you start the new OCR process. This method uses the GdPictureImage object previously set by the SetImage method. Setting up an image is a mandatory step before running any OCR process.

Also be aware, that you can only reuse the result ID if you first release it using the ReleaseOCRResult method before the next use. Releasing already used OCR results can improve the memory management if you run more OCR processes in a row.

Example
How to use the custom result identifier when running the OCR.
Dim caption As String = "Example: RunOCR"
Using gdpictureOCR As GdPictureOCR = New GdPictureOCR()
    'Set up your prefered parameters for OCR.
    gdpictureOCR.ResourcesFolder = "\GdPicture.Net 14\redist\OCR"
    If gdpictureOCR.AddLanguage(OCRLanguage.English) = GdPictureStatus.OK Then
        'Set up the image you want to process.
        Dim gdpictureImaging As GdPictureImaging = New GdPictureImaging()
        'The standard open file dialog displays to allow you to select the file.
        Dim image As Integer = gdpictureImaging.CreateGdPictureImageFromFile("")
        If (gdpictureImaging.GetStat() = GdPictureStatus.OK) AndAlso
           (gdpictureOCR.SetImage(image) = GdPictureStatus.OK) Then
            'Define the custom result identifier.
            Dim resID As String = "MyResult"
            'Run the first OCR process.
            'Note that gdpictureOCR.OCRMode = OCRMode.FavorSpeed by default.
            gdpictureOCR.RunOCR(resID)
            If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
                'Save the result.
                If gdpictureOCR.SaveAsText(resID, "OCR_result1.txt", OCROutputTextFormat.Utf16, True) = GdPictureStatus.OK Then
                    MessageBox.Show("The OCR result has been successfully saved.", caption)
                Else
                    MessageBox.Show("The SaveAsText() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("The OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
            End If
 
            'Release the previous OCR result to make your new result identifier unique.
            'This is the only way how to reuse your custom result identifier.
            If gdpictureOCR.ReleaseOCRResult(resID) = GdPictureStatus.OK Then
                'Change OCR settings.
                gdpictureOCR.OCRMode = OCRMode.FavorAccuracy
                'Run the second OCR process.
                gdpictureOCR.RunOCR(resID)
                If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
                    'Save the result.
                    If gdpictureOCR.SaveAsText(resID, "OCR_result2.txt", OCROutputTextFormat.Utf16, True) = GdPictureStatus.OK Then
                        MessageBox.Show("The OCR result has been successfully saved.", caption)
                    Else
                        MessageBox.Show("The SaveAsText() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
                    End If
                Else
                    MessageBox.Show("The OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("The ReleaseOCRResult() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
            End If
 
            'Release the used image.
            gdpictureImaging.ReleaseGdPictureImage(image)
        Else
            MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat().ToString() + " or " + gdpictureOCR.GetStat().ToString(), caption)
        End If
        gdpictureImaging.Dispose()
    Else
        MessageBox.Show("The AddLanguage() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
    End If
    gdpictureOCR.ReleaseOCRResults()
End Using
string caption = "Example: RunOCR";
using (GdPictureOCR gdpictureOCR = new GdPictureOCR())
{
    //Set up your prefered parameters for OCR.
    gdpictureOCR.ResourcesFolder = "\\GdPicture.Net 14\\redist\\OCR";
    if (gdpictureOCR.AddLanguage(OCRLanguage.English) == GdPictureStatus.OK)
    {
        //Set up the image you want to process.
        GdPictureImaging gdpictureImaging = new GdPictureImaging();
        //The standard open file dialog displays to allow you to select the file.
        int image = gdpictureImaging.CreateGdPictureImageFromFile("");
        if ((gdpictureImaging.GetStat() == GdPictureStatus.OK) &&
            (gdpictureOCR.SetImage(image) == GdPictureStatus.OK))
        {
            //Define the custom result identifier.
            string resID = "MyResult";
 
            //Run the first OCR process.
            //Note that gdpictureOCR.OCRMode = OCRMode.FavorSpeed by default.
            gdpictureOCR.RunOCR(resID);
            if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
            {
                //Save the result.
                if (gdpictureOCR.SaveAsText(resID, "OCR_result1.txt", OCROutputTextFormat.Utf16, true) == GdPictureStatus.OK)
                    MessageBox.Show("The OCR result has been successfully saved.", caption);
                else
                    MessageBox.Show("The SaveAsText() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
            }
            else
            {
                MessageBox.Show("The OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
            }
 
            //Release the previous OCR result to make your new result identifier unique.
            //This is the only way how to reuse your custom result identifier.
            if (gdpictureOCR.ReleaseOCRResult(resID) == GdPictureStatus.OK)
            {
                //Change OCR settings.
                gdpictureOCR.OCRMode = OCRMode.FavorAccuracy;
 
                //Run the second OCR process.
                gdpictureOCR.RunOCR(resID);
                if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
                {
                    //Save the result.
                    if (gdpictureOCR.SaveAsText(resID, "OCR_result2.txt", OCROutputTextFormat.Utf16, true) == GdPictureStatus.OK)
                        MessageBox.Show("The OCR result has been successfully saved.", caption);
                    else
                        MessageBox.Show("The SaveAsText() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
                }
                else
                {
                    MessageBox.Show("The OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
                }
            }
            else
                MessageBox.Show("The ReleaseOCRResult() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
            
            //Release the used image.
            gdpictureImaging.ReleaseGdPictureImage(image);
        }
        else
            MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat().ToString() + " or " + gdpictureOCR.GetStat().ToString(), caption);
        gdpictureImaging.Dispose();
    }
    else
        MessageBox.Show("The AddLanguage() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
    gdpictureOCR.ReleaseOCRResults();
}
See Also