Tanoda
Image.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9namespace Leap {
10 using System;
11 using LeapInternal;
12
20 public class Image {
21 private ImageData leftImage;
22 private ImageData rightImage;
23 private Int64 frameId = 0;
24 private Int64 timestamp = 0;
25
26 public Image(Int64 frameId, Int64 timestamp, ImageData leftImage, ImageData rightImage) {
27 if (leftImage == null || rightImage == null) {
28 throw new ArgumentNullException("images");
29 }
30 if (leftImage.type != rightImage.type ||
31 leftImage.format != rightImage.format ||
32 leftImage.width != rightImage.width ||
33 leftImage.height != rightImage.height ||
34 leftImage.bpp != rightImage.bpp ||
35 leftImage.DistortionSize != rightImage.DistortionSize) {
36 throw new ArgumentException("image mismatch");
37 }
38 this.frameId = frameId;
39 this.timestamp = timestamp;
40 this.leftImage = leftImage;
41 this.rightImage = rightImage;
42 }
43
44 private ImageData imageData(CameraType camera) {
45 return camera == CameraType.LEFT ? leftImage : rightImage;
46 }
47
59 public byte[] Data(CameraType camera) {
60 if (camera != CameraType.LEFT && camera != CameraType.RIGHT)
61 return null;
62
63 return imageData(camera).AsByteArray;
64 }
65
72 public UInt32 ByteOffset(CameraType camera) {
73 if (camera != CameraType.LEFT && camera != CameraType.RIGHT)
74 return 0;
75
76 return imageData(camera).byteOffset;
77 }
78
86 public UInt32 NumBytes {
87 get {
88 return leftImage.width * leftImage.height * leftImage.bpp;
89 }
90 }
91
117 public float[] Distortion(CameraType camera) {
118 if (camera != CameraType.LEFT && camera != CameraType.RIGHT)
119 return null;
120
121 return imageData(camera).DistortionData.Data;
122 }
123
145 return Connection.GetConnection().PixelToRectilinear(camera, pixel);
146 }
147
174 return Connection.GetConnection().RectilinearToPixel(camera, ray);
175 }
176
184 public bool Equals(Image other) {
185 return
186 this.frameId == other.frameId &&
187 this.Type == other.Type &&
188 this.Timestamp == other.Timestamp;
189 }
190
195 public override string ToString() {
196 return "Image sequence" + this.frameId + ", format: " + this.Format + ", type: " + this.Type;
197 }
198
203 public Int64 SequenceId {
204 get {
205 return frameId;
206 }
207 }
208
213 public int Width {
214 get {
215 return (int)leftImage.width;
216 }
217 }
218
223 public int Height {
224 get {
225 return (int)leftImage.height;
226 }
227 }
228
237 public int BytesPerPixel {
238 get {
239 return (int)leftImage.bpp;
240 }
241 }
242
248 get {
249 switch (leftImage.format) {
250 case eLeapImageFormat.eLeapImageType_IR:
251 return FormatType.INFRARED;
252 case eLeapImageFormat.eLeapImageType_RGBIr_Bayer:
253 return FormatType.IBRG;
254 default:
255 return FormatType.INFRARED;
256 }
257 }
258 }
259
261 get {
262 switch (leftImage.type) {
263 case eLeapImageType.eLeapImageType_Default:
264 return ImageType.DEFAULT;
265 case eLeapImageType.eLeapImageType_Raw:
266 return ImageType.RAW;
267 default:
268 return ImageType.DEFAULT;
269 }
270 }
271 }
272
282 public int DistortionWidth {
283 get {
284 return leftImage.DistortionSize * 2;
285 }
286 }
287
294 public int DistortionHeight {
295 get {
296 return leftImage.DistortionSize;
297 }
298 }
299
308 public float RayOffsetX(CameraType camera) {
309 if (camera != CameraType.LEFT && camera != CameraType.RIGHT)
310 return 0;
311
312 return imageData(camera).RayOffsetX;
313 }
314
323 public float RayOffsetY(CameraType camera) {
324 if (camera != CameraType.LEFT && camera != CameraType.RIGHT)
325 return 0;
326
327 return imageData(camera).RayOffsetY;
328 }
329
338 public float RayScaleX(CameraType camera) {
339 if (camera != CameraType.LEFT && camera != CameraType.RIGHT)
340 return 0;
341
342 return imageData(camera).RayScaleX;
343 }
344
353 public float RayScaleY(CameraType camera) {
354 if (camera != CameraType.LEFT && camera != CameraType.RIGHT)
355 return 0;
356
357 return imageData(camera).RayScaleY;
358 }
359
364 public Int64 Timestamp {
365 get {
366 return timestamp;
367 }
368 }
369
376 public enum FormatType {
377 INFRARED = 0,
378 IBRG = 1
379 }
380
381 public enum ImageType {
382 DEFAULT,
383 RAW
384 }
385
386 public enum CameraType {
387 LEFT = 0,
388 RIGHT = 1
389 };
390 }
391
392}
float[] Data
The distortion data.
The Image class represents a stereo image pair from the Leap Motion device.
Definition: Image.cs:20
int Height
The image height.
Definition: Image.cs:223
Image(Int64 frameId, Int64 timestamp, ImageData leftImage, ImageData rightImage)
Definition: Image.cs:26
override string ToString()
A string containing a brief, human readable description of the Image object.
Definition: Image.cs:195
CameraType
Definition: Image.cs:386
float RayOffsetY(CameraType camera)
The vertical ray offset for a particular camera.
Definition: Image.cs:323
float RayScaleX(CameraType camera)
The horizontal ray scale factor for a particular camera.
Definition: Image.cs:338
float[] Distortion(CameraType camera)
The distortion calibration map for this image.
Definition: Image.cs:117
UInt32 NumBytes
The number of bytes in the Data() buffer corresponding to each image. Use the ByteOffset() function t...
Definition: Image.cs:86
int DistortionWidth
The stride of the distortion map.
Definition: Image.cs:282
int Width
The image width.
Definition: Image.cs:213
int DistortionHeight
The distortion map height. Currently fixed at 64.
Definition: Image.cs:294
byte[] Data(CameraType camera)
The buffer containing the image data.
Definition: Image.cs:59
FormatType Format
The image format.
Definition: Image.cs:247
Vector PixelToRectilinear(CameraType camera, Vector pixel)
Provides the corrected camera ray intercepting the specified point on the image.
Definition: Image.cs:144
Int64 Timestamp
Returns a timestamp indicating when this frame began being captured on the device.
Definition: Image.cs:364
float RayScaleY(CameraType camera)
The vertical ray scale factor for a particular camera.
Definition: Image.cs:353
bool Equals(Image other)
Compare Image object equality.
Definition: Image.cs:184
Int64 SequenceId
The image sequence ID.
Definition: Image.cs:203
UInt32 ByteOffset(CameraType camera)
The offset, in number of bytes, from the beginning of the Data() buffer to the first byte of the imag...
Definition: Image.cs:72
Vector RectilinearToPixel(CameraType camera, Vector ray)
Provides the point in the image corresponding to a ray projecting from the camera.
Definition: Image.cs:173
ImageType Type
Definition: Image.cs:260
FormatType
Enumerates the possible image formats.
Definition: Image.cs:376
int BytesPerPixel
The number of bytes per pixel.
Definition: Image.cs:237
float RayOffsetX(CameraType camera)
The horizontal ray offset for a particular camera.
Definition: Image.cs:308
static Connection GetConnection(int connectionId=0)
Definition: Connection.cs:30
Vector RectilinearToPixel(Image.CameraType camera, Vector ray)
Definition: Connection.cs:844
Vector PixelToRectilinear(Image.CameraType camera, Vector pixel)
Definition: Connection.cs:834
DistortionData DistortionData
Definition: ImageData.cs:33
eLeapImageFormat format
Definition: ImageData.cs:19
eLeapImageType type
Definition: ImageData.cs:18
eLeapImageType
Definition: LeapC.cs:152
eLeapImageFormat
Definition: LeapC.cs:164
The Vector struct represents a three-component mathematical vector or point such as a direction or po...
Definition: Vector.cs:36