13 #include <k4arecord/record.h>
14 #include <turbojpeg.h>
25 :
RGBDSensor(), sensor_config_(sensor_config) {}
36 switch (device_config.camera_fps) {
37 case K4A_FRAMES_PER_SECOND_5:
40 case K4A_FRAMES_PER_SECOND_15:
43 case K4A_FRAMES_PER_SECOND_30:
50 timeout_ = int(1000.0f / camera_fps);
52 if (device_config.color_resolution == K4A_COLOR_RESOLUTION_OFF &&
53 device_config.depth_mode == K4A_DEPTH_MODE_OFF) {
55 "Config error: either the color or depth modes must be "
56 "enabled to record.");
61 const uint32_t installed_devices =
63 if (sensor_index >= installed_devices) {
70 static_cast<uint32_t
>(sensor_index), &
device_))) {
72 "Runtime error: k4a_plugin::k4a_device_open() failed");
82 "Runtime error: k4a_plugin::k4a_device_start_cameras() "
90 device_, K4A_COLOR_CONTROL_EXPOSURE_TIME_ABSOLUTE,
91 K4A_COLOR_CONTROL_MODE_AUTO, 0))) {
93 "Runtime error: k4a_plugin::k4a_device_set_color_control() "
100 k4a_calibration_t calibration;
102 device_config.color_resolution,
116 k4a_capture_t capture;
119 if (
result == K4A_WAIT_RESULT_TIMEOUT) {
121 }
else if (
result != K4A_WAIT_RESULT_SUCCEEDED) {
123 "Runtime error: k4a_plugin::k4a_device_get_capture() returned "
133 bool enable_align_depth_to_color)
const {
157 "BGRA input image and RGB output image have different "
162 #pragma omp parallel for schedule(static) \
163 num_threads(utility::EstimateMaxThreads())
165 #pragma omp parallel for collapse(3) schedule(static)
167 for (
int v = 0; v < bgra.
height_; ++v) {
168 for (
int u = 0; u < bgra.
width_; ++u) {
169 for (
int c = 0; c < 3; ++c) {
178 char serial_number_buffer[256];
179 size_t serial_number_buffer_size =
sizeof(serial_number_buffer);
180 if (K4A_BUFFER_RESULT_SUCCEEDED !=
182 &serial_number_buffer_size)) {
184 "Runtime error: k4a_plugin::k4a_device_get_serialnum() "
189 k4a_hardware_version_t version_info;
192 "Runtime error: k4a_plugin::k4a_device_get_version() failed");
198 (version_info.firmware_build == K4A_FIRMWARE_BUILD_RELEASE
202 version_info.rgb.minor, version_info.rgb.iteration);
204 version_info.depth.minor, version_info.depth.iteration,
205 version_info.depth_sensor.major,
206 version_info.depth_sensor.minor);
212 if (device_count > 0) {
213 for (uint8_t i = 0; i < device_count; i++) {
232 k4a_capture_t capture, k4a_transformation_t transformation) {
233 static std::shared_ptr<geometry::Image> color_buffer =
nullptr;
234 static std::shared_ptr<geometry::RGBDImage> rgbd_buffer =
nullptr;
236 if (color_buffer ==
nullptr) {
237 color_buffer = std::make_shared<geometry::Image>();
239 if (rgbd_buffer ==
nullptr) {
240 rgbd_buffer = std::make_shared<geometry::RGBDImage>();
245 if (k4a_color ==
nullptr || k4a_depth ==
nullptr) {
251 if (K4A_IMAGE_FORMAT_COLOR_MJPG !=
254 "Unexpected image format. The stream may have been corrupted.");
262 rgbd_buffer->color_.Prepare(
width,
height, 3,
sizeof(uint8_t));
263 color_buffer->Prepare(
width,
height, 4,
sizeof(uint8_t));
266 tjHandle = tjInitDecompress();
269 static_cast<unsigned long>(
272 TJPF_BGRA, TJFLAG_FASTDCT | TJFLAG_FASTUPSAMPLE)) {
280 k4a_image_t k4a_transformed_depth =
nullptr;
281 if (transformation) {
282 rgbd_buffer->depth_.Prepare(
width,
height, 1,
sizeof(uint16_t));
285 width *
sizeof(uint16_t), rgbd_buffer->depth_.data_.data(),
287 &k4a_transformed_depth);
288 if (K4A_RESULT_SUCCEEDED !=
290 transformation, k4a_depth, k4a_transformed_depth)) {
292 "Failed to transform depth frame to color frame.");
296 rgbd_buffer->depth_.Prepare(
300 memcpy(rgbd_buffer->depth_.data_.data(),
308 if (transformation) {
The Image class stores image with customizable width, height, num of channels and bytes per channel.
int num_of_channels_
Number of chanels in the image.
int height_
Height of the image.
int bytes_per_channel_
Number of bytes per channel.
int width_
Width of the image.
T * PointerAt(int u, int v) const
Function to access the raw data of a single-channel Image.
_k4a_device_configuration_t ConvertToNativeConfig() const
static bool PrintFirmware(_k4a_device_t *device)
AzureKinectSensorConfig sensor_config_
static bool ListDevices()
List available Azure Kinect devices.
bool Connect(size_t sensor_index) override
std::shared_ptr< geometry::RGBDImage > CaptureFrame(bool enable_align_depth_to_color) const override
AzureKinectSensor(const AzureKinectSensorConfig &sensor_config)
Default Constructor.
static std::shared_ptr< geometry::RGBDImage > DecompressCapture(_k4a_capture_t *capture, _k4a_transformation_t *transformation)
_k4a_capture_t * CaptureRawFrame() const
_k4a_transformation_t * transform_depth_to_color_
uint32_t k4a_device_get_installed_count()
k4a_image_t k4a_capture_get_depth_image(k4a_capture_t capture_handle)
void k4a_capture_release(k4a_capture_t capture_handle)
k4a_result_t k4a_image_create_from_buffer(k4a_image_format_t format, int width_pixels, int height_pixels, int stride_bytes, uint8_t *buffer, size_t buffer_size, k4a_memory_destroy_cb_t *buffer_release_cb, void *buffer_release_cb_context, k4a_image_t *image_handle)
k4a_result_t k4a_device_open(uint32_t index, k4a_device_t *device_handle)
k4a_result_t k4a_device_get_calibration(k4a_device_t device_handle, const k4a_depth_mode_t depth_mode, const k4a_color_resolution_t color_resolution, k4a_calibration_t *calibration)
k4a_result_t k4a_device_get_version(k4a_device_t device_handle, k4a_hardware_version_t *version)
void k4a_image_release(k4a_image_t image_handle)
k4a_result_t k4a_device_set_color_control(k4a_device_t device_handle, k4a_color_control_command_t command, k4a_color_control_mode_t mode, int32_t value)
uint8_t * k4a_image_get_buffer(k4a_image_t image_handle)
void k4a_device_close(k4a_device_t device_handle)
int k4a_image_get_height_pixels(k4a_image_t image_handle)
k4a_image_format_t k4a_image_get_format(k4a_image_t image_handle)
k4a_buffer_result_t k4a_device_get_serialnum(k4a_device_t device_handle, char *serial_number, size_t *serial_number_size)
k4a_transformation_t k4a_transformation_create(const k4a_calibration_t *calibration)
k4a_result_t k4a_transformation_depth_image_to_color_camera(k4a_transformation_t transformation_handle, const k4a_image_t depth_image, k4a_image_t transformed_depth_image)
void k4a_device_stop_cameras(k4a_device_t device_handle)
k4a_image_t k4a_capture_get_color_image(k4a_capture_t capture_handle)
k4a_wait_result_t k4a_device_get_capture(k4a_device_t device_handle, k4a_capture_t *capture_handle, int32_t timeout_in_ms)
size_t k4a_image_get_size(k4a_image_t image_handle)
int k4a_image_get_width_pixels(k4a_image_t image_handle)
k4a_result_t k4a_device_start_cameras(k4a_device_t device_handle, k4a_device_configuration_t *config)
void ConvertBGRAToRGB(geometry::Image &bgra, geometry::Image &rgb)
Generic file read and write utility for python interface.