-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
116 lines (96 loc) · 3.14 KB
/
main.cpp
File metadata and controls
116 lines (96 loc) · 3.14 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <k4a/k4a.h>
#include <math.h>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include "utils.hpp"
int main(int argc, char **argv)
{
int returnCode = 1;
k4a_device_t device = NULL;
const int32_t TIMEOUT_IN_MS = 1000;
k4a_capture_t capture = NULL;
std::string file_name;
uint32_t device_count = 0;
k4a_device_configuration_t config = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL;
k4a_image_t depth_image = NULL;
k4a_image_t xy_table = NULL;
k4a_image_t point_cloud = NULL;
int point_count = 0;
if (argc != 2)
{
printf("fastpcd <output file>\n");
returnCode = 2;
goto Exit;
}
file_name = argv[1];
device_count = k4a_device_get_installed_count();
if (device_count == 0)
{
printf("No K4A devices found\n");
return 0;
}
if (K4A_RESULT_SUCCEEDED != k4a_device_open(K4A_DEVICE_DEFAULT, &device))
{
printf("Failed to open device\n");
goto Exit;
}
config.depth_mode = K4A_DEPTH_MODE_WFOV_2X2BINNED;
config.camera_fps = K4A_FRAMES_PER_SECOND_30;
k4a_calibration_t calibration;
if (K4A_RESULT_SUCCEEDED !=
k4a_device_get_calibration(device, config.depth_mode, config.color_resolution, &calibration))
{
printf("Failed to get calibration\n");
goto Exit;
}
k4a_image_create(K4A_IMAGE_FORMAT_CUSTOM,
calibration.depth_camera_calibration.resolution_width,
calibration.depth_camera_calibration.resolution_height,
calibration.depth_camera_calibration.resolution_width * (int)sizeof(k4a_float2_t),
&xy_table);
create_xy_table(&calibration, xy_table);
k4a_image_create(K4A_IMAGE_FORMAT_CUSTOM,
calibration.depth_camera_calibration.resolution_width,
calibration.depth_camera_calibration.resolution_height,
calibration.depth_camera_calibration.resolution_width * (int)sizeof(k4a_float3_t),
&point_cloud);
if (K4A_RESULT_SUCCEEDED != k4a_device_start_cameras(device, &config))
{
printf("Failed to start cameras\n");
goto Exit;
}
// Get a capture
switch (k4a_device_get_capture(device, &capture, TIMEOUT_IN_MS))
{
case K4A_WAIT_RESULT_SUCCEEDED:
break;
case K4A_WAIT_RESULT_TIMEOUT:
printf("Timed out waiting for a capture\n");
goto Exit;
case K4A_WAIT_RESULT_FAILED:
printf("Failed to read a capture\n");
goto Exit;
}
// Get a depth image
depth_image = k4a_capture_get_depth_image(capture);
if (depth_image == 0)
{
printf("Failed to get depth image from capture\n");
goto Exit;
}
generate_point_cloud(depth_image, xy_table, point_cloud, &point_count);
write_point_cloud(file_name.c_str(), point_cloud, point_count);
k4a_image_release(depth_image);
k4a_capture_release(capture);
k4a_image_release(xy_table);
k4a_image_release(point_cloud);
returnCode = 0;
Exit:
if (device != NULL)
{
k4a_device_close(device);
}
return returnCode;
}