C++
Step 1: Install ClearImage SDK
Download and install the ClearImage SDK
Step 2: Configure your project
Use Visual Studio C++ ClearImage example project or follow the instruction below. When using the example project, copy ClearImage.dll in the executable folder or in the PATH.
In your Visual Studio C++ project:
- Include a copy of C:\Program Files (x86)\Inlite\ClearImageSDK\ClearImage.wrapper.hpp in every source file that uses ClearImage API.
- Add a copy of C:\Program Files (x86)\Inlite\ClearImageSDK\ClearImage.lib to your project's Properties->Linker->Input->Additional Dependencies entry.
- Place ClearImage.dll in a location where it can be found according to Microsoft's DLL search order rules. Typically it is a working folder where your application started from. The ClearImage.dll is installed in:
- 32-bit version from C:\Program Files (x86)\Inlite\ClearImageSDK\win32\ClearImage.dll
- 64-bit version from C:\Program Files (x86)\Inlite\ClearImageSDK\x64\ClearImage.dll
This code demonstrates the use of ClearImage DLL API. Runtime errors are reported in ExceptionCI object.
#include "ClearImage.wrapper.hpp"
void main() {
try {
CiServer Server = CreateCiServer();
// your ClearImage API-based code
}
catch (ExceptionCI ex) {
std::wcout << L"ERROR: " << ex.getMessage() << std::endl;
}
catch (std::runtime_error ex) {
std::wcout << "ERROR: " << ex.what() << std::endl;
}
catch (...) {
std::wcout << "ERROR: " << "unknown"<< std::endl;
}
}ClearImage project development
Extend functionality
While developing your application, you can combine code examples on this page with methods described in ClearImage API documentation. DLL API, as exposed through ClearImage.wrapper.hpp, is substantially similar to COM API and .NET API Inlite.ClearImage namespace.
Exception handling
ClearImage DLL API reports errors as an ExceptionCI object.
try {
// Call ClearImage .NET API
}
catch (ExceptionCI ex) {
std::wcout << L"ERROR: " << ex.getMessage() << std::endl;
}Barcode Reading
Read 1D barcodes from a page
This example reads code 39 and code 128 barcodes. Set barcode types used in your application. Setting reader->AutoDetect1D=true; automatically finds the barcode type, but it is slower and is not recommended for production.
void ReadBarcode1D_page(const CiServer &Server, const std::wstring &fileName, const long page)
{
try {
CiBarcodePro reader = Server->CreateBarcodePro();
reader->Type = (FBarcodeType)(cibfCode39 | cibfCode128);
// reader->AutoDetect1D = true;
reader->Image->Open(fileName, page);
reader->Find(0);
for (int i = 1; i <= reader->Barcodes->Count; i++)
std::wcout << reader->Barcodes->Item[i-1]->Text << std::endl;
}
catch (ExceptionCI ex) {
std::wcout << L"ERROR: " << ex.getMessage() << std::endl;
}
}Read 2D Barcode from a page
This example reads PDF417, DataMatrix, and QR code. 2D barcodes might contain binary data available in CiBarcode->Data property as std::vector<char>
void ReadBarcode2D_page(const CiServer& Server, const std::wstring& fileName, const long page)
{
try {
CiQR reader = Server->CreateQR();
// CiPdf417 reader = Server->CreatePdf417();
// CiDataMatrix reader = Server->CreateDataMatrix();
reader->Image->Open(fileName, page);
reader->Find(0);
for (int i = 1; i <= reader->Barcodes->Count; i++)
std::wcout << reader->Barcodes->Item[i-1]->Text << std::endl;
}
catch (ExceptionCI ex) {
std::wcout << L"ERROR: " << ex.getMessage() << std::endl;
}
}Read Postal Barcodes from a page
This example reads Postal Barcodes from an image file page.
void ReadBarcodePostal_page(const CiServer& Server, const std::wstring& fileName, const long page)
{
try {
CiBarcodePro reader = Server->CreateBarcodePro();
reader->Type = cibf4State;
reader->Image->Open(fileName, page);
reader->Find(0);
for (int i = 1; i <= reader->Barcodes->Count; i++)
{
std::wstring type = L"";
switch (reader->Barcodes->Item[i-1]->Type)
{
case cibUspsIntelligentMail: type = L"US Intelligent Mail "; break;
case cibBpoPostcode: type = L"UK Royal Mail "; break;
case cibAustralianPost: type = L"Australian Mail "; break;
case cibSingaporePost: type = L"Singapore Mail "; break;
}
std::wcout << L"Type: " << type << L" " << reader->Barcodes->Item[i-1]->Text << std::endl;
}
}
catch (ExceptionCI ex) {
std::wcout << L"ERROR: " << ex.getMessage() << std::endl;
}
}Read Driver's License barcode
This example reads the Driver's License barcode from an image file page.
void ReadDriverLicBarcode_page(const CiServer& Server, const std::wstring& fileName, const long page)
{
try {
CiPdf417 reader = Server->CreatePdf417();
reader->Image->Open(fileName, page);
reader->Find(0);
for (int i = 1; i <= reader->Barcodes->Count; i++) {
CiBarcode Bc = reader->Barcodes->Item[i-1];
std::wcout << Bc->Text << std::endl;
if (Bc->Type == EBarcodeType::cibPdf417 && Bc->GetInfo(L"last") != L"") {
std::wcout << L"last: " << Bc->GetInfo(L"last") << std::endl;
std::wcout << L"first: " << Bc->GetInfo(L"first") << std::endl;
std::wcout << L"middle: " << Bc->GetInfo(L"middle") << std::endl;
std::wcout << L"suffix: " << Bc->GetInfo(L"suffix") << std::endl;
std::wcout << L"dob: " << Bc->GetInfo(L"dob") << std::endl;
std::wcout << L"eyes: " << Bc->GetInfo(L"eyes") << std::endl;
std::wcout << L"hair: " << Bc->GetInfo(L"hair") << std::endl;
std::wcout << L"sex: " << Bc->GetInfo(L"sex") << std::endl;
std::wcout << L"height: " << Bc->GetInfo(L"height") << std::endl;
std::wcout << L"weight: " << Bc->GetInfo(L"weight") << std::endl;
std::wcout << L"street: " << Bc->GetInfo(L"street") << std::endl;
std::wcout << L"city: " << Bc->GetInfo(L"city") << std::endl;
std::wcout << L"state: " << Bc->GetInfo(L"state") << std::endl;
std::wcout << L"postal: " << Bc->GetInfo(L"postal") << std::endl;
std::wcout << L"country: " << Bc->GetInfo(L"country") << std::endl;
std::wcout << L"id: " << Bc->GetInfo(L"id") << std::endl;
std::wcout << L"issued: " << Bc->GetInfo(L"issued") << std::endl;
std::wcout << L"expires: " << Bc->GetInfo(L"expires") << std::endl;
}
}
}
catch (ExceptionCI ex) {
std::wcout << L"ERROR: " << ex.getMessage() << std::endl;
}
}Read from a multi-page image file
This example reads barcodes from a single-page file or all pages of a multi-page image file.
void ReadBarcode1D_file(const CiServer& Server, const std::wstring& fileName)
{
try {
// configure reader
CiBarcodePro reader = Server->CreateBarcodePro();
reader->Type = (FBarcodeType)(cibfCode39 | cibfCode128);
int page = 1;
while (true) {
reader->Image->Open(fileName, page);
reader->Find(0);
for (int i = 1; i <= reader->Barcodes->Count; i++)
std::wcout << "Page: " << page << " Text: " << reader->Barcodes->Item[i-1]->Text << std::endl;
page++;
if (page > reader->Image->PageCount)
break;
}
}
catch (ExceptionCI ex)
{
std::wcout << L"ERROR: " << ex.getMessage() << std::endl;
}
}Image Processing
Repair image page
This example uses some of the most popular image-processing functions. In a production application, the specific sequence of functions should be selected based on specific application needs.
void RepairPage(const CiRepair& repair)
{
repair->AutoDeskew();
repair->AutoRotate();
repair->AutoCrop(10, 10, 10, 10);
repair->Image->ToBitonal();
repair->BorderExtract(EBorderExtractFlags::ciBexBorderDeskewCrop,
EBorderExtractAlgorithm::ciBeaCleaner);
repair->RemovePunchHoles();
repair->SmoothCharacters(ESmoothType::ciSmoothDarkenEdges);
repair->CleanNoiseExt ((ECleanNoiseFlags) (ciCnxBlackNoise | ciCnxWhiteNoise), 3, 3, 10);
}
void Repair_page(const CiServer& Server, const std::wstring& fileName, const long page,
const std::wstring& fileOut)
{
try {
CiRepair repair = Server->CreateRepair();
repair->Image->Open(fileName, page);
RepairPage(repair);
repair->Image->SaveAs(fileOut, EFileFormat::ciEXT);
}
catch (ExceptionCI ex) {
std::wcout << L"ERROR: " << ex.getMessage() << std::endl;
}
}Repair all images in a multi-page file
This example repairs all images in a multi-page file and saves the result in the fileOut file.
using Inlite.ClearImageNet;
void Repair_file(const CiServer& Server, const std::wstring& fileName, const std::wstring& fileOut)
{
try {
CiRepair repair = Server->CreateRepair();
int page = 1;
while (true) {
repair->Image->Open(fileName, page);
RepairPage(repair); // see code above
if (page == 1) repair->Image->SaveAs(fileOut, EFileFormat::ciEXT);
else repair->Image->Append(fileOut, EFileFormat::ciEXT);
page++;
if (page > repair->Image->PageCount)
break;
}
}
catch (ExceptionCI ex) {
std::wcout << L"ERROR: " << ex.getMessage() << std::endl;
}
}