# Using the Object Template Matcher

This code snippet shows how to use EObjectTemplateMatcher for alignment and template matching.

## C++

```cpp
#include <eVision/EasyObject/EasyObject2/EImageEncoder.h>
#include <eVision/EasyObject/EasyObject2/EObjectTemplateMatcher.h>
```

```cpp
using namespace eVision;

// Encode the template image
EImageEncoder encoder;
ECodedImage2 coded_img;

EImageBW8 template_img;
encoder.Encode(template_img, coded_img);

// Initialize EObjectTemplateMatcher
EObjectTemplateMatcher object_sort;
object_sort.SetAlignment(EObjectTemplateMatcherAlignment_Fast); // optional
object_sort.SetMaximumDistance(60);   // optional

// set the template
object_sort.BuildTemplate(coded_img);

// Encode the test image
EImageBW8 test_img;
encoder.Encode(test_img, coded_img);

// Build a selection of test objects
EObjectSelection object_select;
object_select.AddObjects(coded_img);
object_select.RemoveUsingUnsignedIntegerFeature(EFeature_Area, 10, ESingleThresholdMode_Less);  // optional filter

// Perform the alignment and the matching
object_sort.Match(object_select);

// Display the number of matches
std::cout << object_sort.GetNumberOfPairedObjects() << " paired objects" << std::endl;

// Retrieve the template indexes for each selection object
std::vector<int> template_indexes = object_sort.GetTemplateIndexes();
```

#### SEE ALSO
[`EObjectTemplateMatcher`](../../../../doxygen_cpp/classeVision_1_1EObjectTemplateMatcher.html) [<sub>.NET</sub>](../../../../doxygen_cs/classeVision_1_1EObjectTemplateMatcher.html) [<sub>Python</sub>](../../../../doxygen_python/classeVision_1_1EObjectTemplateMatcher.html)

## C#

```cs
using eVision;
```

```cs
// Encode the template image
EImageEncoder encoder = new EImageEncoder();
ECodedImage2 coded_img = new ECodedImage2();

EImageBW8 template_img = new EImageBW8();
encoder.Encode(template_img, coded_img);

// Initialize EObjectTemplateMatcher
EObjectTemplateMatcher object_sort = new EObjectTemplateMatcher();
object_sort.Alignment = EObjectTemplateMatcherAlignment.Fast; // optional
object_sort.MaximumDistance = 60;   // optional

// set the template
object_sort.BuildTemplate(coded_img);

// Encode the test image
EImageBW8 test_img = new EImageBW8();
encoder.Encode(test_img, coded_img);

// Build a selection of test objects
EObjectSelection object_select = new EObjectSelection();
object_select.AddObjects(coded_img);
object_select.RemoveUsingUnsignedIntegerFeature(EFeature.Area, 10, ESingleThresholdMode.Less);  // optional filter

// Perform the alignment and the matching
object_sort.Match(object_select);

// Get the number of matches
int num = object_sort.NumberOfPairedObjects;

// Retrieve the template indexes for each selection object
int[] template_indexes = object_sort.TemplateIndexes;
```

#### SEE ALSO
[`EObjectTemplateMatcher`](../../../../doxygen_cs/classeVision_1_1EObjectTemplateMatcher.html) [<sub>C++</sub>](../../../../doxygen_cpp/classeVision_1_1EObjectTemplateMatcher.html) [<sub>Python</sub>](../../../../doxygen_python/classeVision_1_1EObjectTemplateMatcher.html)

## Python

```py
import eVision
# Encode the template image
encoder = eVision.EImageEncoder()
coded_img = eVision.ECodedImage2()

template_img = eVision.EImageBW8()
encoder.Encode(template_img, coded_img)

# Initialize EObjectTemplateMatcher
object_sort = eVision.EObjectTemplateMatcher()
object_sort.Alignment = eVision.EObjectTemplateMatcherAlignment.Fast # optional
object_sort.MaximumDistance = 60   # optional

# set the template
object_sort.BuildTemplate(coded_img)

# Encode the test image
test_img = eVision.EImageBW8()
encoder.Encode(test_img, coded_img)

# Build a selection of test objects
object_select = eVision.EObjectSelection()
object_select.AddObjects(coded_img)
object_select.RemoveUsingUnsignedIntegerFeature(eVision.EFeature.Area, 10, eVision.ESingleThresholdMode.Less) # optional filter

# Perform the alignment and the matching
object_sort.Match(object_select)

# Get the number of matches
num = object_sort.NumberOfPairedObjects

# Retrieve the template indexes for each selection object
template_indexes = object_sort.TemplateIndexes
```

#### SEE ALSO
[`EObjectTemplateMatcher`](../../../../doxygen_python/classeVision_1_1EObjectTemplateMatcher.html) [<sub>C++</sub>](../../../../doxygen_cpp/classeVision_1_1EObjectTemplateMatcher.html) [<sub>.NET</sub>](../../../../doxygen_cs/classeVision_1_1EObjectTemplateMatcher.html)
