GdPicture.NET.14
GdPicture14 Namespace / GdPictureOCR Class / ReleaseOCRResults Method
Example





In This Topic
ReleaseOCRResults Method (GdPictureOCR)
In This Topic
Releases all results of all previously executed OCR processes within the current GdPictureOCR object. Each OCR result is internally attached to that GdPictureOCR object, which has executed the OCR process. By disposing of the current GdPictureOCR object you also release all attached OCR results.
Syntax
'Declaration
 
Public Function ReleaseOCRResults() As GdPictureStatus
public GdPictureStatus ReleaseOCRResults()
public function ReleaseOCRResults(): GdPictureStatus; 
public function ReleaseOCRResults() : GdPictureStatus;
public: GdPictureStatus ReleaseOCRResults(); 
public:
GdPictureStatus ReleaseOCRResults(); 

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

We strongly recommend always checking this status first.

Remarks
Please be aware, that each OCR result is internally linked to the GdPictureOCR object, that has executed the OCR process.
Example
How to release already used OCR results to improve memory management.
Dim caption As String = "Example: ReleaseOCRResults"
    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.TiffCreateMultiPageFromFile("")
            If gdpictureImaging.GetStat() = GdPictureStatus.OK Then
                'This example expects that the input tiff file has 2 pages.
                If gdpictureImaging.TiffGetPageCount(image) <> 2 Then
                    MessageBox.Show("This example expects 2 pages tiff files.", caption)
                    Goto [Error]
                End If
 
                'Select the first page.
                If gdpictureImaging.TiffSelectPage(image, 1) <> GdPictureStatus.OK Then
                    MessageBox.Show("The TiffSelectPage() method has failed with the status: " + gdpictureImaging.GetStat().ToString(), caption)
                    Goto [Error]
                 End If
 
                'Set the image.
                gdpictureOCR.SetImage(image)
                If gdpictureOCR.GetStat() <> GdPictureStatus.OK Then
                    MessageBox.Show("The SetImage() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
                    GoTo [error]
                End If
            
                'Define the required ROI.
                gdpictureOCR.SetROI(100, 100, 200, 50)
                'Define the character set for phone numbers.
                gdpictureOCR.CharacterSet = "0123456789"
                
                'Run the OCR process.
                gdpictureOCR.RunOCR("PhoneNumberRegion")
                If gdpictureOCR.GetStat() <> GdPictureStatus.OK Then
                    MessageBox.Show("The OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
                    Goto [Error]
                End If
 
                'Reset the required ROI.
                gdpictureOCR.SetROI(150, 300, 200, 200)
                'Define the character set for addresses.
                gdpictureOCR.CharacterSet = ""
                gdpictureOCR.Context = OCRContext.OCRContextSingleBlock
                
                'Run the OCR process.
                gdpictureOCR.RunOCR("AddressRegion")
                If gdpictureOCR.GetStat() <> GdPictureStatus.OK Then
                    MessageBox.Show("The OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
                    Goto [Error]
                End If
 
                'Analyze your OCR results using the identifiers "PhoneNumberRegion" And "AddressRegion".
                'Continue ...
 
                'Prepare GdPictureOCR for the next process.
 
                'Release unused results for better memory management.
                gdpictureOCR.ReleaseOCRResults()
                'Reset region of interest to the whole page.
                gdpictureOCR.ResetROI()
                gdpictureOCR.Context = OCRContext.OCRContextDocument
 
                'Select the second page.
                If gdpictureImaging.TiffSelectPage(image, 2) <> GdPictureStatus.OK Then
                    MessageBox.Show("The TiffSelectPage() method has failed with the status: " + gdpictureImaging.GetStat().ToString(), caption)
                    Goto [Error]
                End If
 
                'Set another image.
                gdpictureOCR.SetImage(image)
                If gdpictureOCR.GetStat() <> GdPictureStatus.OK Then
                    MessageBox.Show("The SetImage() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
                    GoTo [error]
                End If
            
                'Run the OCR process.
                Dim pageText As String = gdpictureOCR.RunOCR()
                If gdpictureOCR.GetStat() <> GdPictureStatus.OK Then
                    MessageBox.Show("The OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
                    Goto [Error]
                End If
 
                Dim text As String = gdpictureOCR.GetOCRResultText(pageText)
                If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
                    MessageBox.Show("The text on the page is : " + vbCrLf + text, caption)
                Else
                    MessageBox.Show("The GetOCRResultText() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
                End If
 
[error]:
                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: ReleaseOCRResults";
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.TiffCreateMultiPageFromFile("");
        if (gdpictureImaging.GetStat() == GdPictureStatus.OK)
        {
            //This example expects that the input tiff file has 2 pages.
            if (gdpictureImaging.TiffGetPageCount(image) != 2)
            {
                MessageBox.Show("This example expects 2 pages tiff files.", caption);
                goto error;
            }
 
            //Select the first page.
            if (gdpictureImaging.TiffSelectPage(image, 1) != GdPictureStatus.OK)
            {
                MessageBox.Show("The TiffSelectPage() method has failed with the status: " + gdpictureImaging.GetStat().ToString(), caption);
                goto error;
            }
            
            //Set the image.
            gdpictureOCR.SetImage(image);
            if (gdpictureOCR.GetStat() != GdPictureStatus.OK)
            {
                MessageBox.Show("The SetImage() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
                goto error;
            }
 
            //Define the required ROI.
            gdpictureOCR.SetROI(100, 100, 200, 50);
            //Define the character set for phone numbers.
            gdpictureOCR.CharacterSet = "0123456789";
 
            //Run the OCR process.
            gdpictureOCR.RunOCR("PhoneNumberRegion");
            if (gdpictureOCR.GetStat() != GdPictureStatus.OK)
            {
                MessageBox.Show("The OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
                goto error;
            }
 
            //Reset the required ROI.
            gdpictureOCR.SetROI(150, 300, 200, 200);
            //Define the character set for addresses.
            gdpictureOCR.CharacterSet = "";
            gdpictureOCR.Context = OCRContext.OCRContextSingleBlock;
 
            //Run the OCR process.
            gdpictureOCR.RunOCR("AddressRegion");
            if (gdpictureOCR.GetStat() != GdPictureStatus.OK)
            {
                MessageBox.Show("The OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
                goto error;
            }
 
            //Analyze your OCR results using the identifiers "PhoneNumberRegion" and "AddressRegion".
            //Continue ...
 
            //Prepare GdPictureOCR for the next process.
 
            //Release unused results for better memory management.
            gdpictureOCR.ReleaseOCRResults();
 
            //Reset region of interest to the whole page.
            gdpictureOCR.ResetROI();
            gdpictureOCR.Context = OCRContext.OCRContextDocument;
 
            //Select the second page.
            if (gdpictureImaging.TiffSelectPage(image, 2) != GdPictureStatus.OK)
            {
                MessageBox.Show("The TiffSelectPage() method has failed with the status: " + gdpictureImaging.GetStat().ToString(), caption);
                goto error;
            }
            
            //Set another image.
            gdpictureOCR.SetImage(image);
            if (gdpictureOCR.GetStat() != GdPictureStatus.OK)
            {
                MessageBox.Show("The SetImage() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
                goto error;
            }
 
            //Run the OCR process.
            string pageText = gdpictureOCR.RunOCR();
            if (gdpictureOCR.GetStat() != GdPictureStatus.OK)
            {
                MessageBox.Show("The OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
                goto error;
            }
            string text = gdpictureOCR.GetOCRResultText(pageText);
            if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
            {
                MessageBox.Show("The text on the page is : \n" + text, caption);
            }
            else
            {
                MessageBox.Show("The GetOCRResultText() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
            }
 
        error:
            //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