Header Header

Examples
[Image handling]

Table of contents:

pr_capture_simple - Simple Capture example

Show how to capture image.

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() {

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. If no device is connected then the pr_usedevicen() function returns false and the program ends:

    /* 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:

    while(!lib_kbhit()) {

        lib_process_start("Processing document");

Capturing images:

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

Saving the white image:

        /* Saving to file */
        lib_function_start("Saving image");
        if (pr_saveimagea(hpr,0,PR_LIGHT_WHITE,PR_IT_ORIGINAL,"white.bmp",GX_BMP))
            lib_function_end();
        else
            lib_displ_err();

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 sample program ends printing some statistic information:

    return lib_print_stat();
}

The complete source code:

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

#include "../__lib__.h"

int main() {

    /* 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;
    }

    while(!lib_kbhit()) {

        lib_process_start("Processing document");

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

        /* Saving to file */
        lib_function_start("Saving image");
        if (pr_saveimagea(hpr,0,PR_LIGHT_WHITE,PR_IT_ORIGINAL,"white.bmp",GX_BMP))
            lib_function_end();
        else
            lib_displ_err();

        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_capture_adv - Advanced Capture example

Show how to capture image using advanced features

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 callback event function. When an event signals, its name is displayed:

void GXAPI evfunc(int event, int param1, int param2, void *uparam)
{
    switch (event) {
        case PR_EV_UVLEDWARMING:
            lib_write_line("<Event> UV tube warming started");
            break;
        case PR_EV_PAGECAPTURED:
            lib_write_line("<Event> Page captured: page = %i, error_code = %i", param1, param2);
            break;
        case PR_EV_IMAGECAPTURED:
            lib_write_line("<Event> Image captured: page = %i, light = %i", param1, param2);
            break;
        case PR_EV_CAPTURESTARTED:
            lib_write_line("<Event> Capture started: page = %i", param1);
            break;
        case PR_EV_NOIMAGEINFO:
            lib_write_line("<Event> No image info: page = %i, light = %i", param1, param2);
            break;
        case PR_EV_DOCFRAMEFOUND:
            lib_write_line("<Event> Document frame found: page = %i", param1);
            break;
        default:
            lib_write_line("<Event> Other event(%i): p1 = %i, p2 = %i", event, param1, param2);
            break;
    }
}

The main function:

int main() {
    char **devlist; /* list of the devices */
    int ndev;   /* number of devices */
    unsigned int pages[1]={0xff};

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;
    }

Get the device list. If no device is found, the program ends.

    /* Getting the device list */
    lib_function_start("Getting the device list");
    if (pr_getdevicelista(hpr,&devlist,&ndev)) {
        lib_function_end();
    } else {
        lib_displ_err();
        gx_closehandle(&hpr);
        return 0;
    }

    if (ndev <= 0) {
        lib_write_line("No device found!");
        return 0;
    } else {
        lib_write_line("%i device(s) found!", ndev);
    }

Connecting to the first device. If no device is connected then the pr_usedevicen() function returns false and the program ends:

    /* Connecting to the first device */
    lib_function_start("Connecting to the first device %s",devlist[0]);
    if (pr_usedevicea(hpr,devlist[0],PR_UMODE_FULL_CONTROL)) {
        lib_function_end();
    } else {
        lib_displ_err();
        gx_closehandle(&hpr);
        return 0;
    }

Warming UV tubes:

    /* Warming UV tubes */
    lib_function_start("Warming UV tubes");
    if (gx_setmodulepropertyinta(hpr,"freerun_mode",PR_FRMODE_UVLEDWARMING)) {
        lib_function_end();
    } else {
        lib_displ_err();
    }

Setting all the lights for the first page:

    /* Setting all the lights for the first page */
    lib_function_start("Setting lights");
    if (pr_setpagelight(hpr,1,pages)) {
        lib_function_end();
    } else {
        lib_displ_err();
    }

Setting the event callback function:

    /* Setting event function */
    lib_function_start("Setting event function");
    if (gx_setmodulepropertyinta(hpr,"event_types",PR_ET_LED|PR_ET_CAPTURE) &&
        pr_seteventfunction(hpr,evfunc,(void*)0)) {
            lib_function_end();
    } else {
        lib_displ_err();
    }

The main loop begins:

    while(!lib_kbhit()) {

        lib_process_start("Processing document");

Capturing images:

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

Saving the original image:

        /* Saving to file */
        lib_function_start("Saving original image");
        if (pr_saveimagea(hpr,0,PR_LIGHT_WHITE,PR_IT_ORIGINAL,"original.jpg",GX_JPEG)) {
            lib_function_end();
        } else {
            lib_displ_err();
        }

Saving the document image:

        lib_function_start("Saving document image");
        if (pr_saveimagea(hpr,0,PR_LIGHT_WHITE,PR_IT_DOCUMENT,"document.jpg",GX_JPEG)) {
            lib_function_end();
        } else {
            lib_displ_err();
        }

The main loop ends:

        lib_process_end();
        lib_wait_for_sec(3);
    }

Turning off the lights:

    /* Turning off the lights */
    lib_function_start("Turning off the lights");
    if (gx_setmodulepropertyinta(hpr,"freerun_mode",PR_FRMODE_NULL)) {
        lib_function_end();
    } else {
        lib_displ_err();
    }

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:

    /* Destroying the devlist array */
    if (!gx_globalfree(devlist)) 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();
    }

The sample program ends printing some statistic information:

    return lib_print_stat();
}

The complete source code:

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

#include "../__lib__.h"

void GXAPI evfunc(int event, int param1, int param2, void *uparam)
{
    switch (event) {
        case PR_EV_UVLEDWARMING:
            lib_write_line("<Event> UV tube warming started");
            break;
        case PR_EV_PAGECAPTURED:
            lib_write_line("<Event> Page captured: page = %i, error_code = %i", param1, param2);
            break;
        case PR_EV_IMAGECAPTURED:
            lib_write_line("<Event> Image captured: page = %i, light = %i", param1, param2);
            break;
        case PR_EV_CAPTURESTARTED:
            lib_write_line("<Event> Capture started: page = %i", param1);
            break;
        case PR_EV_NOIMAGEINFO:
            lib_write_line("<Event> No image info: page = %i, light = %i", param1, param2);
            break;
        case PR_EV_DOCFRAMEFOUND:
            lib_write_line("<Event> Document frame found: page = %i", param1);
            break;
        default:
            lib_write_line("<Event> Other event(%i): p1 = %i, p2 = %i", event, param1, param2);
            break;
    }
}

int main() {
    char **devlist; /* list of the devices */
    int ndev;   /* number of devices */
    unsigned int pages[1]={0xff};

    /* 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;
    }

    /* Getting the device list */
    lib_function_start("Getting the device list");
    if (pr_getdevicelista(hpr,&devlist,&ndev)) {
        lib_function_end();
    } else {
        lib_displ_err();
        gx_closehandle(&hpr);
        return 0;
    }

    if (ndev <= 0) {
        lib_write_line("No device found!");
        return 0;
    } else {
        lib_write_line("%i device(s) found!", ndev);
    }

    /* Connecting to the first device */
    lib_function_start("Connecting to the first device %s",devlist[0]);
    if (pr_usedevicea(hpr,devlist[0],PR_UMODE_FULL_CONTROL)) {
        lib_function_end();
    } else {
        lib_displ_err();
        gx_closehandle(&hpr);
        return 0;
    }

    /* Warming UV tubes */
    lib_function_start("Warming UV tubes");
    if (gx_setmodulepropertyinta(hpr,"freerun_mode",PR_FRMODE_UVLEDWARMING)) {
        lib_function_end();
    } else {
        lib_displ_err();
    }

    /* Setting all the lights for the first page */
    lib_function_start("Setting lights");
    if (pr_setpagelight(hpr,1,pages)) {
        lib_function_end();
    } else {
        lib_displ_err();
    }

    /* Setting event function */
    lib_function_start("Setting event function");
    if (gx_setmodulepropertyinta(hpr,"event_types",PR_ET_LED|PR_ET_CAPTURE) &&
        pr_seteventfunction(hpr,evfunc,(void*)0)) {
            lib_function_end();
    } else {
        lib_displ_err();
    }

    while(!lib_kbhit()) {

        lib_process_start("Processing document");

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

        /* Saving to file */
        lib_function_start("Saving original image");
        if (pr_saveimagea(hpr,0,PR_LIGHT_WHITE,PR_IT_ORIGINAL,"original.jpg",GX_JPEG)) {
            lib_function_end();
        } else {
            lib_displ_err();
        }

        lib_function_start("Saving document image");
        if (pr_saveimagea(hpr,0,PR_LIGHT_WHITE,PR_IT_DOCUMENT,"document.jpg",GX_JPEG)) {
            lib_function_end();
        } else {
            lib_displ_err();
        }

        lib_process_end();
        lib_wait_for_sec(3);
    }

    /* Turning off the lights */
    lib_function_start("Turning off the lights");
    if (gx_setmodulepropertyinta(hpr,"freerun_mode",PR_FRMODE_NULL)) {
        lib_function_end();
    } else {
        lib_displ_err();
    }

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

    /* Destroying the devlist array */
    if (!gx_globalfree(devlist)) 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();
}


Generated  for Passport Reader
(c) ARH Inc.