# EasyFindVectorLearn

| Support            | ![](assets/images/sample_programs/applies_to/cpp.svg) ![](assets/images/sample_programs/applies_to/cs.svg) ![](assets/images/sample_programs/applies_to/qt.svg) ![](assets/images/sample_programs/applies_to/python.svg)   |
|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Required licenses  | **EasyFind**                                                                                                                                                                                                               |
| Recommended images | Any gray level image from the folder `Sample Images/EasyFind`                                                                                                                                                              |
| Location           | `Matching and Measurement/EasyFindVectorLearn` and `Console samples/Matching and Measurement` *with Python*                                                                                                                |

## Purpose

**EasyFind** learns then finds patterns inside images.

This sample program demonstrates how to:

- Use with vectorized learning patterns. In this mode, learning is done on collections of 2D geometrical shapes rather than rasterized patterns.
- Open a DXF or vector model with File > Open Model. Right-click to change the polarity of a transition.
- Save the vector model with the edited polarity.
- Learn the pattern with the button Learn.
- Open a search image and find the pattern with the button Find .

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

## Code highlights

1. Define a model as a collection of shapes.
   ```c++
   EVectorModel vectorModel;
   ```
2. Load the vector model from a file.
   ```c++
   vectorModel.Load(fileName);
   ```
3. Load the vector model from a DXF file.
   ```c++
   vectorModel.LoadDXF(fileName);
   ```
4. Set the scale of the vector model with respect to the search image.
   ```c++
   vectorModel.GetRoot().GetWorldShape()->SetScale(fScale);
   ```
5. Set the polarity of any shape in the vector model.
   ```c++
   shape.SetProperty("polarity", "direct");
   ```
6. Learn a vector pattern.
   ```c++
   patternfinder.Learn(vectorModel);
   ```
7. Find the pattern that you previously learned inside the image. Retrieve the results as a vector of `EFoundPatterns`.
   ```c++
   std::vector<EFoundPattern> foundPatterns = patternfinder.Find(image);
   ```
8. Draw the vector model and show the polarity as arrows pointing from a dark to light transition.
   ```c++
   vectorModel.Draw(...);
   ```
9. Draw a found pattern in the same reference frame as the search image.
   ```c++
   foundPatterns[n].Draw(...);
   ```
