# Learning Using an EPolygonShape (Legacy)

This code snippet shows how to perform pattern learning and finding operations using legacy EPolygonShape to define the model.

## C++

```cpp
#include <eVision/EasyFind/EPatternFinder.h>
#include <eVision/EasyGauge/Legacy/EPolygonShape.h>
```

```cpp
using namespace eVision;
using namespace eVision::Legacy;
// 1. Create an EPatternFinder instance for the model
EPatternFinder finder;

// 2. Create you vector model and get its root shape
EVectorModel myModel;
Legacy::EFrameShape& shapeMother = myModel.GetRoot();

// 3. Create your polygon
Legacy::EPolygonShape polygon;
std::vector<EPoint> vertices = { {0.f, 0.f}, {1.f, 0.f}, {1.f, 1.f}, {0.f, 1.f} };
polygon.SetPolygon(Legacy::EPolygon(vertices, true));

// 4. Attach the polygon to the root shape and adjust its parameters according to your application and needs.
polygon.Attach(&shapeMother);
polygon.SetProperty("polarity", "direct");

// 5. Learn the model
finder.Learn(myModel);

// 6. If you want to reuse it later, save the new model (.fnd file).
// finder.Save("myModel.fnd");

// 7. Find the pattern in an image
EImageBW8 srcImage;
// srcImage.Load(...);
std::vector<EFoundPattern> foundPattern = finder.Find(&srcImage);
```

#### SEE ALSO
[`EPolygonShape::SetPolygon`](../../../../../doxygen_cpp/classeVision_1_1Legacy_1_1EPolygonShape.html#aed799d8a860960749c6eef2cebb1a70f) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1Legacy_1_1EPolygonShape.html#aa7fdf66e5dec57cbdc67f34689bfe91e) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1Legacy_1_1EPolygonShape.html#a7120dc5587ba2b3b08c6c00c642145a6), [`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)

## C#

```cs
using eVision;
using Legacy = eVision.Legacy;
```

```cs
// 1. Create an EPatternFinder instance for the model
EPatternFinder finder = new EPatternFinder();

// 2. Create you vector model and get its root shape
EVectorModel myModel = new EVectorModel();
Legacy.EFrameShape root = myModel.Root;

// 3. Create your polygon
Legacy.EPolygonShape polygon = new Legacy.EPolygonShape();
EPoint[] vertices = new EPoint[] { new EPoint(0, 0), new EPoint(1, 0),
  new EPoint(1, 1), new EPoint(0, 1) };
Legacy.EPolygon basePolygon = new Legacy.EPolygon(vertices, true);
polygon.Polygon = basePolygon;

// 4. Attach the polygon to the root shape and adjust its parameters according to your application and needs.
polygon.Attach(root);
polygon.SetProperty("polarity", "direct");

// 5. Learn the model
finder.Learn(myModel);

// 6. If you want to reuse it later, save the new model (.fnd file).
// finder.Save("myModel.fnd");

// 7. Find the pattern in an image
EImageBW8 srcImage = new EImageBW8();
// srcImage.Load(...);
EFoundPattern[] foundPattern = null;
foundPattern = finder.Find(srcImage);
```

#### SEE ALSO
[`EPolygonShape.Polygon`](../../../../../doxygen_cs/classeVision_1_1Legacy_1_1EPolygonShape.html#aa7fdf66e5dec57cbdc67f34689bfe91e) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1Legacy_1_1EPolygonShape.html#a39039b4ae3be95b54c4f9fff479b4772) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1Legacy_1_1EPolygonShape.html#a7120dc5587ba2b3b08c6c00c642145a6), [`EPatternFinder.Find`](../../../../../doxygen_cs/classeVision_1_1EPatternFinder.html#a9c35c544243729d9907eb708f7d2a0e2) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#aeeb160cde9343ffc0d8583ac1d330e4d) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EPatternFinder.html#a44780e599d160cbb5f8e405042ace771)

## Python

```py
import eVision
import eVision.Legacy as Legacy
# 1. Create an EPatternFinder instance for the model
finder = eVision.EPatternFinder()

# 2. Create you vector model and get its root shape
my_model = eVision.EVectorModel()
root = my_model.Root

# 3. Create your polygon
polygon = Legacy.EPolygonShape()
vertices = [eVision.EPoint(0, 0), eVision.EPoint(1, 0),
  eVision.EPoint(1, 1), eVision.EPoint(0, 1)]
base_polygon = Legacy.EPolygon(vertices, True)
polygon.Polygon = base_polygon

# 4. Attach the polygon to the root shape and adjust its parameters according to your application and needs.
polygon.Attach(root)
polygon.SetProperty("polarity", "direct")

# 5. Learn the model
finder.Learn(my_model)

# 6. If you want to reuse it later, save the new model (.fnd file).
# finder.Save("myModel.fnd")

# 7. Find the pattern in an image
src_image = eVision.EImageBW8()
# srcImage.Load(...);
found_pattern = finder.Find(src_image)
```

#### SEE ALSO
[`EPolygonShape.Polygon`](../../../../../doxygen_python/classeVision_1_1Legacy_1_1EPolygonShape.html#a7120dc5587ba2b3b08c6c00c642145a6) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1Legacy_1_1EPolygonShape.html#a39039b4ae3be95b54c4f9fff479b4772) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1Legacy_1_1EPolygonShape.html#aa7fdf66e5dec57cbdc67f34689bfe91e), [`EPatternFinder.Find`](../../../../../doxygen_python/classeVision_1_1EPatternFinder.html#a44780e599d160cbb5f8e405042ace771) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EPatternFinder.html#aeeb160cde9343ffc0d8583ac1d330e4d) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EPatternFinder.html#a9c35c544243729d9907eb708f7d2a0e2)
