👐
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. UI Reference

ImageView

Draws the image texture.

PreviousHandVisualNextStreamSource

Last updated 1 year ago

public class ImageView : MonoBehaviour

Inherits class.

Constructors

Name
Description

ImageView()

Creates a new ImageView object.

Properties

Name
Type
Description

Texture

Read-Only. The image texture.

Width

int

Read-Only. The texture width.

Height

int

Read-Only. The texture height.

FlipVertically

bool

Flips the texture vertically.

FlipHorizontally

bool

Flips the texture horizontally.

Methods

Name
Return Type
Description

void

Draws the texture for the specified Texture2D.

Load(StreamSource)

void

Draws the texture for the specified stream source.

void

Draws the texture for the specified color array, width, height and rotation.

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

void

Draws the texture for the specified byte array, width, height and rotation.

Calculates the position in the local space of the image for the specified original 2D position of a point.

Example

The example shows how to draw the texture with the ImageView class.

Draw the image texture

[SerializeField] private ImageView _image;
[SerializeField] private WebcamSource _webcam;
_image.Load(_webcam);

Alternatively, you can provide the color array of the texture.

_image.Load(_webcam.Pixels, _webcam.Width, _webcam.Height);

Get the local position of a finger joint

The FingerJoint class returns the joint's 2D position in pixels relative to the camera's dimensions. To represent this position on an ImageView texture, which may vary in size, the GetPosition method scales the joint's coordinates to match the texture's current width and height.

// Get the finger joint from the detected hand.
FingerJoint pinkyDip = hand.FingerJoints[FingerJointType.PinkyDIP];

// Get the original 2D position (pixels in the camera frame).
Vector2 original_position = pinkyDip.Position2D;

// Get the local 2D position (pixels in the ImageView texture).
Vector2 local_position = image.GetPosition(original_position);

Load()

Load([], int, int, int)

GetPosition()

First, add a field to get frames from a live feed and an ImageViewfield to draw the texture for Unity to serialize.

The easiest way to draw the image texture is by providing directly a object.

UnityEngine.MonoBehaviour
WebcamSource
WebcamSource
UnityEngine.Texture2D
UnityEngine.Texture2D
UnityEngine.Color32
UnityEngine.Vector2
UnityEngine.Vector2