Skip to content

Commit 4779c94

Browse files
committed
Added support for mkv playback
1 parent 6bb2305 commit 4779c94

File tree

8 files changed

+57
-23
lines changed

8 files changed

+57
-23
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# Compiled Dynamic libraries
1515
*.so
1616
*.dylib
17-
*.dll
1817

1918
# Fortran module files
2019
*.mod
@@ -24,7 +23,6 @@
2423
*.lai
2524
*.la
2625
*.a
27-
*.lib
2826

2927
# Executables
3028
*.exe
413 KB
Binary file not shown.

extern/k4a/win32/bin/k4a.dll

636 KB
Binary file not shown.

extern/k4a/win32/bin/k4arecord.dll

1.64 MB
Binary file not shown.

extern/k4a/win32/lib/k4a.lib

17.6 KB
Binary file not shown.

extern/k4a/win32/lib/k4arecord.lib

12.2 KB
Binary file not shown.

src/IRToolTracking.cpp

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ void IRToolTracking::initializeFromFile(const std::string& file) {
3939
std::cerr << "Failed to open file " << file << std::endl;
4040
return;
4141
}
42-
k4a_playback_get_calibration(playback, &calibration);
42+
result = k4a_playback_get_calibration(playback, &calibration);
43+
if (result != K4A_RESULT_SUCCEEDED)
44+
{
45+
std::cerr << "Failed to get calibration" << std::endl;
46+
return;
47+
}
4348
Terminated = false;
4449
playFromFile = true;
4550

@@ -68,7 +73,6 @@ void IRToolTracking::initialize(int index, int width, int height) {
6873
config.depth_mode = K4A_DEPTH_MODE_WFOV_2X2BINNED;
6974
config.color_resolution = K4A_COLOR_RESOLUTION_OFF;
7075
// Retrive calibration
71-
calibration;
7276
if (K4A_RESULT_SUCCEEDED != k4a_device_get_calibration(device, config.depth_mode, config.color_resolution, &calibration))
7377
{
7478
std::cout << "Failed to get calibration" << std::endl;
@@ -112,10 +116,13 @@ void IRToolTracking::processStreams() {
112116
if (Terminated)
113117
return;
114118
// Start the pipeline
115-
if (K4A_RESULT_SUCCEEDED != k4a_device_start_cameras(device, &config))
119+
if (!playFromFile)
116120
{
117-
std::cout<<"Failed to start device"<<std::endl;
118-
return;
121+
if (K4A_RESULT_SUCCEEDED != k4a_device_start_cameras(device, &config))
122+
{
123+
std::cout << "Failed to start device" << std::endl;
124+
return;
125+
}
119126
}
120127

121128
k4a_capture_t capture = NULL;
@@ -128,20 +135,39 @@ void IRToolTracking::processStreams() {
128135

129136
// Continuously capture frames and process them
130137
while (!Terminated) {
131-
// Get a depth frame
132-
switch (k4a_device_get_capture(device, &capture, TIMEOUT_IN_MS))
133-
{
134-
case K4A_WAIT_RESULT_SUCCEEDED:
135-
break;
136-
case K4A_WAIT_RESULT_TIMEOUT:
137-
std::cout<<"Timed out waiting for a capture"<<std::endl;
138-
continue;
139-
break;
140-
case K4A_WAIT_RESULT_FAILED:
141-
std::cout<<"Failed to read a capture"<<std::endl;
142-
k4a_device_close(device);
143-
return;
144-
}
138+
139+
if (playFromFile)
140+
{
141+
switch (k4a_playback_get_next_capture(playback, &capture))
142+
{
143+
case K4A_STREAM_RESULT_SUCCEEDED:
144+
break;
145+
case K4A_STREAM_RESULT_FAILED:
146+
std::cout << "Timed out waiting for a capture" << std::endl;
147+
continue;
148+
break;
149+
case K4A_STREAM_RESULT_EOF:
150+
std::cout << "Reached end of the file" << std::endl;
151+
return;
152+
}
153+
}
154+
else
155+
{
156+
// Get a depth frame
157+
switch (k4a_device_get_capture(device, &capture, TIMEOUT_IN_MS))
158+
{
159+
case K4A_WAIT_RESULT_SUCCEEDED:
160+
break;
161+
case K4A_WAIT_RESULT_TIMEOUT:
162+
std::cout << "Timed out waiting for a capture" << std::endl;
163+
continue;
164+
break;
165+
case K4A_WAIT_RESULT_FAILED:
166+
std::cout << "Failed to read a capture" << std::endl;
167+
k4a_device_close(device);
168+
return;
169+
}
170+
}
145171

146172
// Retrieve depth image
147173
depth_image = k4a_capture_get_depth_image(capture);
@@ -192,6 +218,12 @@ void IRToolTracking::processStreams() {
192218
k4a_image_release(depth_image);
193219
k4a_image_release(ir_image);
194220
k4a_capture_release(capture);
221+
222+
if (playFromFile)
223+
{
224+
// Sleep for 33ms to simulate 30fps
225+
std::this_thread::sleep_for(std::chrono::milliseconds(33));
226+
}
195227
}
196228
}
197229

@@ -201,6 +233,10 @@ void IRToolTracking::shutdown() {
201233
{
202234
k4a_device_close(device);
203235
}
236+
if (playback != NULL)
237+
{
238+
k4a_playback_close(playback);
239+
}
204240
trackingFrame.release();
205241
depthFrame.release();
206242
}

src/viewer_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ int main(int argc, char **argv)
1717
CmdParser::OptionParser cmd_parser;
1818
cmd_parser.RegisterOption("-h|--help", "Prints this help", [&]()
1919
{
20-
std::cout << "ir-tracking-app [options] <realsense_recording.bag> \n"
20+
std::cout << "ir-tracking-app [options] <k4a_recording.mkv> \n"
2121
<< std::endl;
2222
cmd_parser.PrintOptions();
2323
exit(0);
2424
});
25-
cmd_parser.RegisterOption("-i|--input", "RealSense recording file path", 1,
25+
cmd_parser.RegisterOption("-i|--input", "k4a recording file path", 1,
2626
[&](const std::vector<char *> &args)
2727
{
2828
inputFilePath = args[0];

0 commit comments

Comments
 (0)