# HandTracker

```
public class HandTracker : IDisposable
```

Implements [System.IDisposable](https://learn.microsoft.com/en-us/dotnet/api/system.idisposable) interface.

### Constructors

| Name          | Description                       |
| ------------- | --------------------------------- |
| HandTracker() | Creates a new HandTracker object. |

### Properties

| Name      | Type   | Description                   |
| --------- | ------ | ----------------------------- |
| Version   | string | Read-Only. The API version.   |
| Copyright | string | Read-Only. The API copyright. |

### Methods

<table><thead><tr><th width="267">Name</th><th>Return Type</th><th>Description</th></tr></thead><tbody><tr><td>Load(<a href="https://docs.unity3d.com/ScriptReference/Texture2D.html">UnityEngine.Texture2D</a>)</td><td>List&#x3C;<a href="hand">Hand</a>></td><td>Detects hands for the specified Texture2D.</td></tr><tr><td>Load(<a href="https://docs.unity3d.com/ScriptReference/Color32.html">UnityEngine.Color32</a>[], int, int)</td><td>List&#x3C;<a href="hand">Hand</a>></td><td>Detects the hands from the specified color array, width and height.</td></tr><tr><td>Load(byte[], int, int, int)</td><td>List&#x3C;<a href="hand">Hand</a>></td><td>Detects hands for the specified image data, width, height and channels.</td></tr><tr><td>Dispose()</td><td>void</td><td>Releases unmanaged resources</td></tr></tbody></table>

### Example

The example shows how to detect hands with the `HandTracker` class.

#### Create a HandTracker

```csharp
HandTracker handTracker = new HandTracker();
```

#### Detect hands in Texture2D

To detect hands in a Texture2D, create a Texture2D and load an image.  There are multiple ways to load an image. You could load it from a webcam using the [WebcamSource](https://handtracking.lightbuzz.com/ui-reference/streamsource/webcamsource), from a file in the Assets folder or from a file on your disc.

```csharp
// Create an empty Texture2D.
Texture2D texture = new Texture2D(0, 0);

// Load a file to a byte array.
string filename = "path/to/image";
byte[] rawData = System.IO.File.ReadAllBytes(filename);

// Load an byte array to the Texture2D.
texture.LoadImage(rawData);
```

After loading the image to the texture there are 3 different ways to detect hands in that image:

The simplest is to detect hands for the specified Texture2D.

```csharp
List<Hand> hands = handTracker.Load(texture);
```

If you need to run the detection in another thread, for example, you can get the texture pixels and detect hands for the specified color array.

```csharp
// Get the texture as a Color32 array.
Color32[] colors = texture.GetPixels32();

// Detect hands for the specified color array.
List<Hand> hands = handTracker.Load(colors, texture.width, texture.height);
```

Alternatively, you can get the texture raw data and detect hands for the specified byte array.

```csharp
// Get the texture as a byte array.
byte[] rawData = texture.GetRawTextureData();

// Detect hands for the specified byte array, width, height and channels.
List<Hand> hands = handTracker.Load(rawData, texture.width, texture.height, 3);
```

#### Detect hands in an image file

To detect hands in an image file, load the file and detect hands for the specified byte array.&#x20;

```csharp
// Load byte array from file.
string filename = "Assets/Images/test.png";
byte[] rawData = File.ReadAllBytes(filename);

// Detect hands for the specified byte array, width, height and channels.
List<Hand> hands = handTracker.Load(rawData, 500, 500, 3);
```

#### Dispose Handtracker

Once tracking is no longer needed, it's recommended to dispose of the `HandTracker`. You can do that either in the `OnApplicationQuit()` or the `OnDestroy()` methods.

```csharp
handTracker.Dispose();
```
