# Learning a Data Matrix Code

This code snippet shows how to learn from a given image, perform the reading and retrieve the decoded string.

## C++

```cpp
#include <eVision/EasyMatrixCode/EasyMatrixCode2/EMatrixCodeReader.h>
```

```cpp
using namespace eVision;
namespace EMC2 = eVision::EasyMatrixCode2;
// Load an image
EImageBW8 image;
image.Load("image.bmp");
// Prepare a matrix code reader
EMC2::EMatrixCodeReader reader;
// Learn from this image
reader.Learn(image);
// Read the codes in this image
reader.Read(image);

// Retrieve the detected codes
std::vector<EMC2::EMatrixCode> codes = reader.GetReadResults();
// Retrieve the decoded string of the first code
std::string result = codes[0].GetDecodedString();
```

#### SEE ALSO
[`EMatrixCodeReader::Read`](../../../../../doxygen_cpp/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#a890b23ec2a4a8396cb9c70eac513fc02) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#ad08f5fd519e6a442d9432e056833d764) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#abb1ad9145229c3dd52fe1b576099f6c6), [`EMatrixCodeReader::SetMaxNumCodes`](../../../../../doxygen_cpp/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#a4cd37bdc11e18ec343370b260c9afcaa) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#a34aa5cec2d24b4a5f7d4d6d8a0726dc1) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#aff01c9c7974d97f58b21720acb57e230), [`EMatrixCode::GetDecodedString`](../../../../../doxygen_cpp/classeVision_1_1EasyMatrixCode2_1_1EMatrixCode.html#a57f1437adadef93d74a5c93191564a3d) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EasyMatrixCode2_1_1EMatrixCode.html#a10faca778b3ddcc1fe29f5a2f74e9d40) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EasyMatrixCode2_1_1EMatrixCode.html#ae7719ab402a6994cc374c8d901bab2b6)

## C#

```cs
using eVision;
using EMC2 = eVision.EasyMatrixCode2;
```

```cs
// Load an image
EImageBW8 image = new EImageBW8();
image.Load("image.bmp");
// Prepare a matrix code reader
EMC2.EMatrixCodeReader reader = new EMC2.EMatrixCodeReader();
// Learn from this image
reader.Learn(image);
// Read the codes in this image
reader.Read(image);
// Retrieve the detected codes
EMC2.EMatrixCode[] codes = reader.ReadResults;
// Retrieve the decoded string of the first code
string result = codes[0].DecodedString;
```

#### SEE ALSO
[`EMatrixCodeReader.Read`](../../../../../doxygen_cs/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#ad08f5fd519e6a442d9432e056833d764) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#a890b23ec2a4a8396cb9c70eac513fc02) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#abb1ad9145229c3dd52fe1b576099f6c6), [`EMatrixCodeReader.MaxNumCodes`](../../../../../doxygen_cs/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#a34aa5cec2d24b4a5f7d4d6d8a0726dc1) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#afdd051ea8fe00c25dbe8122753b5c50a) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#aff01c9c7974d97f58b21720acb57e230), [`EMatrixCode.DecodedString`](../../../../../doxygen_cs/classeVision_1_1EasyMatrixCode2_1_1EMatrixCode.html#a10faca778b3ddcc1fe29f5a2f74e9d40) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EasyMatrixCode2_1_1EMatrixCode.html#a57f1437adadef93d74a5c93191564a3d) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EasyMatrixCode2_1_1EMatrixCode.html#ae7719ab402a6994cc374c8d901bab2b6)

## Python

```py
import eVision
from eVision import EasyMatrixCode2 as EMC2
# Load an image
image = eVision.EImageBW8()
image.Load("image.bmp")
# Prepare a matrix code reader
reader = EMC2.EMatrixCodeReader()
# Learn from this image
reader.Learn(image)
# Read the codes in this image
codes = reader.Read(image)
# Retrieve the decoded string of the first code
result = codes[0].DecodedString
```

#### SEE ALSO
[`EMatrixCodeReader.Read`](../../../../../doxygen_python/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#abb1ad9145229c3dd52fe1b576099f6c6) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#a890b23ec2a4a8396cb9c70eac513fc02) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#ad08f5fd519e6a442d9432e056833d764), [`EMatrixCodeReader.MaxNumCodes`](../../../../../doxygen_python/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#aff01c9c7974d97f58b21720acb57e230) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#afdd051ea8fe00c25dbe8122753b5c50a) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EasyMatrixCode2_1_1EMatrixCodeReader.html#a34aa5cec2d24b4a5f7d4d6d8a0726dc1), [`EMatrixCode.DecodedString`](../../../../../doxygen_python/classeVision_1_1EasyMatrixCode2_1_1EMatrixCode.html#ae7719ab402a6994cc374c8d901bab2b6) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EasyMatrixCode2_1_1EMatrixCode.html#a57f1437adadef93d74a5c93191564a3d) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EasyMatrixCode2_1_1EMatrixCode.html#a10faca778b3ddcc1fe29f5a2f74e9d40)
