Header

Examples
[Document handling]

Table of contents:

pr_barcode - Image capturing and barcode reading example

Show how to capture images and to read barcode.

The needed gxsdldr.c loader file is included directly:

The __lib__.h file contains some library functions used only in the sample programs, such as the lib_function_start and lib_function_end functions that implement the simple command line interface and measures the elapsed time between the two function calls.

The main function:

Opening the Passport Reader system:

Connecting to the first device.

The main loop begins:

Capturing images:

Reading barcode:

Check data content:

Displaying the document type:

Searching for the barcode and displaying it:

Saving the barcode image:

Searching for the fields and displaying them:

The main loop ends:

Closing the device:

Closing the Passport Reader system:

The main function ends printing some statistic information:

The complete source code:

pr_getocr - Image capturing and OCR example

Shows how to capture image and to call OCR.

The needed gxsdldr.c loader file is included directly:

#include "prapi.h"
#include "gxsdldr.c"

The __lib__.h file contains some library functions used only in the sample programs, such as the lib_function_start and lib_function_end functions that implement the simple command line interface and measures the elapsed time between the two function calls.

#include "../__lib__.h"

The main function:

int main() {
    gxVARIANT params = NULL;
    gxVARIANT vd = NULL;
    gxVARIANT pdoc = NULL;

Opening the Passport Reader system:

    /* Opening the PR system */
    gxHANDLE hpr;   /* handle for the PR system */
    lib_function_start("Opening system files");
    if (gx_openmodulea(&hpr,"prapi","default")) lib_function_end();
    else {
        lib_displ_err();
        return 0;
    }

Connecting to the first device.

    /* Connecting to the first device */
    lib_function_start("Connecting to the first device");
    if (pr_usedevicen(hpr,0,PR_UMODE_FULL_CONTROL)) {
        lib_function_end();
    } else {
        lib_displ_err();
        gx_closehandle(&hpr);
        return 0;
    }

The main loop begins:

    /* Using the device */
    while(!lib_kbhit()) {
        int r1[8] = {100, 1200, 1900, 1200, 1900, 1400, 100, 1400}; /* x1, y1, x2, y2, x3, y3, x4, y4 */
        int height = 2500;
        int spacewidth = 50;
        int spacetype = 0;
        int justification = 0;
        char font[] = "General";
        int i;
        int len = 100;
        char path[100],text[100]="";

        lib_process_start("OCR reading");

Capturing images:

        /* Capturing images */
        lib_function_start("Capturing images");
        if (!pr_capture(hpr)) {
            lib_displ_err();
        } else {
            lib_function_end();

Calling OCR:

            /* Call OCR */
            lib_function_start("Call OCR");
            gx_createvariant(&params,PRV_OCRPARAMS,GX_VARIANT_LIST,0,0,0);
            for(i = 0;i < 8;i++) r1[i] *= 16;
            gx_createvariantitem(&vd,PRV_IMAGEFRAME,GX_VARIANT_INTARRAY,4,8,&r1,params);
            gx_createvariantitem(&vd,PRV_CHARHEIGHT,GX_VARIANT_INT,4,1,&height,params);
            gx_createvariantitem(&vd,PRV_SPACEWIDTH,GX_VARIANT_INT,4,1,&spacewidth,params);
            gx_createvariantitem(&vd,PRV_SPACETYPE,GX_VARIANT_INT,4,1,&spacetype,params);
            gx_createvariantitem(&vd,PRV_JUSTIFICATION,GX_VARIANT_INT,4,1,&justification,params);
            gx_createvariantitem(&vd,PRV_FONTTYPE,GX_VARIANT_ASCII,strlen(font)+1,1,font,params);

            if (pr_getocr(hpr,0,PR_LIGHT_INFRA,PR_IT_ORIGINAL,&pdoc, params)) {
                lib_function_end();
            } else {
                lib_displ_err();
            }

Check data content:

            if (!pdoc) {
                lib_write_line("No OCR data found!");
            } else {

Reading and displaying OCR data:

                /* Reading and displaying OCR data */
                gx_snprintf(path, sizeof(path), "C,D=%i/L,D=%i/C,D=%i",PRV_OCRROWLIST,PRV_OCRROW,PRV_FIELDVALUE);
                if(gx_convertvariantbypatha(pdoc, path, 0, GX_VARIANT_ASCII, &len, 0, text, len))
                {
#ifdef WIN32
                    CharToOem(text,text);
#endif
                    lib_write_line("OCR \"%s\"",text);

                } else {
                    lib_displ_err();
                }
                gx_disposevariant(&pdoc);
            }
            gx_disposevariant(&params);
        }

The main loop ends:

        lib_process_end();
        lib_wait_for_sec(3);
    }

Closing the device:

    /* Closing the device */
    lib_function_start("Closing the device");
    if (pr_closedevice(hpr)) {
        lib_function_end();
    } else {
        lib_displ_err();
    }

Closing the Passport Reader system:

    /* Closing the PR system */
    lib_function_start("Closing the PR system");
    if (gx_closehandle(&hpr)) {
        lib_function_end();
    } else {
        lib_displ_err();
    }

The main function ends printing some statistic information:

    return lib_print_stat();
}

The complete source code:

