# Line Fitting

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.

## C++

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

```cpp
using namespace eVision;
// Image constructor
EImageBW8 srcImage;
// ELineGauge constructor
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);
ELine line(center, 50.f, 20.f);
lineGauge.SetLine(line);
try
{
  // Measure
  ELine measured = lineGauge.Measure(srcImage);
  // Get the origin and end point coordinates of the fitted line
  EPoint originPoint = measured.GetOrg();
  EPoint endPoint = measured.GetEnd();
}
catch (const EException& e)
{
  // The line was not found.
}
// Save the line gauge measurement context
lineGauge.Save("myLineGauge.gge");
```

## C#

```cs
using eVision;
```

```cs
// Image constructor
EImageBW8 srcImage = new EImageBW8();
// ELineGauge constructor
ELineGauge lineGauge = new 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);
ELine line = new ELine(center, 50.0f, 20.0f);
lineGauge.Line = line;
try
{
  // Measure
  ELine measured = lineGauge.Measure(srcImage);
  // Get the origin and end point coordinates of the fitted line
  EPoint originPoint = measured.Org;
  EPoint endPoint = measured.End;
}
catch (EException e)
{
  // The line was not found
}
// Save the line gauge measurement context
lineGauge.Save("myLineGauge.gge");
```

## Python

```py
import eVision
# Image constructor
src_image = eVision.EImageBW8()
# ELineGauge constructor
lineGauge = eVision.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
try:
    # Measure
    measured = lineGauge.Measure(src_image)
    # Get the origin and end point coordinates of the fitted line
    originPoint = measured.Org
    endPoint = measured.End
except eVision.EException:
    # The line was not found.
    pass
# Save the line gauge measurement context
lineGauge.Save("myLineGauge.gge")
```
