<a id="learn-model-from-image"></a>

# Learn a Pattern from Image(s)

* **EasyFind** can extract its feature points from an image using [`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).
* The most common usage is to take a picture of the object of interest and to learn the ROI around that object in your picture.
* Use an `ERegion` to specify your pattern more precisely if the ROI contains unwanted features from the background.

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

## Learn Multiple Patterns from different images

With **EasyFind**, you can also learn multiple patterns at once.

#### NOTE
This is useful when different instances of the pattern look very different, for example because of perspective, illumination or mechanical deformations.

![image](assets/images/easyfind/studio2/learn_multiple_models_1.webp)![image](assets/images/easyfind/studio2/learn_multiple_models_2.webp)

To learn multiple patterns:

1. Call the function [`EPatternFinder::LearnPatterns`](../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#ac8f0f7ed926cb5d81c2880ebb3c75627) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPatternFinder.html#a0ff7206f1670e79980df1461b4d8cc17) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPatternFinder.html#aa725ed6ea3793328f7b004ff77e9c2b6) with several images instead of the function [`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) with a single image.
2. When you call [`EPatternFinder::Find`](../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#aeeb160cde9343ffc0d8583ac1d330e4d) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPatternFinder.html#a9c35c544243729d9907eb708f7d2a0e2) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPatternFinder.html#a44780e599d160cbb5f8e405042ace771), the patterns are searched in the image in parallel.

#### NOTE
The setting [`Easy::SetMaxNumberOfProcessingThreads`](../../../doxygen_cpp/classeVision_1_1Easy.html#a07daba7dfbeff40db5e1d9e4404d4722) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1Easy.html#ae729364026373ca376e818d4b82cd978) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1Easy.html#ae819b646aea6778997c6155442a0ccee) is thus especially interesting here.

<a id="learning-parameters"></a>

## Learning Parameters

#### NOTE
These parameter settings are saved together with your pattern when calling [`EPatternFinder::Save()`](../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#a3ddbf43b156cb45b118443a008114476) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPatternFinder.html#a3403566929562299303a8886266d55b1) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPatternFinder.html#a2beed216e07043da35102d6e6a12bbdf).

<a id="pattern-type"></a>

### Pattern type

Use the parameter [`EPatternFinder::SetPatternType`](../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#ab42047678f7eb4221c3f25435b154829) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPatternFinder.html#aa90d0e01f369508bb7fc071a127a1601) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPatternFinder.html#a8b3bdd20a6e3e4a7da15f06c2594a031) to set the pattern type as `Consistent Edges` (default) or `Thin Structures`.

**EasyFind** supports 2 pattern types:

* Use `Consistent Edges` when:
  - Your pattern is well contrasted with sharp edges.
  - Your pattern is substantially different from the rest of the expected search fields.
* Use `Thin Structures` when:
  - The edges of your pattern are consistent between thin elements and regions.
  - The contrast is the same for each thin element.

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

<a id="light-balance"></a>

### Light Balance

Use the parameter [`EPatternFinder::SetLightBalance`](../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#a0b47f1d453678b0b084a605f2b5da820) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPatternFinder.html#a6e28c55d85e505687c02b282c6d80fab) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPatternFinder.html#a956ec70bfbd2a883a5014bbacf095711) to adjust the gray-level threshold of the `EPatternFinder` so that it fits the useful parts of the pattern.

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

### Timeout

[`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) possesses a timeout:

* Use [`EPatternFinder::SetLearnTimeOut`](../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#ab209638098a5def6bfaa50f97c09b897) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPatternFinder.html#a75db9eff2405530cd2da89641a7fadf6) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPatternFinder.html#ab068c87596d1a389ed35e42aec1c85e6) to add a time limit to the methods [`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) and [`EPatternFinder::LearnPatterns`](../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#ac8f0f7ed926cb5d81c2880ebb3c75627) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPatternFinder.html#a0ff7206f1670e79980df1461b4d8cc17) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPatternFinder.html#aa725ed6ea3793328f7b004ff77e9c2b6).
* If the timeout is reached, an exception is thrown and the processing stops.

#### NOTE
This timeout mechanism is used to prevent the application from freezing while tuning parameters. This is especially useful in **eVision Studio**. Note that this does not correspond to the behavior of code reader timeouts, which aim to prevent long processing times in production settings.

<a id="learning-advanced-params"></a>

### Advanced

<a id="thin-structure"></a>

#### Thin Structure Mode

If the `Pattern Type` is `Thin Structure`, use the parameter [`EPatternFinder::SetThinStructureMode`](../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#a42a5eacbcbd367d9421a7c0ce4335a94) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPatternFinder.html#a041d5362e4f6fe0a76374ee2c2af3208) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPatternFinder.html#a9ec4a92f7a9d296484cd554edb189646) to adjust the gray-level threshold of the model so that it fits the useful parts of the pattern:

* [`EThinStructureMode_Auto`](../../../doxygen_cpp/namespaceeVision.html#a32917f04948e62d8e2ce9179c48e08b3a50b43d0b58ee39b8089a426c9069ee70) [<sub>.NET</sub>](../../../doxygen_cs/namespaceeVision.html#a21e546817586c406ace193d5f2b1815b) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EThinStructureMode.html#a0b7f71203196b5d121a92c451effa640): **EasyFind** chooses automatically the best contrast for thin elements.
* [`EThinStructureMode_Dark`](../../../doxygen_cpp/namespaceeVision.html#a32917f04948e62d8e2ce9179c48e08b3a1686135cb252740b19005e6a682b9f4b) [<sub>.NET</sub>](../../../doxygen_cs/namespaceeVision.html#a21e546817586c406ace193d5f2b1815b) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EThinStructureMode.html#ac7148b166d98a51d52d0af56666e2c31): **EasyFind** selects thin elements darker than their neighborhood.
* [`EThinStructureMode_Bright`](../../../doxygen_cpp/namespaceeVision.html#a32917f04948e62d8e2ce9179c48e08b3ade2e245fd1c4cfcf9dd9e57e6f4ef986) [<sub>.NET</sub>](../../../doxygen_cs/namespaceeVision.html#a21e546817586c406ace193d5f2b1815b) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EThinStructureMode.html#a385f2bf09ccef833b040dfd7ac4d439a): **EasyFind** selects thin elements brighter than their neighborhood.

<a id="number-feature-points-reduction-strength"></a>

#### Number of Feature Points and Reduction Strength

#### NOTE
More feature points lead to a finer matching and a better positioning accuracy but also to a longer processing time.

* Use the parameters [`EPatternFinder::SetMinFeaturePoints`](../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#ae5dc0bf832012bb314886f6ed28c1e77) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPatternFinder.html#af0c4dabd5fe9974aaf3a19f19148910b) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPatternFinder.html#a48befb2319d7c19667409ea392265839) and [`EPatternFinder::SetMaxFeaturePoints`](../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#a7bdc9b8bc8217848337fc484e471cd55) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPatternFinder.html#adec669fb1a9def5908c4516263771423) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPatternFinder.html#a0470ce20bd3f6d5ddd47d9368f2719b5) to adjust the number of feature points used to match the patterns.
  - By default, this number is computed automatically (between `8` and `1024`).
* Use the parameter [`EPatternFinder::SetReductionMode`](../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#a2cd0f129f3ab02bbb41ae4a7f39613e9) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPatternFinder.html#a63741c7ee26a5981bcf3f3b1de5b9f85) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPatternFinder.html#a28e7dd6ff90ec4e0a49497cd40c64f44) to select the reduction mode:
  - [`EReductionMode_Auto`](../../../doxygen_cpp/namespaceeVision.html#aad0c642f5795e81c386b9444080a749ca43ac5b040c6c0187723618031d6299a1) [<sub>.NET</sub>](../../../doxygen_cs/namespaceeVision.html#a2a58bfe19d503a718bfd33405964d4ba) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EReductionMode.html#a0391aa44d7671b5b546e4f59f9aa829c) (default): the reduction strength is computed automatically.
  - [`EReductionMode_Manual`](../../../doxygen_cpp/namespaceeVision.html#aad0c642f5795e81c386b9444080a749cacf86baf7e9b9b210f08f2364690ecfc7) [<sub>.NET</sub>](../../../doxygen_cs/namespaceeVision.html#a2a58bfe19d503a718bfd33405964d4ba) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EReductionMode.html#ac1d43cfa976335a67fc2006c5421bc4e): use the parameter [`EPatternFinder::SetReductionStrength`](../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#a4712e171e7edb99a0e01ace9ed210c78) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPatternFinder.html#a54061154000780cf4824b581f20178d7) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPatternFinder.html#a4370d6f0cb096c1014b129550a360807) to set the reduction strength from more accuracy (`0.0`) to more speed (`1.0`).
