|
|
The needed gxsdldr.cpp loader file is included directly:
#include "prapi.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 pr; #endif int main() { const char *ec[]={"Ok","Warning","Error"}; try {
Opening the Passport Reader system:
pr variable of the PasspportReader class is instantiated, the Passport Reader system is opened automaticaly:/* Opening the PR system */ lib.FunctionStart("Opening system files"); PassportReader pr; /* Object for the PR system */ lib.FunctionEnd();
Checking if the Passport Reader modules were opened:
/* Validity check */
if (!pr.IsValid()) {
lib.Error("Failed to initialize!");
return 0;
}
Connecting to the first device.
/* Connecting to the first device */
lib.FunctionStart("Connecting to the first device");
pr.UseDevice(0,PR_UMODE_FULL_CONTROL);
lib.FunctionEnd();
The main loop begins:
while (!lib.KbHit()) {
prDoc *doc = NULL;
lib.ProcessStart("Processing document");
Capturing images:
try {
/* Capturing images */
lib.FunctionStart("Capturing images");
pr.Capture();
lib.FunctionEnd();
Reading barcode:
/* Reading barcode */
lib.FunctionStart("Reading barcode from infra image");
doc = pr.GetBarcode(0,PR_LIGHT_INFRA,PR_IT_ORIGINAL,0,0);
lib.FunctionEnd();
if (!doc->IsValid()) {
lib.FunctionStart("Reading barcode from white image");
doc = pr.GetBarcode(0,PR_LIGHT_WHITE,PR_IT_ORIGINAL,0,0);
lib.FunctionEnd();
}
Check data content:
if (!doc->IsValid()) {
lib.WriteLine("No data found!");
} else {
Displaying the document type:
/* Displaying document type */ lib.WriteLine("Document type: " + lib.itos(doc->Code()) + ", status: " + ec[doc->Status()/100]);
Searching for the barcode and displaying it:
/* Searching for the barcode and displaying it */
char text[3000];
int stext = sizeof(text);
try {
/* Try to get ascii data */
doc->Field(PR_DF_BC1, text, &stext);
}
catch (const gxException &) {
/* Try to get binary data */
doc->Field(PR_DF_BC1, (void*)text, &stext);
}
text[stext] = 0;
int type = -1;
int status = doc->FieldStatus(PR_DF_BC1);
gxVariant* pdoc = doc->ToVariant();
gxVariant v;
if(pdoc->GetChild(v, GX_VARIANT_BY_ID, PRV_BARCODE, 0))
{
type = v.GetInt();
v.Dispose();
}
/* Converting the data and displaying on the console */
lib.WriteLine("Barcode type: " + lib.itos(type) + ", status: " + lib.itos(status) + ", length: " + lib.itos(stext));
#ifdef WIN32
CharToOemBuff(text, text, stext);
#endif
lib.WriteLine(text);
Saving the barcode image:
/* Saving the barcode image */
lib.FunctionStart("Save barcode image");
gxImage* img = doc->FieldImage(PR_DF_BC1);
if(img->IsValid()) img->Save("barcode.jpg", GX_JPEG);
if(img) delete img;
lib.FunctionEnd();
Searching for the fields and displaying them:
/* Searching for the fields and displaying them */
gxVariant fieldlist;
pdoc->GetChild(fieldlist, GX_VARIANT_BY_ID, PRV_FIELDLIST, 0);
int nitems = fieldlist.GetNItems();
for(int i = 0;i < nitems;i++)
{
gxVariant field;
fieldlist.GetItem(field, GX_VARIANT_BY_INDEX, 0, i);
int field_code = field.GetInt();
stext = sizeof(text);
try {
doc->Field(field_code, text, &stext);
}
catch (const gxException &) {
doc->Field(field_code, (void*)text, &stext);
}
text[stext] = 0;
#ifdef WIN32
CharToOemBuff(text, text, stext);
#endif
if (text[0]) lib.WriteLine("[" + lib.itos(field_code) + "] \"" + text + "\" [" + ec[doc->FieldStatus(field_code)/100] + "]");
}
delete pdoc;
}
} catch (gxException e) { lib.DisplExcp(e); }
The main loop ends:
if (doc) delete doc; lib.ProcessEnd(); lib.WaitForSec(3); }
Closing the device:
/* Closing the device */
lib.FunctionStart("Closing the device");
pr.CloseDevice();
lib.FunctionEnd();
Exception handling section, catching the exception and displaying the error code and error message:
} catch (gxException e) {
lib.DisplExcp(e);
}
The main function ends printing some statistic information:
return lib.PrintStat();
}
The complete source code:
#include "prapi.h" #include "gxsdldr.cpp" #include "../__lib__.h" Lib lib; #ifdef GX_NAMESPACES using namespace gx; using namespace pr; #endif int main() { const char *ec[]={"Ok","Warning","Error"}; try { /* Opening the PR system */ lib.FunctionStart("Opening system files"); PassportReader pr; /* Object for the PR system */ lib.FunctionEnd(); /* Validity check */ if (!pr.IsValid()) { lib.Error("Failed to initialize!"); return 0; } /* Connecting to the first device */ lib.FunctionStart("Connecting to the first device"); pr.UseDevice(0,PR_UMODE_FULL_CONTROL); lib.FunctionEnd(); while (!lib.KbHit()) { prDoc *doc = NULL; lib.ProcessStart("Processing document"); try { /* Capturing images */ lib.FunctionStart("Capturing images"); pr.Capture(); lib.FunctionEnd(); /* Reading barcode */ lib.FunctionStart("Reading barcode from infra image"); doc = pr.GetBarcode(0,PR_LIGHT_INFRA,PR_IT_ORIGINAL,0,0); lib.FunctionEnd(); if (!doc->IsValid()) { lib.FunctionStart("Reading barcode from white image"); doc = pr.GetBarcode(0,PR_LIGHT_WHITE,PR_IT_ORIGINAL,0,0); lib.FunctionEnd(); } if (!doc->IsValid()) { lib.WriteLine("No data found!"); } else { /* Displaying document type */ lib.WriteLine("Document type: " + lib.itos(doc->Code()) + ", status: " + ec[doc->Status()/100]); /* Searching for the barcode and displaying it */ char text[3000]; int stext = sizeof(text); try { /* Try to get ascii data */ doc->Field(PR_DF_BC1, text, &stext); } catch (const gxException &) { /* Try to get binary data */ doc->Field(PR_DF_BC1, (void*)text, &stext); } text[stext] = 0; int type = -1; int status = doc->FieldStatus(PR_DF_BC1); gxVariant* pdoc = doc->ToVariant(); gxVariant v; if(pdoc->GetChild(v, GX_VARIANT_BY_ID, PRV_BARCODE, 0)) { type = v.GetInt(); v.Dispose(); } /* Converting the data and displaying on the console */ lib.WriteLine("Barcode type: " + lib.itos(type) + ", status: " + lib.itos(status) + ", length: " + lib.itos(stext)); #ifdef WIN32 CharToOemBuff(text, text, stext); #endif lib.WriteLine(text); /* Saving the barcode image */ lib.FunctionStart("Save barcode image"); gxImage* img = doc->FieldImage(PR_DF_BC1); if(img->IsValid()) img->Save("barcode.jpg", GX_JPEG); if(img) delete img; lib.FunctionEnd(); /* Searching for the fields and displaying them */ gxVariant fieldlist; pdoc->GetChild(fieldlist, GX_VARIANT_BY_ID, PRV_FIELDLIST, 0); int nitems = fieldlist.GetNItems(); for(int i = 0;i < nitems;i++) { gxVariant field; fieldlist.GetItem(field, GX_VARIANT_BY_INDEX, 0, i); int field_code = field.GetInt(); stext = sizeof(text); try { doc->Field(field_code, text, &stext); } catch (const gxException &) { doc->Field(field_code, (void*)text, &stext); } text[stext] = 0; #ifdef WIN32 CharToOemBuff(text, text, stext); #endif if (text[0]) lib.WriteLine("[" + lib.itos(field_code) + "] \"" + text + "\" [" + ec[doc->FieldStatus(field_code)/100] + "]"); } delete pdoc; } } catch (gxException e) { lib.DisplExcp(e); } if (doc) delete doc; lib.ProcessEnd(); lib.WaitForSec(3); } /* Closing the device */ lib.FunctionStart("Closing the device"); pr.CloseDevice(); lib.FunctionEnd(); } catch (gxException e) { lib.DisplExcp(e); } return lib.PrintStat(); }
The needed gxsdldr.cpp loader file is included directly:
#include "prapi.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 pr; #endif int main() { try {
Opening the Passport Reader system:
pr variable of the PasspportReader class is instantiated, the Passport Reader system is opened automaticaly:/* Opening the PR system */ lib.FunctionStart("Opening system files"); PassportReader pr; /* Object for the PR system */ lib.FunctionEnd();
Checking if the Passport Reader modules were opened:
/* Validity check */
if (!pr.IsValid()) {
lib.Error("Failed to initialize!");
return 0;
}
Connecting to the first device.
/* Connecting to the first device */
lib.FunctionStart("Connecting to the first device");
pr.UseDevice(0,PR_UMODE_FULL_CONTROL);
lib.FunctionEnd();
The main loop begins:
/* Using the device */
while (!lib.KbHit()) {
lib.ProcessStart("Processing document");
Capturing images:
prDoc * doc = NULL;
try {
/* Capturing images */
lib.FunctionStart("Capturing images");
pr.Capture();
lib.FunctionEnd();
Calling OCR:
/* Call OCR */
lib.FunctionStart("Call OCR");
gxPG4 r1 = {100*16, 1200*16, 1900*16, 1200*16, 1900*16, 1400*16, 100*16, 1400*16}; /* x1, y1, x2, y2, x3, y3, x4, y4 */
int height = 2500;
int spacewidth = 50;
int spacetype = 0;
int justification = 0;
char font[] = "General";
gxVariant params, vd;
params.CreateEmptyList(PRV_OCRPARAMS);
vd.Create(PRV_IMAGEFRAME,r1);
params.AddItem(GX_VARIANT_APPEND,0,0,vd);
vd.Create(PRV_CHARHEIGHT,height);
params.AddItem(GX_VARIANT_APPEND,0,0,vd);
vd.Create(PRV_SPACEWIDTH,spacewidth);
params.AddItem(GX_VARIANT_APPEND,0,0,vd);
vd.Create(PRV_SPACETYPE,spacetype);
params.AddItem(GX_VARIANT_APPEND,0,0,vd);
vd.Create(PRV_JUSTIFICATION,justification);
params.AddItem(GX_VARIANT_APPEND,0,0,vd);
vd.Create(PRV_FONTTYPE,font);
params.AddItem(GX_VARIANT_APPEND,0,0,vd);
doc = pr.GetOcr(0,PR_LIGHT_INFRA,PR_IT_ORIGINAL,¶ms);
lib.FunctionEnd();
Check data content:
if (!doc->IsValid()) {
lib.WriteLine("No OCR data found.");
} else {
Reading and displaying OCR data:
/* Reading and displaying OCR data */
try {
string text;
int len = 100;
char path[100];
gxVariant* pdoc = doc->ToVariant();
gx_snprintf(path,sizeof(path),"C,D=%i/L,D=%i/C,D=%i",PRV_OCRROWLIST,PRV_OCRROW,PRV_FIELDVALUE);
gxVariant ocr;
pdoc->GetItemByPath(ocr, path);
text = ocr.GetASCII(len);
lib.WriteLine("OCR \"" + text + "\"");
delete pdoc;
} catch (gxException e) {
lib.DisplExcp(e);
}
}
Exception handling:
} catch (gxException e) {
lib.DisplExcp(e);
}
The main loop ends:
if(doc) delete doc;
lib.ProcessEnd();
lib.WaitForSec(3);
}
Closing the device:
/* Closing the device */
lib.FunctionStart("Closing the device");
pr.CloseDevice();
lib.FunctionEnd();
Exception handling section, catching the exception and displaying the error code and error message:
} catch (gxException e) {
lib.DisplExcp(e);
}
The main function ends printing some statistic information:
return lib.PrintStat();
}
The complete source code:
#include "prapi.h" #include "gxsdldr.cpp" #include "../__lib__.h" Lib lib; #ifdef GX_NAMESPACES using namespace gx; using namespace pr; #endif int main() { try { /* Opening the PR system */ lib.FunctionStart("Opening system files"); PassportReader pr; /* Object for the PR system */ lib.FunctionEnd(); /* Validity check */ if (!pr.IsValid()) { lib.Error("Failed to initialize!"); return 0; } /* Connecting to the first device */ lib.FunctionStart("Connecting to the first device"); pr.UseDevice(0,PR_UMODE_FULL_CONTROL); lib.FunctionEnd(); /* Using the device */ while (!lib.KbHit()) { lib.ProcessStart("Processing document"); prDoc * doc = NULL; try { /* Capturing images */ lib.FunctionStart("Capturing images"); pr.Capture(); lib.FunctionEnd(); /* Call OCR */ lib.FunctionStart("Call OCR"); gxPG4 r1 = {100*16, 1200*16, 1900*16, 1200*16, 1900*16, 1400*16, 100*16, 1400*16}; /* x1, y1, x2, y2, x3, y3, x4, y4 */ int height = 2500; int spacewidth = 50; int spacetype = 0; int justification = 0; char font[] = "General"; gxVariant params, vd; params.CreateEmptyList(PRV_OCRPARAMS); vd.Create(PRV_IMAGEFRAME,r1); params.AddItem(GX_VARIANT_APPEND,0,0,vd); vd.Create(PRV_CHARHEIGHT,height); params.AddItem(GX_VARIANT_APPEND,0,0,vd); vd.Create(PRV_SPACEWIDTH,spacewidth); params.AddItem(GX_VARIANT_APPEND,0,0,vd); vd.Create(PRV_SPACETYPE,spacetype); params.AddItem(GX_VARIANT_APPEND,0,0,vd); vd.Create(PRV_JUSTIFICATION,justification); params.AddItem(GX_VARIANT_APPEND,0,0,vd); vd.Create(PRV_FONTTYPE,font); params.AddItem(GX_VARIANT_APPEND,0,0,vd); doc = pr.GetOcr(0,PR_LIGHT_INFRA,PR_IT_ORIGINAL,¶ms); lib.FunctionEnd(); if (!doc->IsValid()) { lib.WriteLine("No OCR data found."); } else { /* Reading and displaying OCR data */ try { string text; int len = 100; char path[100]; gxVariant* pdoc = doc->ToVariant(); gx_snprintf(path,sizeof(path),"C,D=%i/L,D=%i/C,D=%i",PRV_OCRROWLIST,PRV_OCRROW,PRV_FIELDVALUE); gxVariant ocr; pdoc->GetItemByPath(ocr, path); text = ocr.GetASCII(len); lib.WriteLine("OCR \"" + text + "\""); delete pdoc; } catch (gxException e) { lib.DisplExcp(e); } } } catch (gxException e) { lib.DisplExcp(e); } if(doc) delete doc; lib.ProcessEnd(); lib.WaitForSec(3); } /* Closing the device */ lib.FunctionStart("Closing the device"); pr.CloseDevice(); lib.FunctionEnd(); } catch (gxException e) { lib.DisplExcp(e); } return lib.PrintStat(); }
The needed gxsdldr.cpp loader file is included directly:
#include "prapi.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 pr; #endif int main() { string text; string ec[]={"Ok","Warning","Error"}; try {
Opening the Passport Reader system:
pr variable of the PasspportReader class is instantiated, the Passport Reader system is opened automaticaly:/* Opening the PR system */ lib.FunctionStart("Opening system files"); PassportReader pr; /* Object for the PR system */ lib.FunctionEnd();
Checking if the Passport Reader modules were opened:
/* Validity check */
if (!pr.IsValid()) {
lib.Error("Failed to initialize!");
return 0;
}
Connecting to the first device.
/* Connecting to the first device */
lib.FunctionStart("Connecting to the first device");
pr.UseDevice(0,PR_UMODE_FULL_CONTROL);
lib.FunctionEnd();
The main loop begins:
/* Using the device */
while (!lib.KbHit()) {
lib.ProcessStart("MRZ");
Capturing images:
prDoc * doc = NULL;
try {
/* Capturing images */
lib.FunctionStart("Capturing images");
pr.Capture();
lib.FunctionEnd();
Reading the MRZ data:
/* Getting the MRZ data */
lib.FunctionStart("Reading MRZ");
doc = pr.GetMrz(0,PR_LIGHT_INFRA,PR_IT_ORIGINAL);
lib.FunctionEnd();
Displaying the found data:
if (!doc->IsValid()) {
lib.WriteLine("No MRZ data found!");
} else {
/* Searching for MRZ fields and displaying them */
text = doc->FieldA(PR_DF_MRZ1);
if (text != "") lib.WriteLine("MRZ1 \"" + text + "\" [" + ec[doc->FieldStatus(PR_DF_MRZ1)/100] + "]");
text = doc->FieldA(PR_DF_MRZ2);
if (text != "") lib.WriteLine("MRZ2 \"" + text + "\" [" + ec[doc->FieldStatus(PR_DF_MRZ2)/100] + "]");
text = doc->FieldA(PR_DF_MRZ3);
if (text != "") lib.WriteLine("MRZ3 \"" + text + "\" [" + ec[doc->FieldStatus(PR_DF_MRZ3)/100] + "]");
}
Exception handling:
} catch (gxException e) {
lib.DisplExcp(e);
}
The main loop ends:
if (doc) delete doc;
lib.ProcessEnd();
lib.WaitForSec(3);
}
Closing the device:
/* Closing the device */
lib.FunctionStart("Closing the device");
pr.CloseDevice();
lib.FunctionEnd();
Exception handling section, catching the exception and displaying the error code and error message:
} catch (gxException e) {
lib.DisplExcp(e);
}
The main function ends printing some statistic information:
return lib.PrintStat();
}
The complete source code:
#include "prapi.h" #include "gxsdldr.cpp" #include "../__lib__.h" Lib lib; #ifdef GX_NAMESPACES using namespace gx; using namespace pr; #endif int main() { string text; string ec[]={"Ok","Warning","Error"}; try { /* Opening the PR system */ lib.FunctionStart("Opening system files"); PassportReader pr; /* Object for the PR system */ lib.FunctionEnd(); /* Validity check */ if (!pr.IsValid()) { lib.Error("Failed to initialize!"); return 0; } /* Connecting to the first device */ lib.FunctionStart("Connecting to the first device"); pr.UseDevice(0,PR_UMODE_FULL_CONTROL); lib.FunctionEnd(); /* Using the device */ while (!lib.KbHit()) { lib.ProcessStart("MRZ"); prDoc * doc = NULL; try { /* Capturing images */ lib.FunctionStart("Capturing images"); pr.Capture(); lib.FunctionEnd(); /* Getting the MRZ data */ lib.FunctionStart("Reading MRZ"); doc = pr.GetMrz(0,PR_LIGHT_INFRA,PR_IT_ORIGINAL); lib.FunctionEnd(); if (!doc->IsValid()) { lib.WriteLine("No MRZ data found!"); } else { /* Searching for MRZ fields and displaying them */ text = doc->FieldA(PR_DF_MRZ1); if (text != "") lib.WriteLine("MRZ1 \"" + text + "\" [" + ec[doc->FieldStatus(PR_DF_MRZ1)/100] + "]"); text = doc->FieldA(PR_DF_MRZ2); if (text != "") lib.WriteLine("MRZ2 \"" + text + "\" [" + ec[doc->FieldStatus(PR_DF_MRZ2)/100] + "]"); text = doc->FieldA(PR_DF_MRZ3); if (text != "") lib.WriteLine("MRZ3 \"" + text + "\" [" + ec[doc->FieldStatus(PR_DF_MRZ3)/100] + "]"); } } catch (gxException e) { lib.DisplExcp(e); } if (doc) delete doc; lib.ProcessEnd(); lib.WaitForSec(3); } /* Closing the device */ lib.FunctionStart("Closing the device"); pr.CloseDevice(); lib.FunctionEnd(); } catch (gxException e) { lib.DisplExcp(e); } return lib.PrintStat(); }
The needed gxsdldr.cpp loader file is included directly:
#include "prapi.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 pr; #endif int main() { string text; string ec[]={"Ok","Warning","Error"}; try {
Opening the Passport Reader system:
pr variable of the PasspportReader class is instantiated, the Passport Reader system is opened automaticaly:/* Opening the PR system */ lib.FunctionStart("Opening system files"); PassportReader pr; /* Object for the PR system */ lib.FunctionEnd();
Checking if the Passport Reader modules were opened:
/* Validity check */
if (!pr.IsValid()) {
lib.Error("Failed to initialize!");
return 0;
}
Connecting to the first device.
/* Connecting to the first device */
lib.FunctionStart("Connecting to the first device");
pr.UseDevice(0,PR_UMODE_FULL_CONTROL);
lib.FunctionEnd();
The main loop begins:
/* Using the device */
while (!lib.KbHit()) {
lib.ProcessStart("Processing document");
Capturing images:
prDoc * doc = NULL;
try {
/* Capturing images */
lib.FunctionStart("Capturing images");
pr.Capture();
lib.FunctionEnd();
Recognizing the images:
/* Getting document data */
lib.FunctionStart("Recognizing.");
doc = pr.Recognize(0);
lib.FunctionEnd();
Check data content:
if (!doc->IsValid()) {
lib.WriteLine("No data found.");
} else {
Displaying the document type:
/* Displaying document type */ lib.WriteLine("Document type: " + lib.itos(doc->Code()) + ", status: " + ec[doc->Status()/100]);
Reading some fixed fields and displaying them
/* Reading some fixed fields and displaying them */
text = doc->FieldA(PR_DF_NAME);
if (text != "") lib.WriteLine("NAME \"" + text + "\" [" + ec[doc->FieldStatus(PR_DF_NAME)/100] + "]");
text = doc->FieldA(PR_DF_DOCUMENT_NUMBER);
if (text != "") lib.WriteLine("DOCUMENT NUMBER \"" + text + "\" [" + ec[doc->FieldStatus(PR_DF_DOCUMENT_NUMBER)/100] + "]");
text = doc->FieldA(PR_DF_EXPIRY_DATE);
if (text != "") lib.WriteLine("EXPIRY DATE \"" + text + "\" [" + ec[doc->FieldStatus(PR_DF_EXPIRY_DATE)/100] + "]");
Searching for the fields and displaying them:
/* Searching for the fields and displaying them */
gxVariant* pdoc = doc->ToVariant();
gxVariant fieldlist;
pdoc->GetChild(fieldlist, GX_VARIANT_BY_ID, PRV_FIELDLIST, 0);
int nitems = fieldlist.GetNItems();
for(int i = 0;i < nitems;i++)
{
gxVariant field;
fieldlist.GetItem(field, GX_VARIANT_BY_INDEX, 0, i);
int field_code = field.GetInt();
text = doc->FieldA(field_code);
if (text != "") lib.WriteLine("[" + lib.itos(field_code) + "] \"" + text + "\" [" + ec[doc->FieldStatus(field_code)/100] + "]");
if(field_code >= PR_DF_FORMATTED) continue;
try
{
gxImage* img = doc->FieldImage(field_code);
if(img->IsValid()) img->Save(lib.itos(field_code) + ".jpg", GX_JPEG);
if(img) delete img;
} catch (gxException e) {
lib.DisplExcp(e);
}
}
delete pdoc;
}
Exception handling:
} catch (gxException e) { lib.DisplExcp(e); }
The main loop ends:
if (doc) delete doc;
lib.ProcessEnd();
lib.WaitForSec(3);
}
Closing the device:
/* Closing the device */
lib.FunctionStart("Closing the device");
pr.CloseDevice();
lib.FunctionEnd();
Exception handling section, catching the exception and displaying the error code and error message:
} catch (gxException e) {
lib.DisplExcp(e);
}
The main function ends printing some statistic information:
return lib.PrintStat();
}
The complete source code:
#include "prapi.h" #include "gxsdldr.cpp" #include "../__lib__.h" Lib lib; #ifdef GX_NAMESPACES using namespace gx; using namespace pr; #endif int main() { string text; string ec[]={"Ok","Warning","Error"}; try { /* Opening the PR system */ lib.FunctionStart("Opening system files"); PassportReader pr; /* Object for the PR system */ lib.FunctionEnd(); /* Validity check */ if (!pr.IsValid()) { lib.Error("Failed to initialize!"); return 0; } /* Connecting to the first device */ lib.FunctionStart("Connecting to the first device"); pr.UseDevice(0,PR_UMODE_FULL_CONTROL); lib.FunctionEnd(); /* Using the device */ while (!lib.KbHit()) { lib.ProcessStart("Processing document"); prDoc * doc = NULL; try { /* Capturing images */ lib.FunctionStart("Capturing images"); pr.Capture(); lib.FunctionEnd(); /* Getting document data */ lib.FunctionStart("Recognizing."); doc = pr.Recognize(0); lib.FunctionEnd(); if (!doc->IsValid()) { lib.WriteLine("No data found."); } else { /* Displaying document type */ lib.WriteLine("Document type: " + lib.itos(doc->Code()) + ", status: " + ec[doc->Status()/100]); /* Reading some fixed fields and displaying them */ text = doc->FieldA(PR_DF_NAME); if (text != "") lib.WriteLine("NAME \"" + text + "\" [" + ec[doc->FieldStatus(PR_DF_NAME)/100] + "]"); text = doc->FieldA(PR_DF_DOCUMENT_NUMBER); if (text != "") lib.WriteLine("DOCUMENT NUMBER \"" + text + "\" [" + ec[doc->FieldStatus(PR_DF_DOCUMENT_NUMBER)/100] + "]"); text = doc->FieldA(PR_DF_EXPIRY_DATE); if (text != "") lib.WriteLine("EXPIRY DATE \"" + text + "\" [" + ec[doc->FieldStatus(PR_DF_EXPIRY_DATE)/100] + "]"); /* Searching for the fields and displaying them */ gxVariant* pdoc = doc->ToVariant(); gxVariant fieldlist; pdoc->GetChild(fieldlist, GX_VARIANT_BY_ID, PRV_FIELDLIST, 0); int nitems = fieldlist.GetNItems(); for(int i = 0;i < nitems;i++) { gxVariant field; fieldlist.GetItem(field, GX_VARIANT_BY_INDEX, 0, i); int field_code = field.GetInt(); text = doc->FieldA(field_code); if (text != "") lib.WriteLine("[" + lib.itos(field_code) + "] \"" + text + "\" [" + ec[doc->FieldStatus(field_code)/100] + "]"); if(field_code >= PR_DF_FORMATTED) continue; try { gxImage* img = doc->FieldImage(field_code); if(img->IsValid()) img->Save(lib.itos(field_code) + ".jpg", GX_JPEG); if(img) delete img; } catch (gxException e) { lib.DisplExcp(e); } } delete pdoc; } } catch (gxException e) { lib.DisplExcp(e); } if (doc) delete doc; lib.ProcessEnd(); lib.WaitForSec(3); } /* Closing the device */ lib.FunctionStart("Closing the device"); pr.CloseDevice(); lib.FunctionEnd(); } catch (gxException e) { lib.DisplExcp(e); } return lib.PrintStat(); }