👐
Hand & Finger Tracking for Unity
HomepageSupportContact
  • Hand Tracking Unity Plugin
    • Overview
    • System Requirements
    • Installation
    • QuickStart
    • Supported Joints
  • Help & Support
    • Ask for help
    • Request a feature
  • Examples
    • Detect hand and retrieve joints
    • No Code: Detect and visualize hands from a Sprite
    • Detect and visualize hands from a Sprite
    • Detect and visualize hands from a video
    • Use webcam to detect and visualize hands (2D Canvas)
    • Use webcam to detect and visualize hands (3D World space)
  • API Reference
    • Finger
      • Index
      • Middle
      • Palm
      • Pinky
      • Ring
      • Thumb
    • FingerJoint
    • FingerJointType
    • Hand
    • HandExtensions
    • HandSide
    • HandTracker
  • UI Reference
    • HandManager
    • HandViewer
    • HandVisual
    • ImageView
    • StreamSource
      • SpriteSource
      • VideoSource
      • WebcamSource
    • HandTrackerExtensions
    • WebcamSelector
Powered by GitBook
On this page
  • Constructors
  • Properties
  • Methods
  • Example
  1. API Reference

HandTracker

Detects hands in an image.

PreviousHandSideNextHandManager

Last updated 1 year ago

public class HandTracker : IDisposable

Implements 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

Name
Return Type
Description

Detects hands for the specified Texture2D.

Detects the hands from the specified color array, width and height.

Load(byte[], int, int, int)

Detects hands for the specified image data, width, height and channels.

Dispose()

void

Releases unmanaged resources

Example

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

Create a HandTracker

HandTracker handTracker = new HandTracker();

Detect hands in Texture2D

// 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.

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.

// 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.

// 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.

// 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.

handTracker.Dispose();

Load()

List<>

Load([], int, int)

List<>

List<>

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 , from a file in the Assets folder or from a file on your disc.

System.IDisposable
WebcamSource
UnityEngine.Texture2D
Hand
UnityEngine.Color32
Hand
Hand