Skip to content

DL OCR is not working as expected. #40

@DeepakTechDev

Description

@DeepakTechDev

I was trying to parse the DL with same sample DL attached in the Regula Sample API, and below is the code which I'm trying but seems like the response it not same as what we are expecting, Im expecting the DL OCR data,but while Im console.log, its showing the image releated data such image position and all. and so when I call " window.RegulaDocumentSDK.finalizePackage();" method, its throwing an exception "Bad input" from main.js.

Please guide if I missed something to parse the DL OCR data. (such as DL holder's photo, Full name, expiry date etc.)

import { defineComponents, DocumentReaderService, DocumentReaderProcessor } from './vp-frontend-document-components/main.js';

window.initializeDocumentReader = (dotNetHelper) => {
var license = 'AAEAACy7lfuUgZ4+nGB3cKDov9jgUXtBXdw5S4J/ij8obGK8pQWAY+a/5ecZQhpJTE4K9Gc3x2XJNPYTWgL4lCBAG84O4KErg+kHOr/lgj6IAxGiAlCTW9bc0culWIXkQlY8cktPSvSuapfZAGnv+Cc0WvxCKK9jv8of/itjURn9TtDSpWREl1/5VSqcHDzHh9HhLIqfGypbQ+85tuPJsMMWx45F4EWoGDdTAlUgMolz6zIg5rV1ETnQOH4fI1sYjEMYAoM2S4RU62ZQVTKC0IBqul5qNR9agaeV+6wkv/9ng862gnxY49ssnGUzVPXgBbsc9f74dRJ9OXFZd1nZPGLs0ITkAAAAAAAAEISjO1yGfhuWJkjc7ZTJ5sxdTapKFxett/wiDWbyxll6cocWby2sY7y/Eno8KzXPgrUmkw16D1OnPp8iz2n/+yMTej3vZN9xdqDAnYqM23uwv4v3tBvOE5fXGLsjGGikzA22Tz+lLoHB2gXkiya3jJX0NFoYvORkccaqBmiLlYqDvIbU+WOA/U8MR+XcX5ZrXCYFCN90pTwNyWHhIIeXKtfeqtRi4ZMPFiGU00pv7aX0MRM9+1ZD7R76OVilq9HckkvUSdkFm05Iu9s+V1cifQnkGraMhNiPTce+cBNHwuzv';

// Define the components (camera snapshot or full document reader)
//defineComponents();

// Initialize the DocumentReaderService for full document processing
window.RegulaDocumentSDK = new DocumentReaderService();

// Set up processing parameters (adjust if necessary)
window.RegulaDocumentSDK.recognizerProcessParam = {
    processParam: {
        scenario: 'MrzAndLocate', // Use an appropriate scenario for processing driving license
    },
};

//window.RegulaDocumentSDK.imageProcessParam = {
//  processParam: {
//    scenario: 'MrzAndLocate',
//  },
//};

// Initialize the SDK with your license key
defineComponents().then(() => {
    window.RegulaDocumentSDK.initialize({
        license: license
    }).then(() => {
        console.log('Regula Document SDK initialized successfully.');

        // Listen for document read event (or recognition completed event)
        window.RegulaDocumentSDK.onDocumentRead = function (event) {
            console.log("Document Read Event Triggered:", event);
            alert("Document processed successfully!");

            // Get the OCR result from the event
            const documentData = event.detail; // OCR Result
            console.log("OCR Data:", documentData);

            // Send OCR data to Blazor
            dotNetHelper.invokeMethodAsync('OnDocumentRead', documentData);
        };

        // Optionally, handle processing status changes
        window.RegulaDocumentSDK.onProcessingStatusChange = function (status) {
            console.log("Processing Status Changed:", status);
        };
    }).catch((initError) => {
        console.error('Error initializing Regula Document SDK:', initError);
    });
});

window.RegulaDocumentSDK.onRecognitionCompleted = function (event) {
    console.log('Document processed successfully:', event);

    // Parse the OCR result
    const doc = event.detail; // This is the document OCR result
};


const documentReaderElement = document.querySelector('document-reader');

// Make sure the element is present before adding the listener
if (documentReaderElement) {
    documentReaderElement.addEventListener('document-reader', documentReaderListener);
}

function documentReaderListener(data) {
    console.log(data);
    if (data.detail.action === 'PROCESS_FINISHED') {
        const status = data.detail.data?.status;
        const isFinishStatus = status === 1 || status === 2;

        if (!isFinishStatus || !data.detail.data?.response) return;

        window.RegulaDocumentSDK.finalizePackage();
    }
    if (data.detail?.action === 'CLOSE') {
        const reader = document.querySelector('document-reader');

        if (reader) {
            reader.remove();
        }

        button.style.display = 'block';
    }
}

};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions