Header Header

Examples
[Fingerprint handling]

Table of contents:

fps_finger_capture - Fingerprint example

Finger image capturing and processing example.

The needed gxsdldr.cpp loader file is included directly:

#include "fpsapi.h"
#include "gxsdldr.cpp"

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

#include "../__lib__.h"
Lib lib;

The main function:

#ifdef GX_NAMESPACES
using namespace gx;
using namespace fps;
#endif

int main() {
    try

Opening the Fingerprint Scanner system:

Note:
When the fps variable of the FingerPrintScanner class is instantiated, the Fingerprint Scanner system is opened automaticaly:
    {
        /* Opening the FPS system */
        lib.FunctionStart("Opening system files");
        FingerPrintScanner fps; /* Object for the FPS system */
        lib.FunctionEnd();

Checking if the Fingerprint Scanner modules were opened:

        /* Validity check */
        if (!fps.IsValid())
        {
            lib.Error("Failed to initialize!");
            return 0;
        }

Connecting to the first device. If no device is connected then the UseDevice() function throws an exception:

        /* Connecting to the first device */
        lib.FunctionStart("Connecting to the first device");
        fps.UseDevice(0,FPS_UMODE_FULL_CONTROL);
        lib.FunctionEnd();

The main loop begins:

        while (!lib.KbHit())
        {
            lib.ProcessStart("Processing fingers");

Resetting the internal fingerprint buffer:

            try
            {
                /* Search Finger */
                int reqid, stat, stat0;

                /* Clears internal stored finger buffers */
                fps.ResetFingerList();

Searching for the fingerprints:

                /* Starts an asynchronous capture process
                // params: time in usec, quality in per-thousand, mode of live scan, fingerlist
                //
                // The finger list has the format 0hhh 0000 iiii mmmm rrrr llll tttt ssss
                //  h - scan object: 001 left hand, 010 right hand, 011 same fingers of both hands
                //  i - index finger    |
                //  m - middle finger   |
                //  r - ring finger     |--> value of PR_FINGER_PRESENCE
                //  l - little finger   |
                //  t - left thumb      |
                //  s - right thumb     |
                */
                reqid = fps.CaptureStart(10000, 700, FPS_SCAN_LIVE, 0x10333300);

                for (stat = stat0 = 0; stat < 100; stat0 = stat)
                {
                    /* Test if better images are captured or capture has accomplished */
                    stat = fps.CaptureStatus(reqid);
                    if (stat0 != stat) lib.WriteLine("stat: " + lib.itos(stat));

                    lib.Wait(100);
                }

                /* Closing the capture sequence */
                fps.CaptureWait(reqid);

Saving the fingerprint images:

                /* Save individual finger images */
                fps.SaveImage(0, FPS_POS_LEFT_INDEX, FPS_IT_FINGER, "1index.bmp", GX_BMP);
                fps.SaveImage(0, FPS_POS_LEFT_MIDDLE, FPS_IT_FINGER, "2middle.bmp", GX_BMP);
                fps.SaveImage(0, FPS_POS_LEFT_RING, FPS_IT_FINGER, "3ring.bmp", GX_BMP);
                fps.SaveImage(0, FPS_POS_LEFT_LITTLE, FPS_IT_FINGER, "4little.bmp", GX_BMP);

Exporting the result into a nist file:

                /* This section modifies the values of nist record */

                gxVariant v;
                gxVariant v1;
                gxVariant v2;

                v.CreateEmptyList(0);   /* General list */

                    v1.CreateEmptyList(1);      /* List for storing the type-1 record data */
                    v.AddItem(GX_VARIANT_LAST, 0, 0, v1);

                        v2.Create(4, "ATP");    /* (field id) - (field value) */
                        v1.AddItem(GX_VARIANT_LAST, 0, 0, v2);

                    v1.CreateEmptyList(2);      /* List for storing the type-2 record data */
                    v.AddItem(GX_VARIANT_LAST, 0, 0, v1);

                        v2.Create(45, "Test message");
                        v1.AddItem(GX_VARIANT_LAST, 0, 0, v2);

                        v2.Create(39, "Other text");
                        v1.AddItem(GX_VARIANT_LAST, 0, 0, v2);

                /* Saves all the captured fingers */
                fps.FingerToNist("mynist.nist", &v);

Exception handling section:

            }
            catch (gxException e)
            {
                lib.DisplExcp(e);
            }
The main loop ends:
            lib.ProcessEnd();
            lib.WaitForSec(3);
        }

Closing the device:

        /* Closing device */
        lib.FunctionStart("Closing device");
        fps.CloseDevice();
        lib.FunctionEnd();

Exception handling section, catching the exception and displaying the error code and error message:

    }
    catch (gxException e)
    {
        lib.DisplExcp(e);
    }

The sample program ends printing some statistic information:

    return lib.PrintStat();
}

