2

I need to extract the color and depth data from the Azure Kinect and save that to file. I went through the SDK examples but I can't figure it out.

After setting everything up I can get the color data with:

  k4a_device_configuration_t config = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL;
  config.color_format = K4A_IMAGE_FORMAT_COLOR_BGRA32;
  config.color_resolution = K4A_COLOR_RESOLUTION_720P;
  config.depth_mode = K4A_DEPTH_MODE_NFOV_UNBINNED;
  config.camera_fps = K4A_FRAMES_PER_SECOND_30;
  k4a_device_start_cameras(device, &config);

  k4a_device_get_capture(device, &capture, TIMEOUT_IN_MS)

  k4a_image_t image;
  image = k4a_capture_get_color_image(capture);
  uint8_t* color_data = (uint8_t*)(void*)k4a_image_get_buffer(image);

and then what? How do I parse the color values for each pixel?

It's all new for me so any help would be appreciated. Thanks in advance, Guido

guidout
  • 322
  • 1
  • 4
  • 13

2 Answers2

2

This is how I did using OpenCV:

uint8_t* image_data = (uint8_t*)(void*)k4a_image_get_buffer(color_image);
cv::Mat color_frame = cv::Mat(k4a_image_get_height_pixels(color_image), k4a_image_get_width_pixels(color_image), CV_8UC4, image_data, cv::Mat::AUTO_STEP);
guidout
  • 322
  • 1
  • 4
  • 13
  • Thanks for sharing this. Btw k4a_image_get_buffer() already returns uint8_t * you don't need those casts – Pani Apr 08 '20 at 18:21
1

This depends on which coordinate system the point/pixel you want the color of is in. In the origin color space, it can be found directly in the buffer with index = y * width + x. Getting the color for points/pixels in other coordinate spaces require transformation from either the color or depth buffer. Details of this process can be found here in the SDK. I'm also developing a library that gets color data for depth points that may provide you with additional insight into this process.

Jak_Ene
  • 61
  • 1
  • 3