> For the complete documentation index, see [llms.txt](https://handtracking.lightbuzz.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://handtracking.lightbuzz.com/examples/detect-hand-and-retrieve-joints.md).

# Detect hand and retrieve joints

This example demonstrates how to load  an image file into a `Texture2D`, implement hand tracking with the [HandTracker](/api-reference/handtracker.md),  and retrieve joint information of the detected index finger.

#### Step 1: Load the Image into Texture2D

1. Ensure you have your image file ready, preferably in a supported format such as PNG or JPEG.
2. Use the appropriate method (e.g., `Texture2D.LoadImage`) to load your image into a `Texture2D` object.

```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);
```

#### Step 2: Create and Use a HandTracker

1. Instantiate a [HandTracker](/api-reference/handtracker.md) object in your application. The [HandTracker](/api-reference/handtracker.md) is responsible for detecting hands within the texture.
2. Pass the `Texture2D` object created in Step 1 to the [HandTracker](/api-reference/handtracker.md) for processing.
3. The [HandTracker](/api-reference/handtracker.md) will analyze the texture and detect any hands present in the image.

```csharp
// Create a handTracker.
HandTracker tracker = new HandTracker();

// Detect hands.
List<Hand> hands = tracker.Load(texture);
```

#### Step 3: Retrieve Index Finger Joint Information

1. Once a hand is detected in Step 2,  you can retrieve information on the detected hand, its fingers and their finger joints.
2. Specifically, get the hand side (left or right) and the index finger's information. The index includes, among other joints, the 2D and 3D positions of the index metacarpophalangeal joint as shown in this example.

```csharp
// If at least one hand is detected
if (hands.Count > 0)
{
    // Get hand side. 
    HandSide side = hands[0].Side;
    
    // Get index finger.
    Index index = hands[0].Index;
    
    // Get index MCP finger joint.
    FingerJoint indexMCP = index.MCP;
    
    // Get joint 2D position.
    Vector2 screenPosition = indexMCP.Position2D;
    
    // Get joint 3D position.
    Vector3 worldPosition = indexMCP.Position3D;
}
```

### Full example code

```csharp
string filename = "path/to/image";
byte[] rawData = System.IO.File.ReadAllBytes(filename);
Texture2D texture = new Texture2D(0, 0);
texture.LoadImage(rawData);

// Create a handTracker.
HandTracker tracker = new HandTracker();

// Find hands in an image.
List<Hand> hands = tracker.Load(texture);

// If at least one hand is detected
if (hands.Count > 0)
{
    // Get hand side. 
    HandSide side = hands[0].Side;
    // Get index finger.
    Index index = hands[0].Index;
    // Get index MCP finger joint.
    FingerJoint indexMCP = index.MCP;
    // Get joint 2D position.
    Vector2 screenPosition = indexMCP.Position2D;
    // Get joint 3D position.
    Vector3 worldPosition = indexMCP.Position3D;
}
```

By following these steps, you will be able to load an image, detect hands within it, and obtain detailed joint information for the index finger using a`Texture2D` and the [HandTracker](/api-reference/handtracker.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://handtracking.lightbuzz.com/examples/detect-hand-and-retrieve-joints.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
