ImageΒΆ

The Image class represents a single image from one of the Leap Motion cameras. More...

Inherits IDisposable.

Public Types

enum  FormatType
 Enumerates the possible image formats. More...
 
enum  PerspectiveType
 Enumerates the image perspectives. More...
 

Public Member Functions

bool Equals (Image other)
 Compare Image object equality. More...
 
 Image ()
 Constructs a Image object. More...
 
Vector PixelToRectilinear (PerspectiveType camera, Vector pixel)
 Provides the corrected camera ray intercepting the specified point on the image. More...
 
Vector RectilinearToPixel (PerspectiveType camera, Vector ray)
 Provides the point in the image corresponding to a ray projecting from the camera. More...
 
override string ToString ()
 A string containing a brief, human readable description of the Image object. More...
 

Properties

int BytesPerPixel [get]
 The number of bytes per pixel. More...
 
byte[] Data [get]
 The image data. More...
 
float[] Distortion [get]
 The distortion calibration map for this image. More...
 
int DistortionHeight [get]
 The distortion map height. More...
 
int DistortionWidth [get]
 The stride of the distortion map. More...
 
Image.FormatType Format [get]
 The image format. More...
 
int Height [get]
 The image height. More...
 
static Image Invalid [get]
 Returns an invalid Image object. More...
 
bool IsValid [get]
 Reports whether this Image instance contains valid data. More...
 
float RayOffsetX [get]
 The horizontal ray offset. More...
 
float RayOffsetY [get]
 The vertical ray offset. More...
 
float RayScaleX [get]
 The horizontal ray scale factor. More...
 
float RayScaleY [get]
 The vertical ray scale factor. More...
 
long SequenceId [get]
 The image sequence ID. More...
 
long Timestamp [get]
 Returns a timestamp indicating when this frame began being captured on the device. More...
 
int Width [get]
 The image width. More...
 

Detailed Description

The Image class represents a single image from one of the Leap Motion cameras.

In addition to image data, the Image object provides a distortion map for correcting lens distortion.

