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++

#include <eVision/EasyMatrixCode/EasyMatrixCode2/EMatrixCodeReader.h>
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();

C#

using eVision;
using EMC2 = eVision.EasyMatrixCode2;
// 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;

Python

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