#include "prapi.h"
#include "gxsdldr.c"

#include "../__lib__.h"

int main() {
    gxVARIANT params = NULL;
    gxVARIANT vd = NULL;
    gxVARIANT pdoc = NULL;

    /* Opening the PR system */
    gxHANDLE hpr;   /* handle for the PR system */
    lib_function_start("Opening system files");
    if (gx_openmodulea(&hpr,"prapi","default")) lib_function_end();
    else {
        lib_displ_err();
        return 0;
    }

    /* Connecting to the first device */
    lib_function_start("Connecting to the first device");
    if (pr_usedevicen(hpr,0,PR_UMODE_FULL_CONTROL)) {
        lib_function_end();
    } else {
        lib_displ_err();
        gx_closehandle(&hpr);
        return 0;
    }

    /* Using the device */
    while(!lib_kbhit()) {
        int r1[8] = {100, 1200, 1900, 1200, 1900, 1400, 100, 1400}; /* x1, y1, x2, y2, x3, y3, x4, y4 */
        int height = 2500;
        int spacewidth = 50;
        int spacetype = 0;
        int justification = 0;
        char font[] = "General";
        int i;
        int len = 100;
        char path[100],text[100]="";

        lib_process_start("OCR reading");

        /* Capturing images */
        lib_function_start("Capturing images");
        if (!pr_capture(hpr)) {
            lib_displ_err();
        } else {
            lib_function_end();

            /* Call OCR */
            lib_function_start("Call OCR");
            gx_createvariant(&params,PRV_OCRPARAMS,GX_VARIANT_LIST,0,0,0);
            for(i = 0;i < 8;i++) r1[i] *= 16;
            gx_createvariantitem(&vd,PRV_IMAGEFRAME,GX_VARIANT_INTARRAY,4,8,&r1,params);
            gx_createvariantitem(&vd,PRV_CHARHEIGHT,GX_VARIANT_INT,4,1,&height,params);
            gx_createvariantitem(&vd,PRV_SPACEWIDTH,GX_VARIANT_INT,4,1,&spacewidth,params);
            gx_createvariantitem(&vd,PRV_SPACETYPE,GX_VARIANT_INT,4,1,&spacetype,params);
            gx_createvariantitem(&vd,PRV_JUSTIFICATION,GX_VARIANT_INT,4,1,&justification,params);
            gx_createvariantitem(&vd,PRV_FONTTYPE,GX_VARIANT_ASCII,strlen(font)+1,1,font,params);

            if (pr_getocr(hpr,0,PR_LIGHT_INFRA,PR_IT_ORIGINAL,&pdoc, params)) {
                lib_function_end();
            } else {
                lib_displ_err();
            }

            if (!pdoc) {
                lib_write_line("No OCR data found!");
            } else {
                /* Reading and displaying OCR data */
                gx_snprintf(path, sizeof(path), "C,D=%i/L,D=%i/C,D=%i",PRV_OCRROWLIST,PRV_OCRROW,PRV_FIELDVALUE);
                if(gx_convertvariantbypatha(pdoc, path, 0, GX_VARIANT_ASCII, &len, 0, text, len))
                {
#ifdef WIN32
                    CharToOem(text,text);
#endif
                    lib_write_line("OCR \"%s\"",text);

                } else {
                    lib_displ_err();
                }
                gx_disposevariant(&pdoc);
            }
            gx_disposevariant(&params);
        }

        lib_process_end();
        lib_wait_for_sec(3);
    }

    /* Closing the device */
    lib_function_start("Closing the device");
    if (pr_closedevice(hpr)) {
        lib_function_end();
    } else {
        lib_displ_err();
    }

    /* Closing the PR system */
    lib_function_start("Closing the PR system");
    if (gx_closehandle(&hpr)) {
        lib_function_end();
    } else {
        lib_displ_err();
    }

    return lib_print_stat();
}

pr_mrz - Image capturing and MRZ reading example

Shows how to capture image and to read MRZ data.

The needed gxsdldr.c loader file is included directly:

The __lib__.h file contains some library functions used only in the sample programs, such as the lib_function_start and lib_function_end functions that implement the simple command line interface and measures the elapsed time between the two function calls.

The main function:

Opening the Passport Reader system:

Connecting to the first device.

The main loop begins:

Capturing images:

Reading the MRZ data:

Displaying the found data:

The main loop ends:

Closing the device:

Closing the Passport Reader system:

The main function ends printing some statistic information:

The complete source code:

pr_recognize - Image capturing and recognition example

Show how to capture and recognize images.

The needed gxsdldr.c loader file is included directly:

The __lib__.h file contains some library functions used only in the sample programs, such as the lib_function_start and lib_function_end functions that implement the simple command line interface and measures the elapsed time between the two function calls.

The main function:

Opening the Passport Reader system:

Connecting to the first device.

The main loop begins:

Capturing images:

Recognizing the images:

Check data content:

Displaying the document type:

Reading some fixed fields and displaying them

Searching for the fields and displaying them:

The main loop ends:

Closing the device:

Closing the Passport Reader system:

The main function ends printing some statistic information:

The complete source code:


Generated  for Passport Reader
(c) ADAPTIVE RECOGNITION