# Frames and Alignment

## Reference frames

In some cases, it can be useful to express the parameter or the result of a processing in a reference frame (a system of coordinates):

* To use the same set of parameters with different reference frame (automatic alignment).
* To express a result with respect to that reference frame.
  ![image](assets/images/easygauge/frameexample.jpg)
* In **eVision**, reference frames are represented by the class [`EFrame`](../../doxygen_cpp/classeVision_1_1EFrame.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EFrame.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EFrame.html). An [`EFrame`](../../doxygen_cpp/classeVision_1_1EFrame.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EFrame.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EFrame.html) object encodes a *local* reference frame through its center, angle and scale along the x and y axis with respect to the *world* reference frame.
  * The *world* reference frame is the reference frame defined by a calibration (object [`ECameraCalibration`](../../doxygen_cpp/classeVision_1_1ECameraCalibration.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1ECameraCalibration.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1ECameraCalibration.html), see [Camera Calibration](../advanced_operations/camera_calibration/index.html.md)).
  * An *affine transformation* is a transformation that links the coordinates of a point expressed in the local reference frame to its coordinates in the real world. This means that lines and parallelism are preserved. A frame with a center of (0, 0), an angle equal to 0 and scales equal to 1 is equivalent to the *world* frame.
* The [`EFrame`](../../doxygen_cpp/classeVision_1_1EFrame.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EFrame.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EFrame.html) object can also map to the *sensor* reference frame.
  * The *sensor* reference frame is the reference frame in which pixel coordinate are expressed.
  * It is centered on the top-left of the image with the x axis going right and the y axis going down.
  * Some methods or objects only support affine transformations from the sensor to the local reference frame ([`EFrame::IsLocalToSensorAffine`](../../doxygen_cpp/classeVision_1_1EFrame.html#aa55c1d5eaae377b29abc9f01842d336d) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EFrame.html#a0c3b1d2b354994f584ec8659b378851e) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EFrame.html#ae50f2dd51275fcf4a850f5ea62ee05d1)). This means that there must not be any camera calibration associated with the frame or that the camera calibration must also be affine. If your image has perspective effects or distortions, you can unwarp the image before using it in combination with a frame.
  * If the frame has no calibration ([`EFrame::IsCalibrated`](../../doxygen_cpp/classeVision_1_1EFrame.html#ac9fd2f9c4c09728b785aaae19cb12ff4) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EFrame.html#ab8106ad52d9b2f7ccaff7a29717b0f77) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EFrame.html#aa80877368650524c8ce82b1ddf49d283) is `false`), the *world* and *sensor* reference frames are the same.

Here are several examples of frames:

| Local frame   | Calibration   | Equivalence            | Image                                                           |
|---------------|---------------|------------------------|-----------------------------------------------------------------|
| Default       | no            | world = sensor = local | ![image](assets/images/easygauge/defaultframenocalibration.jpg) |
| Custom        | no            | world = sensor         | ![image](assets/images/easygauge/customframenocalibration.jpg)  |
| Default       | yes           | world = local          | ![image](assets/images/easygauge/defaultframecalibrated.jpg)    |
| Custom        | yes           | none                   | ![image](assets/images/easygauge/customframecalibrated.jpg)     |
* The parameters of a frame are always encoded with respect to the *world* reference frame.
* However, it is still possible to express these parameters with respect to another frame when constructing the frame using `EFrame(parent, centerX, centerY, angle, scaleX, scaleY)` ([`EFrame`](../../doxygen_cpp/classeVision_1_1EFrame.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EFrame.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EFrame.html)):
  * In this case, [`EFrame::GetCenterX`](../../doxygen_cpp/classeVision_1_1EFrame.html#aad14349672deb3040bc31cba57c3d4a2) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EFrame.html#a5e04e7d7330dc9e025096e661edcdd65) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EFrame.html#a47b3aeb29f18f051e6456d751bb70964) can be different than the specified `centerX`.
  * You can also use the method [`EFrame::WorldToLocal`](../../doxygen_cpp/classeVision_1_1EFrame.html#a68a47885e74bc75eb5244cd09a87a47a) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EFrame.html#aea900ccd2db8199cc53bbca398b31706) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EFrame.html#a4ed697b504e470acda84f5dd77f1ea02) to compute the relationship between two frames to use one of the two frames as the *world* reference frame of the other.

## Mapping between local, world and sensor frames

You can use the methods [`EFrame::LocalToWorld`](../../doxygen_cpp/classeVision_1_1EFrame.html#a3b5a94b339847fd86fe391126c07080e) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EFrame.html#aca1e2a0c03a747d25f4a9b08b88e084b) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EFrame.html#a65728fb16b8234ad83bb420cf955335a), [`EFrame::LocalToSensor`](../../doxygen_cpp/classeVision_1_1EFrame.html#a11dc2063ce05a6e397a9e1e45918d10c) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EFrame.html#adde828b272e5cfebe18dce8fd8ce910c) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EFrame.html#a04e97a6840abc6155a0e250ae68d67ba), [`EFrame::SensorToLocal`](../../doxygen_cpp/classeVision_1_1EFrame.html#adc1fbb45c6415b286df3b3ae7a7a6856) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EFrame.html#adadbeff7d06e5284e3087aca1a7d9b2b) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EFrame.html#a580ce084053d4d6a3f1321e56b9ef335) and [`EFrame::WorldToLocal`](../../doxygen_cpp/classeVision_1_1EFrame.html#a68a47885e74bc75eb5244cd09a87a47a) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EFrame.html#aea900ccd2db8199cc53bbca398b31706) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EFrame.html#a4ed697b504e470acda84f5dd77f1ea02) to transform the points or some geometrical primitives from one reference frame to another.

## Methods supporting frames as input

| Library   | Method                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| EasyGauge | [`ERectangleGauge::Measure`](../../doxygen_cpp/classeVision_1_1ERectangleGauge.html#adb99d7886162b8a7d7f13856e870296c) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1ERectangleGauge.html#a11a005b4c4d25b674ac452ddd077cfbe) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1ERectangleGauge.html#ad6146bf4c1d7d98f90cc8c1fdd95634e)<br /><br/>\\\\<br/>[`ECircleGauge::Measure`](../../doxygen_cpp/classeVision_1_1ECircleGauge.html#ad2dd44cc4460cf871a898373143502e1) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1ECircleGauge.html#a577854baf1e8e18b4be0300dd4b83d34) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1ECircleGauge.html#a9c154d44bd780ca9cc3dea3213ef6261)<br /><br/>\\\\<br/>[`EPolygonGauge::Measure`](../../doxygen_cpp/classeVision_1_1EPolygonGauge.html#a01bd46e353ec7dc02cd210a8f877d6d5) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EPolygonGauge.html#a05ed074e5422978bf95ef0b16d47e4ea) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EPolygonGauge.html#aa321bb7e03c0542d0e2db8e03a5df9b6)<br /><br/>\\\\<br/>[`ELineGauge::Measure`](../../doxygen_cpp/classeVision_1_1ELineGauge.html#a6f1bef02de06c3b3e64914b55022db04) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1ELineGauge.html#ad654d593dce082f2df4d793dc0599df8) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1ELineGauge.html#a945da074490189c8ef991e35412314a4)<br /><br/>\\\\<br/>[`EPointGauge::Measure`](../../doxygen_cpp/classeVision_1_1EPointGauge.html#a206d538662fa5ce93d9e82729acd8615) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EPointGauge.html#a6e0df1aab18f2aca145a011ac3b4dbd4) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EPointGauge.html#aea4d70f17107d67dd9dcdd2fd4906147)<br /><br/>\\\\<br/>[`EWedgeGauge::Measure`](../../doxygen_cpp/classeVision_1_1EWedgeGauge.html#a160e69b0a1f857b0ae0e409ced023419) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EWedgeGauge.html#aa03780a1ae01a8d2a13c3bd64eee9bbe) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EWedgeGauge.html#a44d19661f492161900b3b130d3009878) |

## Objects that can be expressed in a frame

The objects that can be expressed in a reference frame have an `EFrame` argument in their drawing function:

| Library   | Method                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| EasyGauge | [`ERectangle`](../../doxygen_cpp/classeVision_1_1ERectangle.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1ERectangle.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1ERectangle.html)(\*)<br /><br/>\\\\<br/>[`EEllipse`](../../doxygen_cpp/classeVision_1_1EEllipse.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EEllipse.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EEllipse.html)(\*)<br /><br/>\\\\<br/>[`EWedge`](../../doxygen_cpp/classeVision_1_1EWedge.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EWedge.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EWedge.html)(\*)<br /><br/>\\\\<br/>[`ELine`](../../doxygen_cpp/classeVision_1_1ELine.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1ELine.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1ELine.html)(\*)<br /><br/>\\\\<br/>[`EPointSet`](../../doxygen_cpp/classeVision_1_1EPointSet.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EPointSet.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EPointSet.html)(\*)<br /><br/>\\\\<br/>[`EPolygon`](../../doxygen_cpp/classeVision_1_1EPolygon.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EPolygon.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EPolygon.html)(\*)<br /><br/>\\\\<br/>[`ECircle`](../../doxygen_cpp/classeVision_1_1ECircle.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1ECircle.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1ECircle.html)(\*)<br /><br/>\\\\<br/>[`ERegion`](../../doxygen_cpp/classeVision_1_1ERegion.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1ERegion.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1ERegion.html)<br /><br/>\\\\<br/>[`ERectangleRegion`](../../doxygen_cpp/classeVision_1_1ERectangleRegion.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1ERectangleRegion.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1ERectangleRegion.html)<br /><br/>\\\\<br/>[`ECircleRegion`](../../doxygen_cpp/classeVision_1_1ECircleRegion.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1ECircleRegion.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1ECircleRegion.html)<br /><br/>\\\\<br/>[`EPolygonRegion`](../../doxygen_cpp/classeVision_1_1EPolygonRegion.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EPolygonRegion.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EPolygonRegion.html)<br /><br/>\\\\<br/>[`EEllipseRegion`](../../doxygen_cpp/classeVision_1_1EEllipseRegion.html) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EEllipseRegion.html) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EEllipseRegion.html) |

(\*) The object supports frames with a non-affine calibration model (that is a calibration with perspective or distortions).

## Converting an object to a reference frame

To convert an object to a reference frame, use the `ToFrame` method of that object.

You can convert the following objects to a reference frame:

| Library        | Method                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Easy           | `ERectangle.ToFrame`<br /><br/>\\\\<br/>`EEllipse.ToFrame`<br /><br/>\\\\<br/>`EWedge.ToFrame`<br /><br/>\\\\<br/>`ELine.ToFrame`<br /><br/>\\\\<br/>`EPointSet.ToFrame`<br /><br/>\\\\<br/>`EPolygon.ToFrame`<br /><br/>\\\\<br/>`ECircle.ToFrame`                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| EasyMatch      | [`EFoundPattern::ToFrame`](../../doxygen_cpp/classeVision_1_1EFoundPattern.html#a4e52a390000a60d7138850546c4b5908) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EFoundPattern.html#acf2d531c76487735bfaec8a6c55dacb3) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EFoundPattern.html#a730110ba7dc90ed71a579641c087fa42)                                                                                                                                                                                                                                                                                                                                                                                |
| EasyFind       | [`EFoundPattern::ToFrame`](../../doxygen_cpp/classeVision_1_1EFoundPattern.html#a4e52a390000a60d7138850546c4b5908) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EFoundPattern.html#acf2d531c76487735bfaec8a6c55dacb3) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EFoundPattern.html#a730110ba7dc90ed71a579641c087fa42)                                                                                                                                                                                                                                                                                                                                                                                |
| EasyBarCode    | [`EBarCode::ToFrame`](../../doxygen_cpp/classeVision_1_1EasyBarCode2_1_1EBarCode.html#a5bd4f3c5ca2b8b53f41c3920a646d109) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EasyBarCode2_1_1EBarCode.html#abbbeb8e64ca456461797beb10c1350d6) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EasyBarCode2_1_1EBarCode.html#a65d41a8e6f982387ffcfd365bfaff8cd)<br /><br/>\\\\<br/>[`ECode::ToFrame`](../../doxygen_cpp/classeVision_1_1ECode.html#a589ddce4004a7732c58abb03ef42391c) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1ECode.html#a9b6e1264167919be5aee580f83425075) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1ECode.html#a5f40876eb114a83cd68e262b38f7d166)                      |
| EasyMatrixCode | [`EMatrixCode::ToFrame`](../../doxygen_cpp/classeVision_1_1EasyMatrixCode2_1_1EMatrixCode.html#a3298321091befb6362d93b4dc326e0f7) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EasyMatrixCode2_1_1EMatrixCode.html#aea6b439edb2798f63a83f18e7bc5d56e) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EasyMatrixCode2_1_1EMatrixCode.html#a766b7d6173d4228868216779ba7d1566)<br /><br/>\\\\<br/>[`ECode::ToFrame`](../../doxygen_cpp/classeVision_1_1ECode.html#a589ddce4004a7732c58abb03ef42391c) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1ECode.html#a9b6e1264167919be5aee580f83425075) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1ECode.html#a5f40876eb114a83cd68e262b38f7d166) |
| EasyQRCode     | [`EQRCode::ToFrame`](../../doxygen_cpp/classeVision_1_1EQRCode.html#a53c3ecb1b9604fa8c805064aeabffdf6) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1EQRCode.html#a4820bf3171f54d1932a093c7ddea867b) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1EQRCode.html#ac560773ff982354deee8e6e58fb93e32)<br /><br/>\\\\<br/>[`ECode::ToFrame`](../../doxygen_cpp/classeVision_1_1ECode.html#a589ddce4004a7732c58abb03ef42391c) [<sub>.NET</sub>](../../doxygen_cs/classeVision_1_1ECode.html#a9b6e1264167919be5aee580f83425075) [<sub>Python</sub>](../../doxygen_python/classeVision_1_1ECode.html#a5f40876eb114a83cd68e262b38f7d166)                                                                          |
