|
|
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.
#include "../__lib__.h"
The main function:
int main() { char *ec[]={"Ok","Warning","Error"}; gxVARIANT img; gxIMAGE *gim; 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:
while(!lib_kbhit()) {
int code;
int status;
char path[100], text[3000];
int stext = sizeof(text);
int i, id = PRV_FIELDLIST;
gxVARIANT fieldlist;
lib_process_start("Processing document");
Capturing images:
/* Capturing images */
lib_function_start("Capturing images");
if (!pr_capture(hpr)) {
lib_displ_err();
} else {
lib_function_end();
Reading barcode:
/* Reading barcode */
lib_function_start("Reading barcode from infra image");
if (pr_getbarcode(hpr,0,PR_LIGHT_INFRA,PR_IT_ORIGINAL,0,0,&pdoc))
lib_function_end();
else
lib_displ_err();
if (!pdoc) {
lib_function_start("Reading barcode from white image");
if (pr_getbarcode(hpr,0,PR_LIGHT_WHITE,PR_IT_ORIGINAL,0,0,&pdoc))
lib_function_end();
else
lib_displ_err();
}
Check data content:
if (!pdoc) {
lib_write_line("No data found!");
} else {
Displaying the document type:
/* Displaying document type */ if (pr_getdocumentstatus(hpr, pdoc, &code, &status)) { lib_write_line("Document type: %i, status: %s", code, ec[status/100]); } else { lib_displ_err(); }
Searching for the barcode and displaying it:
/* Searching for the barcode and displaying it */
if (pr_getfieldfromdoca(hpr, pdoc, PR_DF_BC1, text, &stext, &status, 0) ||
pr_getfieldfromdocb(hpr, pdoc, PR_DF_BC1, text, &stext, &status, 0)) {
int type = -1;
int stype = 4;
text[stext] = 0;
/* Get the barcode type */
if(!gx_convertvariantchild(pdoc, PRV_BARCODE, 0, GX_VARIANT_INT, &stype, 0, &type, stype))
lib_displ_err();
/* Converting the data for displaying on console */
#ifdef WIN32
CharToOemBuff(text, text, stext);
#endif
lib_write_line("Barcode type: %i, status: %i, length: %i\ndata:\n%s", type, status, stext, text);
} else {
lib_displ_err();
}
Saving the barcode image:
/* Saving the barcode image */
lib_function_start("Save barcode image");
if(pr_getfieldimage(hpr,pdoc,PR_DF_BC1,0,&img) &&
gx_imagefromvariant(gx_direct(GX_CALL_GROUP_GX_IMAGE), &gim, img) &&
gx_saveimagea(gx_direct(GX_CALL_GROUP_GX_IMAGE), gim, "barcode.jpg", GX_JPEG) &&
gx_unrefimage(gx_direct(GX_CALL_GROUP_GX_IMAGE), gim) &&
gx_disposevariant(&img))
{
lib_function_end();
} else {
lib_displ_err();
}
Searching for the fields and displaying them:
/* Searching for the fields and displaying them */
if(gx_getvariantchild(pdoc,GX_VARIANT_BY_ID, &id, 0, &fieldlist)) {
int nitems = 0;
/* Get the number of recognized fields */
if(gx_getvariant(fieldlist, 0, 0, 0, &nitems, 0)) {
for (i=0; i<nitems; i++) {
int field_code = 0;
int sz = sizeof(int);
int n = 0;
gx_snprintf(path, sizeof(path), "L,X=%d", i);
if(gx_convertvariantbypatha(fieldlist, path, 0, GX_VARIANT_INT, &sz, &n, &field_code, sizeof(field_code))) {
/* Get the field text */
stext = sizeof(text);
if (pr_getfieldfromdoca(hpr,pdoc,field_code,text,&stext,&status,0) ||
pr_getfieldfromdocb(hpr,pdoc,field_code,text,&stext,&status,0)) {
if (*text) {
text[stext] = 0;
/* Converting the data for displaying on console */
#ifdef WIN32
CharToOem(text,text);
#endif
lib_write_line("[%5i] \"%s\" [%s]", field_code, text, ec[status/100]);
} else {
lib_write_line("[%5i] \"Binary or empty data...\" [%s]", field_code, ec[status/100]);
}
} else {
lib_displ_err();
}
} else {
lib_displ_err();
}
}
}
if (!gx_disposevariant(&fieldlist)) lib_displ_err();
}
if (!gx_disposevariant(&pdoc)) 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 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() { char *ec[]={"Ok","Warning","Error"}; gxVARIANT img; gxIMAGE *gim; 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; } while(!lib_kbhit()) { int code; int status; char path[100], text[3000]; int stext = sizeof(text); int i, id = PRV_FIELDLIST; gxVARIANT fieldlist; lib_process_start("Processing document"); /* Capturing images */ lib_function_start("Capturing images"); if (!pr_capture(hpr)) { lib_displ_err(); } else { lib_function_end(); /* Reading barcode */ lib_function_start("Reading barcode from infra image"); if (pr_getbarcode(hpr,0,PR_LIGHT_INFRA,PR_IT_ORIGINAL,0,0,&pdoc)) lib_function_end(); else lib_displ_err(); if (!pdoc) { lib_function_start("Reading barcode from white image"); if (pr_getbarcode(hpr,0,PR_LIGHT_WHITE,PR_IT_ORIGINAL,0,0,&pdoc)) lib_function_end(); else lib_displ_err(); } if (!pdoc) { lib_write_line("No data found!"); } else { /* Displaying document type */ if (pr_getdocumentstatus(hpr, pdoc, &code, &status)) { lib_write_line("Document type: %i, status: %s", code, ec[status/100]); } else { lib_displ_err(); } /* Searching for the barcode and displaying it */ if (pr_getfieldfromdoca(hpr, pdoc, PR_DF_BC1, text, &stext, &status, 0) || pr_getfieldfromdocb(hpr, pdoc, PR_DF_BC1, text, &stext, &status, 0)) { int type = -1; int stype = 4; text[stext] = 0; /* Get the barcode type */ if(!gx_convertvariantchild(pdoc, PRV_BARCODE, 0, GX_VARIANT_INT, &stype, 0, &type, stype)) lib_displ_err(); /* Converting the data for displaying on console */ #ifdef WIN32 CharToOemBuff(text, text, stext); #endif lib_write_line("Barcode type: %i, status: %i, length: %i\ndata:\n%s", type, status, stext, text); } else { lib_displ_err(); } /* Saving the barcode image */ lib_function_start("Save barcode image"); if(pr_getfieldimage(hpr,pdoc,PR_DF_BC1,0,&img) && gx_imagefromvariant(gx_direct(GX_CALL_GROUP_GX_IMAGE), &gim, img) && gx_saveimagea(gx_direct(GX_CALL_GROUP_GX_IMAGE), gim, "barcode.jpg", GX_JPEG) && gx_unrefimage(gx_direct(GX_CALL_GROUP_GX_IMAGE), gim) && gx_disposevariant(&img)) { lib_function_end(); } else { lib_displ_err(); } /* Searching for the fields and displaying them */ if(gx_getvariantchild(pdoc,GX_VARIANT_BY_ID, &id, 0, &fieldlist)) { int nitems = 0; /* Get the number of recognized fields */ if(gx_getvariant(fieldlist, 0, 0, 0, &nitems, 0)) { for (i=0; i<nitems; i++) { int field_code = 0; int sz = sizeof(int); int n = 0; gx_snprintf(path, sizeof(path), "L,X=%d", i); if(gx_convertvariantbypatha(fieldlist, path, 0, GX_VARIANT_INT, &sz, &n, &field_code, sizeof(field_code))) { /* Get the field text */ stext = sizeof(text); if (pr_getfieldfromdoca(hpr,pdoc,field_code,text,&stext,&status,0) || pr_getfieldfromdocb(hpr,pdoc,field_code,text,&stext,&status,0)) { if (*text) { text[stext] = 0; /* Converting the data for displaying on console */ #ifdef WIN32 CharToOem(text,text); #endif lib_write_line("[%5i] \"%s\" [%s]", field_code, text, ec[status/100]); } else { lib_write_line("[%5i] \"Binary or empty data...\" [%s]", field_code, ec[status/100]); } } else { lib_displ_err(); } } else { lib_displ_err(); } } } if (!gx_disposevariant(&fieldlist)) lib_displ_err(); } if (!gx_disposevariant(&pdoc)) 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(); }
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.
#include "../__lib__.h"
The main function:
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(¶ms,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(¶ms); }
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(¶ms,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(¶ms); } 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(); }
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.
#include "../__lib__.h"
The main function:
int main() { gxVARIANT pdoc;
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()) {
char text[100];
int stext;
int status;
char *ec[]={"Ok","Warning","Error"};
lib_process_start("MRZ reading");
Capturing images:
/* Capturing images */
lib_function_start("Capturing images");
if (!pr_capture(hpr)) {
lib_displ_err();
}
else
{
lib_function_end();
Reading the MRZ data:
/* Getting the MRZ data */
lib_function_start("Reading MRZ");
if (pr_getmrz(hpr,0,PR_LIGHT_INFRA,PR_IT_ORIGINAL,&pdoc)) {
lib_function_end();
} else {
lib_displ_err();
}
Displaying the found data:
if (!pdoc) {
lib_write_line("No MRZ data found!");
} else {
/* Searching for MRZ fields and displaying them */
stext = sizeof(text);
if (pr_getfieldfromdoca(hpr, pdoc, PR_DF_MRZ1, text, &stext, &status, 0)) {
if (*text) lib_write_line("MRZ1 \"%s\" [%s]", text, ec[status/100]);
} else {
lib_displ_err();
}
stext = sizeof(text);
if (pr_getfieldfromdoca(hpr, pdoc, PR_DF_MRZ2, text, &stext, &status, 0)) {
if (*text) lib_write_line("MRZ2 \"%s\" [%s]", text, ec[status/100]);
} else {
lib_displ_err();
}
stext = sizeof(text);
if (pr_getfieldfromdoca(hpr, pdoc, PR_DF_MRZ3, text, &stext, &status, 0)) {
if(*text) lib_write_line("MRZ3 \"%s\" [%s]", text, ec[status/100]);
} else {
lib_displ_err();
}
gx_disposevariant(&pdoc);
}
}
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 pdoc; /* 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()) { char text[100]; int stext; int status; char *ec[]={"Ok","Warning","Error"}; lib_process_start("MRZ reading"); /* Capturing images */ lib_function_start("Capturing images"); if (!pr_capture(hpr)) { lib_displ_err(); } else { lib_function_end(); /* Getting the MRZ data */ lib_function_start("Reading MRZ"); if (pr_getmrz(hpr,0,PR_LIGHT_INFRA,PR_IT_ORIGINAL,&pdoc)) { lib_function_end(); } else { lib_displ_err(); } if (!pdoc) { lib_write_line("No MRZ data found!"); } else { /* Searching for MRZ fields and displaying them */ stext = sizeof(text); if (pr_getfieldfromdoca(hpr, pdoc, PR_DF_MRZ1, text, &stext, &status, 0)) { if (*text) lib_write_line("MRZ1 \"%s\" [%s]", text, ec[status/100]); } else { lib_displ_err(); } stext = sizeof(text); if (pr_getfieldfromdoca(hpr, pdoc, PR_DF_MRZ2, text, &stext, &status, 0)) { if (*text) lib_write_line("MRZ2 \"%s\" [%s]", text, ec[status/100]); } else { lib_displ_err(); } stext = sizeof(text); if (pr_getfieldfromdoca(hpr, pdoc, PR_DF_MRZ3, text, &stext, &status, 0)) { if(*text) lib_write_line("MRZ3 \"%s\" [%s]", text, ec[status/100]); } else { lib_displ_err(); } gx_disposevariant(&pdoc); } } 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(); }
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.
#include "../__lib__.h"
The main function:
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:
while(!lib_kbhit()) {
int code;
int status;
int id = PRV_FIELDLIST;
gxVARIANT fieldlist;
int i;
char path[100], text[100];
int stext;
lib_process_start("Processing document");
Capturing images:
/* Capturing images */
lib_function_start("Capturing images");
if (!pr_capture(hpr)) {
lib_displ_err();
} else {
lib_function_end();
Recognizing the images:
/* Getting document data */
lib_function_start("Recognizing.");
if (pr_recognize(hpr,0,&pdoc)) {
lib_function_end();
} else {
lib_displ_err();
}
Check data content:
if (!pdoc) {
lib_write_line("No data found!");
} else {
Displaying the document type:
/* Displaying document type */
if (pr_getdocumentstatus(hpr, pdoc, &code, &status)) {
lib_write_line("Document type: %i, status: %s", code, ec[status/100]);
} else {
lib_displ_err();
}
Reading some fixed fields and displaying them
/* Reading some fixed fields and displaying them */
stext = sizeof(text);
if (pr_getfieldfromdoca(hpr, pdoc, PR_DF_NAME, text, &stext, &status, 0)) {
if (*text) lib_write_line("NAME \"%s\" [%s]", text, ec[status/100]);
} else {
lib_displ_err();
}
stext = sizeof(text);
if (pr_getfieldfromdoca(hpr, pdoc, PR_DF_DOCUMENT_NUMBER, text, &stext, &status, 0)) {
if (*text) lib_write_line("DOCUMENT NUMBER \"%s\" [%s]",text,ec[status/100]);
} else {
lib_displ_err();
}
stext = sizeof(text);
if (pr_getfieldfromdoca(hpr, pdoc, PR_DF_EXPIRY_DATE, text, &stext, &status, 0)) {
if(*text) lib_write_line("EXPIRY DATE \"%s\" [%s]",text,ec[status/100]);
} else {
lib_displ_err();
}
Searching for the fields and displaying them:
/* Searching for the fields and displaying them */
if(gx_getvariantchild(pdoc,GX_VARIANT_BY_ID, &id, 0, &fieldlist)) {
int nitems = 0;
/* Get the number of recognized fields */
if(gx_getvariant(fieldlist, 0, 0, 0, &nitems, 0)) {
for (i=0; i<nitems; i++) {
int field_code = 0;
int sz = sizeof(int);
int n = 0;
gx_snprintf(path, sizeof(path), "L,X=%d", i);
if(gx_convertvariantbypatha(fieldlist, path, 0, GX_VARIANT_INT, &sz, &n, &field_code, sizeof(field_code))) {
/* Get the field text */
stext = sizeof(text);
if (pr_getfieldfromdoca(hpr,pdoc,field_code,text,&stext,&status,0)) {
if (*text) {
/* Converting the data for displaying on console */
#ifdef WIN32
CharToOem(text,text);
#endif
lib_write_line("[%5i] \"%s\" [%s]", field_code, text, ec[status/100]);
}
} else {
lib_displ_err();
}
if(field_code >= PR_DF_FORMATTED) continue;
/* Get the field image */
gx_snprintf(text, sizeof(text), "%i.jpg",field_code);
if(pr_getfieldimage(hpr,pdoc,field_code,0,&img) &&
gx_imagefromvariant(gx_direct(GX_CALL_GROUP_GX_IMAGE), &gim, img) &&
gx_saveimagea(gx_direct(GX_CALL_GROUP_GX_IMAGE), gim, text, GX_JPEG) &&
gx_unrefimage(gx_direct(GX_CALL_GROUP_GX_IMAGE), gim) &&
gx_disposevariant(&img)
)
{
} else {
lib_displ_err();
}
} else {
lib_displ_err();
}
}
}
if (!gx_disposevariant(&fieldlist)) lib_displ_err();
}
if (!gx_disposevariant(&pdoc)) 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 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() { char *ec[]={"Ok","Warning","Error"}; gxVARIANT img; gxIMAGE *gim; gxVARIANT pdoc; /* 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()) { int code; int status; int id = PRV_FIELDLIST; gxVARIANT fieldlist; int i; char path[100], text[100]; int stext; lib_process_start("Processing document"); /* Capturing images */ lib_function_start("Capturing images"); if (!pr_capture(hpr)) { lib_displ_err(); } else { lib_function_end(); /* Getting document data */ lib_function_start("Recognizing."); if (pr_recognize(hpr,0,&pdoc)) { lib_function_end(); } else { lib_displ_err(); } if (!pdoc) { lib_write_line("No data found!"); } else { /* Displaying document type */ if (pr_getdocumentstatus(hpr, pdoc, &code, &status)) { lib_write_line("Document type: %i, status: %s", code, ec[status/100]); } else { lib_displ_err(); } /* Reading some fixed fields and displaying them */ stext = sizeof(text); if (pr_getfieldfromdoca(hpr, pdoc, PR_DF_NAME, text, &stext, &status, 0)) { if (*text) lib_write_line("NAME \"%s\" [%s]", text, ec[status/100]); } else { lib_displ_err(); } stext = sizeof(text); if (pr_getfieldfromdoca(hpr, pdoc, PR_DF_DOCUMENT_NUMBER, text, &stext, &status, 0)) { if (*text) lib_write_line("DOCUMENT NUMBER \"%s\" [%s]",text,ec[status/100]); } else { lib_displ_err(); } stext = sizeof(text); if (pr_getfieldfromdoca(hpr, pdoc, PR_DF_EXPIRY_DATE, text, &stext, &status, 0)) { if(*text) lib_write_line("EXPIRY DATE \"%s\" [%s]",text,ec[status/100]); } else { lib_displ_err(); } /* Searching for the fields and displaying them */ if(gx_getvariantchild(pdoc,GX_VARIANT_BY_ID, &id, 0, &fieldlist)) { int nitems = 0; /* Get the number of recognized fields */ if(gx_getvariant(fieldlist, 0, 0, 0, &nitems, 0)) { for (i=0; i<nitems; i++) { int field_code = 0; int sz = sizeof(int); int n = 0; gx_snprintf(path, sizeof(path), "L,X=%d", i); if(gx_convertvariantbypatha(fieldlist, path, 0, GX_VARIANT_INT, &sz, &n, &field_code, sizeof(field_code))) { /* Get the field text */ stext = sizeof(text); if (pr_getfieldfromdoca(hpr,pdoc,field_code,text,&stext,&status,0)) { if (*text) { /* Converting the data for displaying on console */ #ifdef WIN32 CharToOem(text,text); #endif lib_write_line("[%5i] \"%s\" [%s]", field_code, text, ec[status/100]); } } else { lib_displ_err(); } if(field_code >= PR_DF_FORMATTED) continue; /* Get the field image */ gx_snprintf(text, sizeof(text), "%i.jpg",field_code); if(pr_getfieldimage(hpr,pdoc,field_code,0,&img) && gx_imagefromvariant(gx_direct(GX_CALL_GROUP_GX_IMAGE), &gim, img) && gx_saveimagea(gx_direct(GX_CALL_GROUP_GX_IMAGE), gim, text, GX_JPEG) && gx_unrefimage(gx_direct(GX_CALL_GROUP_GX_IMAGE), gim) && gx_disposevariant(&img) ) { } else { lib_displ_err(); } } else { lib_displ_err(); } } } if (!gx_disposevariant(&fieldlist)) lib_displ_err(); } if (!gx_disposevariant(&pdoc)) 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(); }