# FaceTracking2DModule

The `FaceTracking2DModule` class enables tracking faces in 2D.

## Example

```
//==============================================================================
// The following example demonstrates how to bind the position of a rectangle to
// a 2D face.
//
// Project setup:
// - Insert a rectangle
//==============================================================================

// Load in the required modules
const FaceTracking2D = require('FaceTracking2D');
const Scene = require('Scene');

// Locate the rectangle in the Scene and store its transform
const rectangle = Scene.root.find("rectangle0");
const rectangleTransform = rectangle.transform;

// Locate the canvas in the Scene and store the width and height
const canvas = Scene.root.find("canvas0");
const canvasBounds = canvas.bounds;
const canvasBoundsWidth = canvasBounds.width;
const canvasBoundsHeight = canvasBounds.height;

// Store the bounding box center of a detected face
const face2D = FaceTracking2D.face(0);
const face2DBounds = face2D.boundingBox;
const face2DBoundsCenter = face2DBounds.center;

// Convert the normalized screen space value for x and y by multiplying by the
// width and height of the canvas
const scaledX = face2DBoundsCenter.x.mul(canvasBoundsWidth);
const scaledY = face2DBoundsCenter.y.mul(canvasBoundsHeight);

// Subtract the half the width/height to center the plane correctly and multiply
// the y-position by -1, this is necessary because 0,0 in the canvas is the
// bottom left of the device
const rectangleX  = scaledX.sub(canvasBoundsWidth.div(2));
const rectangleY = scaledY.sub(canvasBoundsHeight.div(2)).mul(-1);

// Bind the new values to the x and y-axis positions of the rectangle
rectangleTransform.x = rectangleX;
rectangleTransform.y = rectangleY;
```

## Properties

| Property | Description                                                                                                                                                          |
| -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `count`  | <p><code>(get) count: ScalarSignal (set) (Not Available)</code></p><p>Returns a <code>ScalarSignal</code> representing the number of faces tracked in the scene.</p> |

## Methods

| Method | Description                                                                                                                                       |
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `face` | <p><code>face(index: number): Face2D</code></p><p>Returns the <code>Face2D</code> object from the detected face array at the specified index.</p> |

## Classes

| Class                                                                                                 | Description                                           |
| ----------------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
| [`Face2D`](https://sparkar.facebook.com/docs/ar-studio/reference/classes/facetracking2dmodule.face2d) | The `Face2D` class exposes details of a tracked face. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sparkar-community.gitbook.io/docs/facetracking2dmodule.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
