# EasyObjectEChecker2

| Support            | ![](assets/images/sample_programs/applies_to/cpp.svg) ![](assets/images/sample_programs/applies_to/cs.svg)   |
|--------------------|--------------------------------------------------------------------------------------------------------------|
| Required licenses  | **EasyObject**                                                                                               |
| Recommended images | Any image from the folder `Sample Images/EasyObject/Fiducial`                                                |
| Location           | `Matching and Measurement/EasyObjectEChecker2`                                                               |

## Purpose

**EChecker2** is a golden template inspection algorithm.

This sample program demonstrates how to:

- Specify the inspection area.
- Select fiducials for the localization and the alignment of the inspection area.
- Train the method and apply it on new images.

![](assets/images/sample_programs/matching-easyobjectechecker2.webp)

## Code highlights

1. Initialize an object with a reference image, a vector of `ERegion` corresponding to the fiducials and an `ERegion` corresponding to the region to inspect.
   ```c++
   // Put fiducial regions in vector
   std::vector<ERegion*> fiducials;
   fiducials.push_back(regions_[RegionID_Fiducial1]);
   fiducials.push_back(regions_[RegionID_Fiducial2]);

   // Initialize training
   checker_.Initialize(referenceImage_, fiducials, *(regions_[RegionID_Inspection]));
   ```
2. Train the checker with a vector of training images.

#### ATTENTION
As all the parameters of `EChecker` have an influence on how the model is built, you must restart the model creation if any of these parameters is changed.

```none
```c++
// Train
checker_.SetInspectionTolerance(5.0f);
checker_.Train(images);
```
```

1. Inspect an image and filter the list of defects based on their area.

The result of a `EChecker` inspection is an object `EasyObject ECodedImage2`.

```none
```c++
// Inspect Image
checker_.Inspect(image, codedImage_);

// Clear defect selection
defects_.Clear();

// Select defects on area
defects_.AddObjects(codedImage_);
defects_.RemoveUsingUnsignedIntegerFeature(EFeature_Area, 25, ESingleThresholdMode_Less);
```
```
