# Line Fitting (Legacy)

This code snippet shows how to create a line measurement tool, adjust the transition parameters, set the nominal gauge position, perform the measurement and retrieve the result using the legacy EasyGauge API.

## C++

```cpp
#include <eVision/EasyGauge/Legacy/ELineGauge.h>
```

```cpp
using namespace eVision;
using namespace eVision::Legacy;
// Image constructor
EImageBW8 srcImage;
// ELineGauge constructor
Legacy::ELineGauge lineGauge;
// Adjust the transition parameters
lineGauge.SetTransitionType(ETransitionType_Bw);
lineGauge.SetTransitionChoice(ETransitionChoice_NthFromEnd);
lineGauge.SetTransitionIndex(2);
// Set the line fitting gauge position,
// length (50 units) and orientation (20)
EPoint center(256.f, 256.f);
Legacy::ELine line(center, 50.f, 20.f);
lineGauge.SetLine(line);
// Measure
lineGauge.Measure(&srcImage);
// Get the origin and end point coordinates of the fitted line
EPoint originPoint = lineGauge.GetMeasuredLine().GetOrg();
EPoint endPoint = lineGauge.GetMeasuredLine().GetEnd();
// Save the point gauge measurement context
lineGauge.Save("myLineGauge.gge");
```

## C#

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

```cs
// Image constructor
EImageBW8 srcImage = new EImageBW8();
// ELineGauge constructor
Legacy.ELineGauge lineGauge = new Legacy.ELineGauge();
// Adjust the transition parameters
lineGauge.TransitionType = ETransitionType.Bw;
lineGauge.TransitionChoice = ETransitionChoice.NthFromEnd;
lineGauge.TransitionIndex = 2;
// Set the line fitting gauge position,
// length (50 units) and orientation (20°)
EPoint center = new EPoint(256.0f, 256.0f);
Legacy.ELine line = new Legacy.ELine(center, 50.0f, 20.0f);
lineGauge.Line = line;
// Measure
lineGauge.Measure(srcImage);
// Get the origin and end point coordinates of the fitted line
EPoint originPoint = lineGauge.MeasuredLine.Org;
EPoint endPoint = lineGauge.MeasuredLine.End;
// Save the point gauge measurement context
lineGauge.Save("myLineGauge.gge");
```

## Python

```py
import eVision
import eVision.Legacy as Legacy
# Image constructor
src_image = eVision.EImageBW8()
# ELineGauge constructor
lineGauge = Legacy.ELineGauge()
# Adjust the transition parameters
lineGauge.TransitionType = eVision.ETransitionType.Bw
lineGauge.TransitionChoice = eVision.ETransitionChoice.NthFromEnd
lineGauge.TransitionIndex = 2
# Set the line fitting gauge position,
# length (50 units) and orientation (20°)
center = eVision.EPoint(256.0, 256.0)
line = eVision.ELine(center, 50.0, 20.0)
lineGauge.Line = line
# Measure
lineGauge.Measure(src_image)
# Get the origin and end point coordinates of the fitted line
originPoint = lineGauge.MeasuredLine.Org
endPoint = lineGauge.MeasuredLine.End
# Save the point gauge measurement context
lineGauge.Save("myLineGauge.gge")
```
