CodeMAX Barcode Reader SDK C++ Example

Posted by Sension Admin 30/05/2018 0 Comment(s) Knowledge Base,

CodeMAX Barcode Reader SDK C++ Example


Images of barcodes cannot always be captured under ideal conditions. This often results in underexposed, blurry or distorted images. Additionally, the barcodes can be damaged e.g. by scratches, wrinkles or glare in the image. Decoding such challenging barcode images is no problem with the CodeMAX Barcode Reader SDK, and it is surprisingly simple compared to competing barcode reader SDK’s.

Let’s look at an example of how easily the CodeMAX Barcode Reader SDK can be integrated into a small C++ program to decode an image containing a severely damaged Code128 barcode and a wrinkled EAN13 barcode as seen below. Note that we do not need to explicitly specify that we are looking for these particular types of barcodes or set any special options to decode the degraded barcodes. The CodeMAX Barcode Reader SDK will automatically detect all supported barcodes in the image, and restore any damages such that the barcodes can be decoded.

 



The example usage of the CodeMAX Barcode Reader SDK for C++ looks like this:
 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// First we import the CodeMAX Barcode Reader SDK library 
// and instantiate objects and variables:
 
#include "codemax.h"
#include "cmdefines.h"
 
using namespace cm;
 
int main(int argc, char *argv[])
{
 CodeMAX decoder;
 cmIoImg inputImage;
 cmIoImg resultImage;
 cmDecodeInfo decodeInfo;
 
 // Then we load the test image:
 inputImage.load("image.jpg");
 
 // Next we initialize the decoder to decode barcodes using 
 // the precise mode allow maximum 100 ms to decode a barcode
 // before time-out and enable all supported symbologies.
 decoder.setup(enumProcStrategy::CM_PROCSTRATEGY_PRECISE, 100, CM_ENABLE_ALL);
 
 // Now we are ready to start decoding, which is done by providing
 // the input image and an optional empty image which will contain 
 // information about the decoded barcodes:
 decoder.decodeImage(inputImage, decodeInfo, NULL, &resultImage);
 
 // Finally, we save the result image to the disk, and iterate over
 // all decoded barcodes and print relevant information about the 
 // barcodes to the terminal.
 resultImage.save("resultImage.jpg");
 
 std::cout << "CodeMAX Barcode Reader SDK C++ Example\n\n";
 
 for (int i = 0; i < decodeInfo.numBarcodes; i++)
 {
  decoder.getBarcodeRegionInfo(i, decodeInfo);
  std::cout << "Barcode type: " << decodeInfo.barcodeData[i].barcodeType << "\n";
  std::cout << "Barcode content: " << decodeInfo.barcodeData[i].barcodeContent << "\n";
 }
 
 return 0;
}

 

The output in the terminal looks like this after executing the example program:


1
2
3
4
5
6
CodeMAX Barcode Reader SDK C++ Example
 
Barcode type: EAN13
Barcode content: 5711988001082
Barcode type:: CODE128
Barcode content: 9208607303193208


And the output image with overlay information:

 



Hence, with just a few lines of code the extremely powerful, yet easy to use CodeMAX Barcode Reader SDK can be used to decode severely degraded barcodes. Please note that this is bare minimum working example. You should always include error checking in production code. Contact us already today for a free 30 day trial of the CodeMAX Barcode Reader Demo SDK which supports both 1D and 2D barcodes.

Please refer to the list supported symbologies for an overview of all the different barcodes the CodeMAX Barcode Reader SDK supports. It is also possible to test our CodeMAX Barcode Reader SDK using our online barcode reader.