OCR - Unhandled Exception - SetROI RunOCR

Discussions about machine vision support in GdPicture.
Post Reply
evandyke
Posts: 2
Joined: Mon Sep 27, 2021 4:24 pm

OCR - Unhandled Exception - SetROI RunOCR

Post by evandyke » Mon Sep 27, 2021 9:31 pm

Hi,


I am encountering issues on some documents when trying to OCR specific regions of a document. For any one byte array, I am trying to OCR two different regions (Region a, Region b) with one OCR context to get relevant information. On some documents, after a successful OCR of region a, when I try to OCR region b the application crashes on the RunOCR method. I am checking the status of the SetROI method and it shows as ok, and I wrap it in a try/catch but I'm still unable to catch the exception. The exception is unhandled and it appears to be in the tesseract dll.

Interestingly, if I swap the order and check region b first, then region a....it works fine. It also works fine if I separate out the OCR into different methods with unique OCR contexts.


The error is in the PC Event Viewer and it shows the faulting module as the tesseract dll.

GDPicture version: 14.1.130

The error:
Faulting application name: JDIS.exe, version: 19.1.1.8, time stamp: 0x61437fe5
Faulting module name: GdPicture.NET.14.ocr.tesseract.3.64.dll, version: 2.0.0.66, time stamp: 0x611fa78a
Exception code: 0xc0000409
Fault offset: 0x00000000002a7e55
Faulting process id: 0x1f44
Faulting application start time: 0x01d7abdcffa0ee93
Faulting application path: FullPathRemovedForTicket\bin\Debug\JDIS.exe
Faulting module path: FullPathRemovedForTicket\bin\Debug\GdPicture.NET.14.ocr.tesseract.3.64.dll
Report Id: 72bf44a8-b384-4e08-aa3d-9c17fed9a58a
Faulting package full name:
Faulting package-relative application ID:


Sample Code:

Code: Select all

 Private Sub OCRDocument(ByRef image As Byte())
        Try
            Dim formNumber As String = ""
            Dim oGdPictureOCR As GdPictureOCR = New GdPictureOCR()
            Dim oGdPictureImaging As New GdPictureImaging()
            Dim imageId As Integer = oGdPictureImaging.CreateGdPictureImageFromByteArray(image)
            If oGdPictureImaging.GetStat() <> GdPictureStatus.OK Then
                Throw New Exception("OCR Failed to create GDPictureImage. STAT: " + oGdPictureImaging.GetStat().ToString())
            End If

            Dim imageWidth = oGdPictureImaging.GetWidth(imageId)
            Dim imageHeight = oGdPictureImaging.GetHeight(imageId)
            Dim eighthHeight As Integer = imageHeight / 8
            Dim halfWidth As Integer = imageWidth / 2

            Dim caseIdLeftPoint As Integer = halfWidth
            Dim caseIdTopPoint As Integer = 10
            Dim caseIdWidthArea As Integer = halfWidth - 5
            Dim caseIdHeightArea As Integer = eighthHeight

            Dim formLeftPoint As Integer = 0
            Dim formTopPoint As Integer = imageHeight - eighthHeight
            Dim formwidthArea As Integer = halfWidth
            Dim formheightArea As Integer = eighthHeight

            oGdPictureOCR.Context = OCRContext.OCRContextDocument
            oGdPictureOCR.OCRMode = OCRMode.FavorAccuracy

            oGdPictureOCR.ResourceFolder = System.AppDomain.CurrentDomain.BaseDirectory.ToString()
            Dim formIdcontent As String = Nothing
            Dim gdPicStatus As GdPictureStatus = oGdPictureOCR.AddLanguage(OCRLanguage.English)
            If gdPicStatus = GdPictureStatus.OK Then
                If oGdPictureOCR.SetImage(imageId) = GdPictureStatus.OK Then
                    'REGION A
                    oGdPictureOCR.SetROI(caseIdLeftPoint, caseIdTopPoint, caseIdWidthArea, caseIdHeightArea)
                    Dim caseIdOcrId As String = oGdPictureOCR.RunOCR("caseNumber")
                    Dim caseIdStatus As GdPictureStatus = oGdPictureOCR.GetStat()
                    If caseIdStatus <> GdPictureStatus.OK Then
                        Throw New Exception("OCR problem with oGdPictureOCR.RunOCR for case ID. STAT: " + oGdPictureOCR.GetStat().ToString())
                    End If

                    'REGION B
                    Dim formIdOcrSetROIStatus As GdPictureStatus = oGdPictureOCR.SetROI(formLeftPoint, formTopPoint, formwidthArea, formheightArea)
                    If formIdOcrSetROIStatus <> GdPictureStatus.OK Then
                        Throw New Exception("OCR problem with oGdPictureOCR.SetROI for form number. STAT: " + oGdPictureOCR.GetStat().ToString())
                    End If
                    Dim formOcrId As String = ""
                    Try
                        'UNHANDLED EXCEPTION HAPPENS HERE ON SOME DOCUMENTS
                        formOcrId = oGdPictureOCR.RunOCR("formId")
                    Catch ex As Exception
                        Throw New Exception("OCR problem with oGdPictureOCR.RunOCR for form number. STAT: " + oGdPictureOCR.GetStat().ToString())
                    End Try
                    Dim formIdOcrStatus As GdPictureStatus = oGdPictureOCR.GetStat()
                    If formIdOcrStatus <> GdPictureStatus.OK Then
                        Throw New Exception("OCR problem with oGdPictureOCR.RunOCR for form number. STAT: " + oGdPictureOCR.GetStat().ToString())
                    End If
                    formIdcontent = oGdPictureOCR.GetOCRResultText(formOcrId)
                Else
                    Throw New Exception("OCR problem with oGdPictureOCR.SetImage. STAT: " + oGdPictureOCR.GetStat().ToString())
                End If
            Else
                Throw New Exception("OCR problem with AddLanguage method gdPicStatus. STAT: " + gdPicStatus.ToString())
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

Thank you for any insight anyone may be able to provide.

Hugo
Posts: 163
Joined: Tue Dec 18, 2018 10:09 am

Re: OCR - Unhandled Exception - SetROI RunOCR

Post by Hugo » Tue Sep 28, 2021 4:35 pm

Hi Evandyke,

Thank you for your feedback.

Could you contact us here please? https://orpalis.zendesk.com/hc/en-us/requests/new
It seems your issue is fairly specific and I am not entirely sure I fully understand your situation right now.

I would appreciate you provide us with a code project showing us the behavior you are getting so we may better understand the situation you are in.

Regards,

evandyke
Posts: 2
Joined: Mon Sep 27, 2021 4:24 pm

Re: OCR - Unhandled Exception - SetROI RunOCR

Post by evandyke » Tue Sep 28, 2021 5:56 pm

Ok, sounds good. I'm going to try and find a sample "problem" image that does not have sensitive data and build a small stand-alone project showcasing the issue. Once I have that together I will submit the request.

Thank you.

Hugo
Posts: 163
Joined: Tue Dec 18, 2018 10:09 am

Re: OCR - Unhandled Exception - SetROI RunOCR

Post by Hugo » Wed Sep 29, 2021 5:12 pm

Evandyke,

Thank you for letting me know. I have replied to you in the ticket you created. We'll continue discussions there and get to the bottom of this.

Regards,

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests