<a id="learn-from-vectors"></a>

# Learn a Pattern from Vectors

<a id="learning-from-vectors"></a>

## Learning

**EasyFind** detects the instances of a pattern in images.

* The reference pattern is a set of all the feature points that **EasyFind** computes during the learning process:
  - **EasyFind** can extract these points from a bitmap representation of the pattern (see [Learn the Pattern from Image(s)](learning.html.md)).
  - Or it can use the feature points that are directly given by geometrical shapes as described below.
* To learn a pattern from geometrical shapes:
  - Use the class [`EVectorModel`](../../../doxygen_cpp/classeVision_1_1EVectorModel.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EVectorModel.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EVectorModel.html) to hold a collection of shapes as a vector model.
  - Load the `EVectorModel` from an external `dxf` file or use the **eVision** API to define it.
  - that `EVectorModel` object is then input to [`EPatternFinder::Learn`](../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#aa9de4e652c3d71bc83dda008fcf9ecc1) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPatternFinder.html#aeee399ee9d9ba5e2d5e8b30094bd5bf3) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPatternFinder.html#a4c2c47cfc0bd7de1d0a02b3f03414d59).

![image](assets/images/easyfind/learn_from_a_vector_model.webp)

<a id="learn-shape"></a>

### Learn a set of EShape

#### NOTE
Creating an `EVectorModel` from a set of `EShape` is not available in **eVision Studio**, but loading a `dxf` file is.

* To define the geometrical shapes of your model, you can directly define [`ELine`](../../../doxygen_cpp/classeVision_1_1Legacy_1_1ELine.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1Legacy_1_1ELine.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1Legacy_1_1ELine.html), [`EPolygon`](../../../doxygen_cpp/classeVision_1_1Legacy_1_1EPolygon.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1Legacy_1_1EPolygon.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1Legacy_1_1EPolygon.html) and [`ECircle`](../../../doxygen_cpp/classeVision_1_1Legacy_1_1ECircle.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1Legacy_1_1ECircle.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1Legacy_1_1ECircle.html).
* These shapes must be attached to [`EVectorModel::GetRoot()`](../../../doxygen_cpp/classeVision_1_1EVectorModel.html#a5873c86a36af206330a3bc3a9fa644cf) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EVectorModel.html#ae5ab8d320e29d426c7cd7852ab672d1a) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EVectorModel.html#a915f7d164ba1c062474f77f3d358541b).
* Each shape must potentially be [oriented]().

#### SEE ALSO
<svg version="1.1" width="1.0em" height="1.0em" class="sd-octicon sd-octicon-file-code sd-mr-1" viewBox="0 0 16 16" aria-hidden="true"><path d="M4 1.75C4 .784 4.784 0 5.75 0h5.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v8.586A1.75 1.75 0 0 1 14.25 15h-9a.75.75 0 0 1 0-1.5h9a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 10 4.25V1.5H5.75a.25.25 0 0 0-.25.25v2.5a.75.75 0 0 1-1.5 0Zm1.72 4.97a.75.75 0 0 1 1.06 0l2 2a.75.75 0 0 1 0 1.06l-2 2a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734l1.47-1.47-1.47-1.47a.75.75 0 0 1 0-1.06ZM3.28 7.78 1.81 9.25l1.47 1.47a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-2-2a.75.75 0 0 1 0-1.06l2-2a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042Zm8.22-6.218V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"></path></svg> [Code snippet illustrating the usage of an `EPolygonShape` to define the `EVectorModel`](../../../resources/code_snippets/matching_and_measurement/easyfind/legacy/patternlearningandfindingwithshapeslegacy.html.md).

<a id="learn-dxf"></a>

### Learn a dxf file

#### NOTE
This feature is available in **eVision Studio**.

Alternatively, to define the geometrical shapes of your model, you can load an [`EVectorModel`](../../../doxygen_cpp/classeVision_1_1EVectorModel.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EVectorModel.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EVectorModel.html) from an external `dxf` file.

Once loaded, the [`EVectorModel`](../../../doxygen_cpp/classeVision_1_1EVectorModel.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EVectorModel.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EVectorModel.html):

* Holds a collection of shapes.
* Holds a center position depending on the method used for the definition of the `dxf`.
* Each shape must potentially still be [oriented]().

#### SEE ALSO
<svg version="1.1" width="1.0em" height="1.0em" class="sd-octicon sd-octicon-file-code sd-mr-1" viewBox="0 0 16 16" aria-hidden="true"><path d="M4 1.75C4 .784 4.784 0 5.75 0h5.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v8.586A1.75 1.75 0 0 1 14.25 15h-9a.75.75 0 0 1 0-1.5h9a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 10 4.25V1.5H5.75a.25.25 0 0 0-.25.25v2.5a.75.75 0 0 1-1.5 0Zm1.72 4.97a.75.75 0 0 1 1.06 0l2 2a.75.75 0 0 1 0 1.06l-2 2a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734l1.47-1.47-1.47-1.47a.75.75 0 0 1 0-1.06ZM3.28 7.78 1.81 9.25l1.47 1.47a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-2-2a.75.75 0 0 1 0-1.06l2-2a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042Zm8.22-6.218V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"></path></svg> [Code snippet illustrating the creation of a `EVectorModel` from a `dxf` file](../../../resources/code_snippets/matching_and_measurement/easyfind/patternlearningandfindingwithdxf.html.md).

<a id="vector-model-parameters"></a>

## Vector Model Parameters

<a id="scaling-vector-model"></a>

### Scaling the Vector Model

* Use the parameter [`EVectorModel::SetScale`](../../../doxygen_cpp/classeVision_1_1EVectorModel.html#a4bb938306269e89a89735c66835e5866) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EVectorModel.html#a07cc88a178687803920a6ca694a48935) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EVectorModel.html#a775df1dca595bb9a4ad483c109913db1) to set the scale of your vector model.
  - The scale represents the size of the instances in the search field (in pixels) divided by their size in the [`EVectorModel`](../../../doxygen_cpp/classeVision_1_1EVectorModel.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EVectorModel.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EVectorModel.html).

![image](assets/images/easyfind/learning_process_03.svg)

<a id="centering-vector-model"></a>

### Centering the Vector Model

* Use the parameter [`EVectorModel::SetCenter`](../../../doxygen_cpp/classeVision_1_1EVectorModel.html#a2e63995af422e8fc2a96a39b27827e5d) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EVectorModel.html#a0afb51d9b42589e1b66e42752817fb1d) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EVectorModel.html#a6d091744233f27c30d06d906f9e977f9) to set or get the center of your vector model.
  - The center is the anchor point in the [`EVectorModel`](../../../doxygen_cpp/classeVision_1_1EVectorModel.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EVectorModel.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EVectorModel.html) coordinate system.
  - After the `Find`, you can retrieve its position in the search field coordinates as illustrated below.

![image](assets/images/easyfind/learning_process_04.svg)

<a id="orienting-transitions"></a>

### Orienting the Transitions in the Vector Model

* To search for light to dark or dark to light transitions, set the polarity attribute for the vector model with the [`EShape::SetProperty`](../../../doxygen_cpp/classeVision_1_1Legacy_1_1EShape.html#a024d43df0f94b798ddc9c0ab58e0f4bd) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1Legacy_1_1EShape.html#ad2be7d6d49abdd30ea4a6100d7729f04) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1Legacy_1_1EShape.html#afc6b44a590701ba88fb7d1a97b8da8e7) method.

![image](assets/images/easyfind/learning_process_05.svg)

<a id="orienting-transitions-code"></a>

#### Code

Sets the polarity of one of the `EShape` composing an `EVectorModel`.

### C++

```c++
Legacy::EFrameShape& vectorModelRoot = vectorModel.GetRoot();
vectorModelRoot.GetDaughter(0)->SetProperty("polarity", "direct");
```

### C#

```c#
Euresys.Open_eVision.Legacy.EFrameShape vectorModelRoot = vectorModel.Root;
vectorModelRoot.GetDaughter(0).SetProperty("polarity", "direct");
```

### Python

```python
vectorModelRoot = vectorModel.Root
vectorModelRoot.GetDaughter(0).SetProperty("polarity", "direct")
```

#### NOTE
We recommend tuning this graphically in **eVision Studio** rather than through the API. You can have a look at the sample “Find a vector pattern” specifically.
