Reference Guide
GdPicture14 Namespace / GdPictureOCR Class / SetROI Method
The x-coordinate of the upper-left point of the region of interest, in pixels, measured from the upper-left corner of the image.
The y-coordinate of the upper-left point of the region of interest, in pixels, measured from the upper-left corner of the image.
The width of the region of interest, in pixels.
The height of the region of interest, in pixels.
Example





In This Topic
    SetROI Method (GdPictureOCR)
    In This Topic
    Sets up the new region of interest (ROI) of an image, that is subsequently processed using the OCR. Only the specified region is included into the next OCR process.
    Syntax
    'Declaration
     
    
    Public Function SetROI( _
       ByVal Left As Integer, _
       ByVal Top As Integer, _
       ByVal Width As Integer, _
       ByVal Height As Integer _
    ) As GdPictureStatus
    public GdPictureStatus SetROI( 
       int Left,
       int Top,
       int Width,
       int Height
    )
    public function SetROI( 
        Left: Integer;
        Top: Integer;
        Width: Integer;
        Height: Integer
    ): GdPictureStatus; 
    public function SetROI( 
       Left : int,
       Top : int,
       Width : int,
       Height : int
    ) : GdPictureStatus;
    public: GdPictureStatus SetROI( 
       int Left,
       int Top,
       int Width,
       int Height
    ) 
    public:
    GdPictureStatus SetROI( 
       int Left,
       int Top,
       int Width,
       int Height
    ) 

    Parameters

    Left
    The x-coordinate of the upper-left point of the region of interest, in pixels, measured from the upper-left corner of the image.
    Top
    The y-coordinate of the upper-left point of the region of interest, in pixels, measured from the upper-left corner of the image.
    Width
    The width of the region of interest, in pixels.
    Height
    The height of the region of interest, in pixels.

    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
    The point, that represents the upper-left corner of the image, has the coordinates (0,0).
    Example
    How to set up different regions of interest for different OCR processes.
    Dim caption As String = "Example: SetROI"
        Using oGdPictureOCR As GdPictureOCR = New GdPictureOCR()
            'Set up your prefered parameters for OCR.
            oGdPictureOCR.ResourceFolder = "\GdPicture.Net 14\redist\OCR"
            If oGdPictureOCR.AddLanguage(OCRLanguage.English) = GdPictureStatus.OK Then
                'Set up the image you want to process.
                Dim oGdPictureImage As GdPictureImaging = New GdPictureImaging()
                'The standard open file dialog displays to allow you to select the file.
                Dim image As Integer = oGdPictureImage.CreateGdPictureImageFromFile("")
                If (oGdPictureImage.GetStat() = GdPictureStatus.OK) AndAlso
                   (oGdPictureOCR.SetImage(image) = GdPictureStatus.OK) Then
     
                    'Define the required ROI.
                    oGdPictureOCR.SetROI(100, 100, 200, 50)
                    'Define the character set for phone numbers.
                    oGdPictureOCR.CharacterSet = "0123456789"
                    'Run the OCR process.
                    oGdPictureOCR.RunOCR("PhoneNumberRegion")
                    If oGdPictureOCR.GetStat() <> GdPictureStatus.OK Then
                        MessageBox.Show("The OCR process has failed with the status: " + oGdPictureOCR.GetStat().ToString(), caption)
                        Goto [Error]
                    End If
     
                    'Reset the required ROI.
                    oGdPictureOCR.SetROI(150, 300, 200, 200)
                    'Define the character set for addresses.
                    oGdPictureOCR.CharacterSet = ""
                    oGdPictureOCR.Context = OCRContext.OCRContextSingleBlock
                    'Run the OCR process.
                    oGdPictureOCR.RunOCR("AddressRegion")
                    If oGdPictureOCR.GetStat() <> GdPictureStatus.OK Then
                        MessageBox.Show("The OCR process has failed with the status: " & oGdPictureOCR.GetStat().ToString(), caption)
                        Goto [Error]
                    End If
     
                    'Analyze your OCR results using the identifiers "PhoneNumberRegion" And "AddressRegion".
                    'Continue ...
     
    [error]:
                    oGdPictureImage.ReleaseGdPictureImage(image)
                Else
                    MessageBox.Show("The error occurred when setting up the image: " + oGdPictureImage.GetStat().ToString() + " or " + oGdPictureOCR.GetStat().ToString(), caption)
                End If
                oGdPictureImage.Dispose()
            Else
                MessageBox.Show("The AddLanguage() method has failed with the status: " + oGdPictureOCR.GetStat().ToString(), caption)
            End If
            oGdPictureOCR.ReleaseOCRResults()
        End Using
    string caption = "Example: SetROI";
    using (GdPictureOCR oGdPictureOCR = new GdPictureOCR())
    {
        //Set up your prefered parameters for OCR.
        oGdPictureOCR.ResourceFolder = "\\GdPicture.Net 14\\redist\\OCR";
        if (oGdPictureOCR.AddLanguage(OCRLanguage.English) == GdPictureStatus.OK)
        {
            //Set up the image you want to process.
            GdPictureImaging oGdPictureImage = new GdPictureImaging();
            //The standard open file dialog displays to allow you to select the file.
            int image = oGdPictureImage.CreateGdPictureImageFromFile("");
            if ((oGdPictureImage.GetStat() == GdPictureStatus.OK) &&
                (oGdPictureOCR.SetImage(image) == GdPictureStatus.OK))
            {
                //Define the required ROI.
                oGdPictureOCR.SetROI(100, 100, 200, 50);
                //Define the character set for phone numbers.
                oGdPictureOCR.CharacterSet = "0123456789";
     
                //Run the OCR process.
                oGdPictureOCR.RunOCR("PhoneNumberRegion");
                if (oGdPictureOCR.GetStat() != GdPictureStatus.OK)
                {
                    MessageBox.Show("The OCR process has failed with the status: " + oGdPictureOCR.GetStat().ToString(), caption);
                    goto error;
                }
     
                //Reset the required ROI.
                oGdPictureOCR.SetROI(150, 300, 200, 200);
                //Define the character set for addresses.
                oGdPictureOCR.CharacterSet = "";
                oGdPictureOCR.Context = OCRContext.OCRContextSingleBlock;
     
                //Run the OCR process.
                oGdPictureOCR.RunOCR("AddressRegion");
                if (oGdPictureOCR.GetStat() != GdPictureStatus.OK)
                {
                    MessageBox.Show("The OCR process has failed with the status: " + oGdPictureOCR.GetStat().ToString(), caption);
                    goto error;
                }
     
                //Analyze your OCR results using the identifiers "PhoneNumberRegion" and "AddressRegion".
                //Continue ...
     
            error:
                //Release the used image.
                oGdPictureImage.ReleaseGdPictureImage(image);
            }
            else
                MessageBox.Show("The error occurred when setting up the image: " + oGdPictureImage.GetStat().ToString() + " or " + oGdPictureOCR.GetStat().ToString(), caption);
            oGdPictureImage.Dispose();
        }
        else
            MessageBox.Show("The AddLanguage() method has failed with the status: " + oGdPictureOCR.GetStat().ToString(), caption);
        oGdPictureOCR.ReleaseOCRResults();
    }
    See Also