Leap.Image image = new Leap.Image ();
Bitmap bitmap = new Bitmap (image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
//set palette
ColorPalette grayscale = bitmap.Palette;
for (int i = 0; i < 256; i++) {
grayscale.Entries [i] = Color.FromArgb ((int)255, i, i, i);
}
bitmap.Palette = grayscale;
Rectangle lockArea = new Rectangle (0, 0, bitmap.Width, bitmap.Height);
BitmapData bitmapData = bitmap.LockBits (lockArea, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
byte[] rawImageData = image.Data;
System.Runtime.InteropServices.Marshal.Copy (rawImageData, 0, bitmapData.Scan0, image.Width * image.Height);
bitmap.UnlockBits (bitmapData);

Note that Image objects can be invalid, which means that they do not contain valid image data. Get valid Image objects from Frame::frames(). Test for validity with the Image::isValid() function.

Since
2.1.0

Member Enumeration Documentation

enum FormatType
strong

Enumerates the possible image formats.

The Image::format() function returns an item from the FormatType enumeration.

Since
2.2.0
enum PerspectiveType
strong

Enumerates the image perspectives.

Since
3.0
Enumerator
INVALID 

Invalid or unknown image perspective.

STEREO_LEFT 

Left side of a stereo pair.

STEREO_RIGHT 

Right side of a stereo pair.

MONO 

Reserved for future use.

Constructor & Destructor Documentation

Image ( )

Constructs a Image object.

An uninitialized image is considered invalid. Get valid Image objects from a ImageList object obtained from the Frame::images() method.

Since
2.1.0

Member Function Documentation

bool Equals ( Image  other)

Compare Image object equality.

Two Image objects are equal if and only if both Image objects represent the exact same Image and both Images are valid.

Since
2.1.0
Vector PixelToRectilinear ( PerspectiveType  camera,
Vector  pixel 
)

Provides the corrected camera ray intercepting the specified point on the image.

Given a point on the image, PixelToRectilinear() corrects for camera distortion and returns the true direction from the camera to the source of that image point within the Leap Motion field of view.

This direction vector has an x and y component [x, y, 1], with the third element always one. Note that this vector uses the 2D camera coordinate system where the x-axis parallels the longer (typically horizontal) dimension and the y-axis parallels the shorter (vertical) dimension. The camera coordinate system does not correlate to the 3D Leap Motion coordinate system.

Vector feature = new Vector (127, 68, 0);
Vector slopes = image.PixelToRectilinear (Leap.Image.PerspectiveType.STEREO_LEFT,
feature);

Note: This function should be called immediately after an image is obtained. Incorrect results will be returned if the image orientation has changed or a different device is plugged in between the time the image was received and the time this function is called.

Note, this function was formerly named Rectify().

Parameters
camerawhether the pixel parameter is a pixel in the left or the right stereo image.
pixelA Vector containing the position of a pixel in the image.
Returns
A Vector containing the ray direction (the z-component of the vector is always one).
Since
2.1.0
Vector RectilinearToPixel ( PerspectiveType  camera,
Vector  ray 
)

Provides the point in the image corresponding to a ray projecting from the camera.

Given a ray projected from the camera in the specified direction, RectilinearToPixel() corrects for camera distortion and returns the corresponding pixel coordinates in the image.

The ray direction is specified in relationship to the camera. The first vector element corresponds to the "horizontal" view angle; the second corresponds to the "vertical" view angle.

float horizontal_slope = (float)Math.Tan (65 * 180 / Math.PI);
float vertical_slope = (float)Math.Tan (15 * 180 / Math.PI);
Vector pixel = image.RectilinearToPixel (Leap.Image.PerspectiveType.STEREO_LEFT,
new Vector (horizontal_slope, vertical_slope, 0));
if(pixel.x >= 0 && pixel.y >= 0 && pixel.x <= image.Width && pixel.y <= image.Height){
int data_index = (int)(Math.Floor (pixel.y) * image.Width + Math.Floor (pixel.x));
Console.WriteLine (data_index);
byte brightness = image.Data [data_index];
}

The RectilinearToPixel() function returns pixel coordinates outside of the image bounds if you project a ray toward a point for which there is no recorded data.

RectilinearToPixel() is typically not fast enough for realtime distortion correction. For better performance, use a shader program exectued on a GPU.

Note: This function should be called immediately after an image is obtained. Incorrect results will be returned if the image orientation has changed or a different device is plugged in between the time the image was received and the time this function is called.

Note, this function was formerly named Warp().

Parameters
camerawhether the ray parameter intercepts the left or the right stereo image.
rayA Vector containing the ray direction.
Returns
A Vector containing the pixel coordinates [x, y, 1] (with z always one).
Since
2.1.0
override string ToString ( )

A string containing a brief, human readable description of the Image object.

Returns
A description of the Image as a string.
Since
2.1.0

Property Documentation

int BytesPerPixel
get

The number of bytes per pixel.

Use this value along with Image::width() and Image:::height() to calculate the size of the data buffer.

int bufferSize = image.BytesPerPixel * image.Width * image.Height;
Since
2.2.0
byte [] Data
get

The image data.

The image data is a set of 8-bit intensity values. The buffer is image.Width * image.Height * image.BytesPerPixel bytes long.

byte[] image_buffer = image.Data;
Since
2.1.0
float [] Distortion
get

The distortion calibration map for this image.

The calibration map is a 64x64 grid of points. Each point is defined by a pair of 32-bit floating point values. Each point in the map represents a ray projected into the camera. The value of a grid point defines the pixel in the image data containing the brightness value produced by the light entering along the corresponding ray. By interpolating between grid data points, you can find the brightness value for any projected ray. Grid values that fall outside the range [0..1] do not correspond to a value in the image data and those points should be ignored.

float[] distortion_buffer = image.Distortion;

The calibration map can be used to render an undistorted image as well as to find the true angle from the camera to a feature in the raw image. The distortion map itself is designed to be used with GLSL shader programs. In other contexts, it may be more convenient to use the Image Rectify() and Warp() functions.

Distortion is caused by the lens geometry as well as imperfections in the lens and sensor window. The calibration map is created by the calibration process run for each device at the factory (and which can be rerun by the user).

Note, in a future release, there will be two distortion maps per image; one containing the horizontal values and the other containing the vertical values.

Since
2.1.0
int DistortionHeight
get

The distortion map height.

Currently fixed at 64.

int correctionGridHeight = image.DistortionHeight;
Since
2.1.0
int DistortionWidth
get

The stride of the distortion map.

Since each point on the 64x64 element distortion map has two values in the buffer, the stride is 2 times the size of the grid. (Stride is currently fixed at 2 * 64 = 128).

int correctionGridWidth = image.DistortionWidth;
Since
2.1.0
Image.FormatType Format
get

The image format.

if (image.Format == Leap.Image.FormatType.INFRARED) {
Bitmap bitmap = new Bitmap (image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
//set palette
ColorPalette grayscale = bitmap.Palette;
for (int i = 0; i < 256; i++) {
grayscale.Entries [i] = Color.FromArgb ((int)255, i, i, i);
}
bitmap.Palette = grayscale;
}
Since
2.2.0
int Height
get

The image height.

int height = image.Height;
Since
2.1.0
Image Invalid
staticget

Returns an invalid Image object.

You can use the instance returned by this function in comparisons testing whether a given Image instance is valid or invalid. (You can also use the Image::isValid() function.)

Returns
The invalid Image instance.
Since
2.1.0
bool IsValid
get

Reports whether this Image instance contains valid data.

Returns
true, if and only if the image is valid.
Since
2.1.0
float RayOffsetX
get

The horizontal ray offset.

Used to convert between normalized coordinates in the range [0..1] and the ray slope range [-4..4].

Vector raySlopes = new Vector (-3.25f, 1.75f, 0.0f);
Vector normRay =
new Vector (raySlopes.x * image.RayScaleX + image.RayOffsetX,
raySlopes.y * image.RayScaleY + image.RayOffsetY, 0);
Since
2.1.0
float RayOffsetY
get

The vertical ray offset.

Used to convert between normalized coordinates in the range [0..1] and the ray slope range [-4..4].

Vector normSlopes = new Vector (.25f, .98f, 0.0f); //An arbitrary slope vector
Vector slope = new Vector ((normSlopes.x - image.RayOffsetX) / image.RayScaleX,
(normSlopes.y - image.RayOffsetY) / image.RayScaleY, 0);
Since
2.1.0
float RayScaleX
get

The horizontal ray scale factor.

Used to convert between normalized coordinates in the range [0..1] and the ray slope range [-4..4].

Vector raySlopes = new Vector (-3.25f, 1.75f, 0.0f);
Vector normRay =
new Vector (raySlopes.x * image.RayScaleX + image.RayOffsetX,
raySlopes.y * image.RayScaleY + image.RayOffsetY, 0);
Since
2.1.0
float RayScaleY
get

The vertical ray scale factor.

Used to convert between normalized coordinates in the range [0..1] and the ray slope range [-4..4].

Vector normSlopes = new Vector (.25f, .98f, 0.0f); //An arbitrary slope vector
Vector slope = new Vector ((normSlopes.x - image.RayOffsetX) / image.RayScaleX,
(normSlopes.y - image.RayOffsetY) / image.RayScaleY, 0);
Since
2.1.0
long SequenceId
get

The image sequence ID.

int lastImage = 0;
while (!done) {
Image left_image = controller.Images[0];
if (left_image.SequenceId != lastImage) {
image right_image = controller.Images [1];
lastImage = left_image.SequenceId;
// Use images...
}
}
Since
2.2.1
long Timestamp
get

Returns a timestamp indicating when this frame began being captured on the device.

Since
2.2.7
int Width
get

The image width.

int width = image.Width;
Since
2.1.0