The complete source code:

#include "fpsapi.h"
#include "gxsdldr.cpp"

#include "../__lib__.h"
Lib lib;

#ifdef GX_NAMESPACES
using namespace gx;
using namespace fps;
#endif

int main() {
    try
    {
        /* Opening the FPS system */
        lib.FunctionStart("Opening system files");
        FingerPrintScanner fps; /* Object for the FPS system */
        lib.FunctionEnd();

        /* Validity check */
        if (!fps.IsValid())
        {
            lib.Error("Failed to initialize!");
            return 0;
        }

        /* Connecting to the first device */
        lib.FunctionStart("Connecting to the first device");
        fps.UseDevice(0,FPS_UMODE_FULL_CONTROL);
        lib.FunctionEnd();

        while (!lib.KbHit())
        {
            lib.ProcessStart("Processing fingers");

            try
            {
                /* Search Finger */
                int reqid, stat, stat0;

                /* Clears internal stored finger buffers */
                fps.ResetFingerList();

                /* Starts an asynchronous capture process
                // params: time in usec, quality in per-thousand, mode of live scan, fingerlist
                //
                // The finger list has the format 0hhh 0000 iiii mmmm rrrr llll tttt ssss
                //  h - scan object: 001 left hand, 010 right hand, 011 same fingers of both hands
                //  i - index finger    |
                //  m - middle finger   |
                //  r - ring finger     |--> value of PR_FINGER_PRESENCE
                //  l - little finger   |
                //  t - left thumb      |
                //  s - right thumb     |
                */
                reqid = fps.CaptureStart(10000, 700, FPS_SCAN_LIVE, 0x10333300);

                for (stat = stat0 = 0; stat < 100; stat0 = stat)
                {
                    /* Test if better images are captured or capture has accomplished */
                    stat = fps.CaptureStatus(reqid);
                    if (stat0 != stat) lib.WriteLine("stat: " + lib.itos(stat));

                    lib.Wait(100);
                }

                /* Closing the capture sequence */
                fps.CaptureWait(reqid);

                /* Save individual finger images */
                fps.SaveImage(0, FPS_POS_LEFT_INDEX, FPS_IT_FINGER, "1index.bmp", GX_BMP);
                fps.SaveImage(0, FPS_POS_LEFT_MIDDLE, FPS_IT_FINGER, "2middle.bmp", GX_BMP);
                fps.SaveImage(0, FPS_POS_LEFT_RING, FPS_IT_FINGER, "3ring.bmp", GX_BMP);
                fps.SaveImage(0, FPS_POS_LEFT_LITTLE, FPS_IT_FINGER, "4little.bmp", GX_BMP);

                /* This section modifies the values of nist record */

                gxVariant v;
                gxVariant v1;
                gxVariant v2;

                v.CreateEmptyList(0);   /* General list */

                    v1.CreateEmptyList(1);      /* List for storing the type-1 record data */
                    v.AddItem(GX_VARIANT_LAST, 0, 0, v1);

                        v2.Create(4, "ATP");    /* (field id) - (field value) */
                        v1.AddItem(GX_VARIANT_LAST, 0, 0, v2);

                    v1.CreateEmptyList(2);      /* List for storing the type-2 record data */
                    v.AddItem(GX_VARIANT_LAST, 0, 0, v1);

                        v2.Create(45, "Test message");
                        v1.AddItem(GX_VARIANT_LAST, 0, 0, v2);

                        v2.Create(39, "Other text");
                        v1.AddItem(GX_VARIANT_LAST, 0, 0, v2);

                /* Saves all the captured fingers */
                fps.FingerToNist("mynist.nist", &v);
            }
            catch (gxException e)
            {
                lib.DisplExcp(e);
            }

            lib.ProcessEnd();
            lib.WaitForSec(3);
        }

        /* Closing device */
        lib.FunctionStart("Closing device");
        fps.CloseDevice();
        lib.FunctionEnd();
    }
    catch (gxException e)
    {
        lib.DisplExcp(e);
    }
    return lib.PrintStat();
}


Generated  for Fingerprint Scanner
(c) ARH Inc.