This repository was archived by the owner on Aug 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 639
Expand file tree
/
Copy pathProgram.cs
More file actions
102 lines (87 loc) · 3.72 KB
/
Program.cs
File metadata and controls
102 lines (87 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Linq.Expressions;
using Microsoft.Azure.Kinect.Sensor;
using Microsoft.Azure.Kinect.Sensor.Record;
namespace Recording
{
class Program
{
static void Main(string[] args)
{
int frame = 0;
if (args.Length < 1)
{
Console.WriteLine("Please specify the name of an .mkv output file.");
return;
}
string path = args[0];
try
{
Console.WriteLine($"Recording from device to \"{path}\".");
DeviceConfiguration configuration = new DeviceConfiguration()
{
CameraFPS = FPS.FPS30,
ColorFormat = ImageFormat.ColorMJPG,
ColorResolution = ColorResolution.R720p,
DepthMode = DepthMode.NFOV_2x2Binned,
SynchronizedImagesOnly = true
};
using (Device device = Device.Open())
using (Recorder recorder = Recorder.Create(path, device, configuration))
{
device.StartCameras(configuration);
device.StartImu();
recorder.AddImuTrack();
recorder.WriteHeader();
for (frame = 0; frame < 100; frame++)
{
using (Capture capture = device.GetCapture())
{
recorder.WriteCapture(capture);
Console.WriteLine($"Wrote capture ({capture.Color.DeviceTimestamp})");
try
{
while (true)
{
// Throws TimeoutException when Imu sample is not available
ImuSample sample = device.GetImuSample(TimeSpan.Zero);
recorder.WriteImuSample(sample);
Console.WriteLine($"Wrote imu ({sample.AccelerometerTimestamp})");
}
}
catch (TimeoutException)
{
}
}
}
}
Console.WriteLine($"Wrote {frame} frames to output.mkv");
using (Playback playback = Playback.Open(@"output.mkv"))
{
Console.WriteLine($"Tracks = {playback.TrackCount}");
Console.WriteLine($"RecordingLength = {playback.RecordingLength}");
for (int i = 0; i < playback.TrackCount; i++)
{
string name = playback.GetTrackName(i);
string codecId = playback.GetTrackCodecId(name);
Console.WriteLine($" Track {i}: {name} ({codecId}) (builtin={playback.GetTrackIsBuiltin(name)})");
}
Capture capture;
while (null != (capture = playback.GetNextCapture()))
{
Console.WriteLine($"Color timestamp: {capture.Color.DeviceTimestamp} Depth timestamp: {capture.Depth.DeviceTimestamp}");
}
}
} catch (AzureKinectException exception)
{
Console.WriteLine(exception.ToString());
Console.WriteLine();
Console.WriteLine("Azure Kinect log messages:");
foreach (LogMessage m in exception.LogMessages)
{
Console.WriteLine(m.ToString());
}
}
}
}
}