# EasyBarCode - Reading Bar Codes

![EasyBarCode](assets/images/easybarcode2/home_illustration.webp)

<a id="easybarcode2-definition"></a>

## Bar Code Definition

A bar code is a 2D pattern of parallel bars and spaces of varying thickness that represents a character string.

These bars and spaces are arranged according to a convention named symbology (see [supported symbologies](../list_of_supported_codes.html.md#list-supported-barcodes)), that specifies the character set and the encoding rules.

<a id="easybarcode2-pruprose"></a>

## Purpose of the **EasyBarCode** library

The **EasyBarCode** library allows to read bar codes in images:

* The reading is fast and robust.
* Several codes can be read in the same image.
* Many symbologies are supported
* The processing can be limited to an [`ERegion`](../../../doxygen_cpp/classeVision_1_1ERegion.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1ERegion.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1ERegion.html) in the image.
* Specific support is provided for codes arranged in a grid.
* The bar codes can be graded according to the `ISO 15416` norms.

#### NOTE
Using a different set of classes, the **EasyBarCode** library also supports [mail bar codes](easymailbarcode.html.md).

<a id="easybarcode2-reading"></a>

## Reading Bar Codes

* Use the method [`EBarCodeReader::Read`](../../../doxygen_cpp/classeVision_1_1EasyBarCode2_1_1EBarCodeReader.html#a82a90c2861ab8b77859b3d3ac0ea154f) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyBarCode2_1_1EBarCodeReader.html#adf5742837f2fe289a51ef4a56ae5fe80) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyBarCode2_1_1EBarCodeReader.html#a3441ffc9eb4eb2f9ca77ae7396d7c2f3) to locate the bar codes as [`EBarCode`](../../../doxygen_cpp/classeVision_1_1EasyBarCode2_1_1EBarCode.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyBarCode2_1_1EBarCode.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyBarCode2_1_1EBarCode.html) objects in an image and decode them.
* This method returns a vector of [`EBarCode`](../../../doxygen_cpp/classeVision_1_1EasyBarCode2_1_1EBarCode.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyBarCode2_1_1EBarCode.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyBarCode2_1_1EBarCode.html) objects for each bar code in the field of view, up to the maximum set with [`EBarCodeReader::SetMaxNumCodes`](../../../doxygen_cpp/classeVision_1_1EasyBarCode2_1_1EBarCodeReader.html#a7a6d9c0f9303c1826c74c79e8faa6346) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyBarCode2_1_1EBarCodeReader.html#ab60e5f220fc1035fb3affa6736d662b1) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyBarCode2_1_1EBarCodeReader.html#a4590059e47f46e9f130b33c9e9fb0c14). By default, this maximum is set to 1 to optimize the process in the prevalent single-code cases.

#### WARNING
Be aware that setting `MaxNumCodes` to a value bigger than the number of codes in big images can make **EasyBarCode** slow, as it will keep trying to find codes that do not exist in the image.

* Each instance contains, among others, the [`decoded string`](../../../doxygen_cpp/classeVision_1_1EasyBarCode2_1_1EBarCode.html#a6212f783f14dad58a6461286c7009faf) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyBarCode2_1_1EBarCode.html#a670cc15ced8eee65eea93f0016804f2d) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyBarCode2_1_1EBarCode.html#aee7f712cb6932919c95e53ab9b7cefdc) embedded in the bar code.

#### NOTE
The relevant classes of the [`EasyBarCode`](../../../reference_manual/text_and_code_reading/easybarcode-library.html.md) library are stored in the namespace `EasyBarCode2`. Classes outside that namespace (refered to as `EasyBarCode1`) are an earlier version of the **EasyBarCode** library, now deprecated.

### C++

```cpp
#include <eVision/EasyBarCode/EasyBarCode2/EBarCodeReader.h>
```

```cpp
using namespace eVision;

// Image constructor
EImageBW8 srcImage;

// Bar code reader constructor
EasyBarCode2::EBarCodeReader reader;

// Set the max number of bar codes to find
reader.SetMaxNumCodes(6);

// Read the barcodes in the source image
std::vector<EasyBarCode2::EBarCode> results = reader.Read(srcImage);

// Get decoded string
std::string decodedString = results[0].GetDecodedString();
```

### C#

```cs
using eVision;
```

```cs
// Image constructor
EImageBW8 srcImage = new EImageBW8();

// Bar code reader constructor
eVision.EasyBarCode2.EBarCodeReader reader = new eVision.EasyBarCode2.EBarCodeReader();

// Set the max number of bar codes to find
reader.MaxNumCodes = 6;

// Read the bar codes in the source image
eVision.EasyBarCode2.EBarCode[] results = reader.Read(srcImage);

// Get decoded string
string decodedString = results[0].GetDecodedString();
```

### Python

```py
import eVision
from eVision import EasyBarCode2

# Image constructor
srcImage = eVision.EImageBW8()

# Bar code reader constructor
reader = EasyBarCode2.EBarCodeReader()

# Set the max number of bar codes to find
reader.MaxNumCodes = 6

# Read the bar codes in the source image
results = reader.Read(srcImage)

# Get decoded string
decodedString = results[0].GetDecodedString()
```

<a id="easybarcode2-contents"></a>

## Contents

How to use the **EasyBarCode** library.

How to use the **EasyBarCode** library to read mail bar codes.

How to use the first version of the **EasyBarCode** library, now deprecated.

<a id="easybarcode2-quick-links"></a>

## Quick Links

List of all Classes, Structs and Enumerations of the **EasyBarCode** library.

Code snippets for the **EasyBarCode** library.

All the code symbologies read by the text and code reading libraries.

Assess the printing quality of your bar, data matrix and QR codes.

Read bar, data matrix and QR codes using a unified interface.

#### SEE ALSO
Some **eVision Studio** samples illustrate several aspects of the **EasyBarCode** library:

* `Barcode reading`: Reads bar codes of diverse symbologies in images.
* `Barcode reading PDF417`: Reads bar codes of the PDF417 symbology in images.
* `Barcode reading PharmaCode`: Reads bar codes of Pharmacode symbology in images.
* `Barcode reading Gs1 DataBar Stacked`: Reads bar codes of the Gs1 DataBar Stacked symbology in images.
* `MailBarcode reading`: Reads mail bar codes.
