Azure Kinect Sensor SDK  refs/heads/feature/transformation-custom-image-support
Documentation for https://github.com/Microsoft/Azure-Kinect-Sensor-SDK
k4a.hpp
1 
7 #ifndef K4A_HPP
8 #define K4A_HPP
9 
10 #include "k4a.h"
11 
12 #include <algorithm>
13 #include <chrono>
14 #include <cstdint>
15 #include <limits>
16 #include <stdexcept>
17 #include <string>
18 #include <vector>
19 
20 namespace k4a
21 {
22 
33 class error : public std::runtime_error
34 {
35 public:
36  using runtime_error::runtime_error;
37 };
38 
39 // Helper functions not intended for use by client code
40 //
41 namespace internal
42 {
44 
51 template<typename output_type, typename input_type> output_type clamp_cast(input_type input)
52 {
53  static_assert(std::is_arithmetic<input_type>::value, "clamp_cast only supports arithmetic types");
54  static_assert(std::is_arithmetic<output_type>::value, "clamp_cast only supports arithmetic types");
55  const input_type min_value = std::is_signed<input_type>() ?
56  static_cast<input_type>(std::numeric_limits<output_type>::min()) :
57  0;
58 
59  input_type max_value = static_cast<input_type>(std::numeric_limits<output_type>::max());
60  if (max_value < 0)
61  {
62  // Output type is of greater or equal size to input type and we've overflowed.
63  //
64  max_value = std::numeric_limits<input_type>::max();
65  }
66  input = std::min(input, max_value);
67  input = std::max(input, min_value);
68  return static_cast<output_type>(input);
69 }
71 } // namespace internal
72 
80 class image
81 {
82 public:
88  image(k4a_image_t handle = nullptr) noexcept : m_handle(handle) {}
89 
92  image(const image &other) noexcept : m_handle(other.m_handle)
93  {
94  if (m_handle != nullptr)
95  {
96  k4a_image_reference(m_handle);
97  }
98  }
99 
102  image(image &&other) noexcept : m_handle(other.m_handle)
103  {
104  other.m_handle = nullptr;
105  }
106 
107  ~image()
108  {
109  reset();
110  }
111 
114  image &operator=(const image &other) noexcept
115  {
116  if (this != &other)
117  {
118  reset();
119  m_handle = other.m_handle;
120  if (m_handle != nullptr)
121  {
122  k4a_image_reference(m_handle);
123  }
124  }
125  return *this;
126  }
127 
130  image &operator=(image &&other) noexcept
131  {
132  if (this != &other)
133  {
134  reset();
135  m_handle = other.m_handle;
136  other.m_handle = nullptr;
137  }
138  return *this;
139  }
140 
143  image &operator=(std::nullptr_t) noexcept
144  {
145  reset();
146  return *this;
147  }
148 
151  bool operator==(const image &other) const noexcept
152  {
153  return m_handle == other.m_handle;
154  }
155 
158  bool operator==(std::nullptr_t) const noexcept
159  {
160  return m_handle == nullptr;
161  }
162 
165  bool operator!=(const image &other) const noexcept
166  {
167  return m_handle != other.m_handle;
168  }
169 
172  bool operator!=(std::nullptr_t) const noexcept
173  {
174  return m_handle != nullptr;
175  }
176 
179  operator bool() const noexcept
180  {
181  return m_handle != nullptr;
182  }
183 
186  k4a_image_t handle() const noexcept
187  {
188  return m_handle;
189  }
190 
193  void reset() noexcept
194  {
195  if (m_handle != nullptr)
196  {
197  k4a_image_release(m_handle);
198  m_handle = nullptr;
199  }
200  }
201 
207  static image create(k4a_image_format_t format, int width_pixels, int height_pixels, int stride_bytes)
208  {
209  k4a_image_t handle = nullptr;
210  k4a_result_t result = k4a_image_create(format, width_pixels, height_pixels, stride_bytes, &handle);
211  if (K4A_RESULT_SUCCEEDED != result)
212  {
213  throw error("Failed to create image!");
214  }
215  return image(handle);
216  }
217 
224  int width_pixels,
225  int height_pixels,
226  int stride_bytes,
227  uint8_t *buffer,
228  size_t buffer_size,
229  k4a_memory_destroy_cb_t *buffer_release_cb,
230  void *buffer_release_cb_context)
231  {
232  k4a_image_t handle = nullptr;
233  k4a_result_t result = k4a_image_create_from_buffer(format,
234  width_pixels,
235  height_pixels,
236  stride_bytes,
237  buffer,
238  buffer_size,
239  buffer_release_cb,
240  buffer_release_cb_context,
241  &handle);
242  if (K4A_RESULT_SUCCEEDED != result)
243  {
244  throw error("Failed to create image from buffer");
245  }
246  return image(handle);
247  }
248 
253  uint8_t *get_buffer() noexcept
254  {
255  return k4a_image_get_buffer(m_handle);
256  }
257 
262  const uint8_t *get_buffer() const noexcept
263  {
264  return k4a_image_get_buffer(m_handle);
265  }
266 
271  size_t get_size() const noexcept
272  {
273  return k4a_image_get_size(m_handle);
274  }
275 
281  {
282  return k4a_image_get_format(m_handle);
283  }
284 
289  int get_width_pixels() const noexcept
290  {
291  return k4a_image_get_width_pixels(m_handle);
292  }
293 
298  int get_height_pixels() const noexcept
299  {
300  return k4a_image_get_height_pixels(m_handle);
301  }
302 
307  int get_stride_bytes() const noexcept
308  {
309  return k4a_image_get_stride_bytes(m_handle);
310  }
311 
316  std::chrono::microseconds get_device_timestamp() const noexcept
317  {
318  return std::chrono::microseconds(k4a_image_get_device_timestamp_usec(m_handle));
319  }
320 
325  std::chrono::nanoseconds get_system_timestamp() const noexcept
326  {
327  return std::chrono::nanoseconds(k4a_image_get_system_timestamp_nsec(m_handle));
328  }
329 
334  std::chrono::microseconds get_exposure() const noexcept
335  {
336  return std::chrono::microseconds(k4a_image_get_exposure_usec(m_handle));
337  }
338 
343  uint32_t get_white_balance() const noexcept
344  {
345  return k4a_image_get_white_balance(m_handle);
346  }
347 
352  uint32_t get_iso_speed() const noexcept
353  {
354  return k4a_image_get_iso_speed(m_handle);
355  }
356 
361  void set_timestamp(std::chrono::microseconds timestamp) noexcept
362  {
363  k4a_image_set_device_timestamp_usec(m_handle, internal::clamp_cast<uint64_t>(timestamp.count()));
364  }
365 
370  void set_exposure_time(std::chrono::microseconds exposure) noexcept
371  {
372  k4a_image_set_exposure_usec(m_handle, internal::clamp_cast<uint64_t>(exposure.count()));
373  }
374 
379  void set_white_balance(uint32_t white_balance) noexcept
380  {
381  k4a_image_set_white_balance(m_handle, white_balance);
382  }
383 
388  void set_iso_speed(uint32_t iso_speed) noexcept
389  {
390  k4a_image_set_iso_speed(m_handle, iso_speed);
391  }
392 
393 private:
394  k4a_image_t m_handle;
395 };
396 
402 class capture
403 {
404 public:
410  capture(k4a_capture_t handle = nullptr) noexcept : m_handle(handle) {}
411 
414  capture(const capture &other) noexcept : m_handle(other.m_handle)
415  {
416  if (m_handle != nullptr)
417  {
418  k4a_capture_reference(m_handle);
419  }
420  }
421 
424  capture(capture &&other) noexcept : m_handle(other.m_handle)
425  {
426  other.m_handle = nullptr;
427  }
428 
429  ~capture()
430  {
431  reset();
432  }
433 
436  capture &operator=(const capture &other) noexcept
437  {
438  if (this != &other)
439  {
440  reset();
441  m_handle = other.m_handle;
442  if (m_handle != nullptr)
443  {
444  k4a_capture_reference(m_handle);
445  }
446  }
447  return *this;
448  }
449 
452  capture &operator=(capture &&other) noexcept
453  {
454  if (this != &other)
455  {
456  reset();
457  m_handle = other.m_handle;
458  other.m_handle = nullptr;
459  }
460  return *this;
461  }
462 
465  capture &operator=(std::nullptr_t) noexcept
466  {
467  reset();
468  return *this;
469  }
470 
473  bool operator==(const capture &other) const noexcept
474  {
475  return m_handle == other.m_handle;
476  }
477 
480  bool operator==(std::nullptr_t) const noexcept
481  {
482  return m_handle == nullptr;
483  }
484 
487  bool operator!=(const capture &other) const noexcept
488  {
489  return m_handle != other.m_handle;
490  }
491 
494  bool operator!=(std::nullptr_t) const noexcept
495  {
496  return m_handle != nullptr;
497  }
498 
501  operator bool() const noexcept
502  {
503  return m_handle != nullptr;
504  }
505 
508  void reset() noexcept
509  {
510  if (m_handle != nullptr)
511  {
512  k4a_capture_release(m_handle);
513  m_handle = nullptr;
514  }
515  }
516 
521  image get_color_image() const noexcept
522  {
523  return image(k4a_capture_get_color_image(m_handle));
524  }
525 
530  image get_depth_image() const noexcept
531  {
532  return image(k4a_capture_get_depth_image(m_handle));
533  }
534 
539  image get_ir_image() const noexcept
540  {
541  return image(k4a_capture_get_ir_image(m_handle));
542  }
543 
548  void set_color_image(const image &color_image) noexcept
549  {
550  k4a_capture_set_color_image(m_handle, color_image.handle());
551  }
552 
557  void set_depth_image(const image &depth_image) noexcept
558  {
559  k4a_capture_set_depth_image(m_handle, depth_image.handle());
560  }
561 
566  void set_ir_image(const image &ir_image) noexcept
567  {
568  k4a_capture_set_ir_image(m_handle, ir_image.handle());
569  }
570 
575  void set_temperature_c(float temperature_c) noexcept
576  {
577  k4a_capture_set_temperature_c(m_handle, temperature_c);
578  }
579 
584  float get_temperature_c() const noexcept
585  {
586  return k4a_capture_get_temperature_c(m_handle);
587  }
588 
594  static capture create()
595  {
596  k4a_capture_t handle = nullptr;
597  k4a_result_t result = k4a_capture_create(&handle);
598  if (K4A_RESULT_SUCCEEDED != result)
599  {
600  throw error("Failed to create capture!");
601  }
602  return capture(handle);
603  }
604 
605 private:
606  k4a_capture_t m_handle;
607 };
608 
615 {
622  k4a_calibration_type_t source_camera,
623  k4a_calibration_type_t target_camera) const
624  {
625  k4a_float3_t target_point3d;
626  k4a_result_t result =
627  k4a_calibration_3d_to_3d(this, &source_point3d, source_camera, target_camera, &target_point3d);
628 
629  if (K4A_RESULT_SUCCEEDED != result)
630  {
631  throw error("Calibration contained invalid transformation parameters!");
632  }
633  return target_point3d;
634  }
635 
644  bool convert_2d_to_3d(const k4a_float2_t &source_point2d,
645  float source_depth,
646  k4a_calibration_type_t source_camera,
647  k4a_calibration_type_t target_camera,
648  k4a_float3_t *target_point3d) const
649  {
650  int valid = 0;
652  this, &source_point2d, source_depth, source_camera, target_camera, target_point3d, &valid);
653 
654  if (K4A_RESULT_SUCCEEDED != result)
655  {
656  throw error("Calibration contained invalid transformation parameters!");
657  }
658  return static_cast<bool>(valid);
659  }
660 
668  bool convert_3d_to_2d(const k4a_float3_t &source_point3d,
669  k4a_calibration_type_t source_camera,
670  k4a_calibration_type_t target_camera,
671  k4a_float2_t *target_point2d) const
672  {
673  int valid = 0;
674  k4a_result_t result =
675  k4a_calibration_3d_to_2d(this, &source_point3d, source_camera, target_camera, target_point2d, &valid);
676 
677  if (K4A_RESULT_SUCCEEDED != result)
678  {
679  throw error("Calibration contained invalid transformation parameters!");
680  }
681  return static_cast<bool>(valid);
682  }
683 
692  bool convert_2d_to_2d(const k4a_float2_t &source_point2d,
693  float source_depth,
694  k4a_calibration_type_t source_camera,
695  k4a_calibration_type_t target_camera,
696  k4a_float2_t *target_point2d) const
697  {
698  int valid = 0;
700  this, &source_point2d, source_depth, source_camera, target_camera, target_point2d, &valid);
701 
702  if (K4A_RESULT_SUCCEEDED != result)
703  {
704  throw error("Calibration contained invalid transformation parameters!");
705  }
706  return static_cast<bool>(valid);
707  }
708 
714  static calibration get_from_raw(char *raw_calibration,
715  size_t raw_calibration_size,
718  {
719  calibration calib;
720  k4a_result_t result =
721  k4a_calibration_get_from_raw(raw_calibration, raw_calibration_size, depth_mode, color_resolution, &calib);
722 
723  if (K4A_RESULT_SUCCEEDED != result)
724  {
725  throw error("Failed to load calibration from raw calibration blob!");
726  }
727  return calib;
728  }
729 
735  static calibration get_from_raw(uint8_t *raw_calibration,
736  size_t raw_calibration_size,
739  {
740  return get_from_raw(reinterpret_cast<char *>(raw_calibration),
741  raw_calibration_size,
742  depth_mode,
743  color_resolution);
744  }
745 
751  static calibration get_from_raw(std::vector<uint8_t> &raw_calibration,
754  {
755  return get_from_raw(reinterpret_cast<char *>(raw_calibration.data()),
756  raw_calibration.size(),
757  depth_mode,
759  }
760 };
761 
768 {
769 public:
774  transformation(const k4a_calibration_t &calibration) noexcept : m_handle(k4a_transformation_create(&calibration)) {}
775 
781  transformation(k4a_transformation_t handle = nullptr) noexcept : m_handle(handle) {}
782 
785  transformation(transformation &&other) noexcept : m_handle(other.m_handle)
786  {
787  other.m_handle = nullptr;
788  }
789 
790  transformation(const transformation &) = delete;
791 
792  ~transformation()
793  {
794  destroy();
795  }
796 
800  {
801  if (this != &other)
802  {
803  destroy();
804  m_handle = other.m_handle;
805  other.m_handle = nullptr;
806  }
807 
808  return *this;
809  }
810 
813  transformation &operator=(std::nullptr_t) noexcept
814  {
815  destroy();
816  return *this;
817  }
818 
819  transformation &operator=(const transformation &) = delete;
820 
823  void destroy() noexcept
824  {
825  if (m_handle != nullptr)
826  {
827  k4a_transformation_destroy(m_handle);
828  m_handle = nullptr;
829  }
830  }
831 
837  void depth_image_to_color_camera(const image &depth_image, image *transformed_depth_image) const
838  {
839  k4a_result_t result = k4a_transformation_depth_image_to_color_camera(m_handle,
840  depth_image.handle(),
841  transformed_depth_image->handle());
842  if (K4A_RESULT_SUCCEEDED != result)
843  {
844  throw error("Failed to convert depth map to color camera geometry!");
845  }
846  }
847 
853  void depth_image_to_color_camera_custom(const image &depth_image,
854  const image &custom_image,
855  image *transformed_depth_image,
856  image *transformed_custom_image,
857  k4a_transformation_interpolation_type_t interpolation_type,
858  uint32_t invalid_custom_value) const
859  {
860  k4a_result_t result = k4a_transformation_depth_image_to_color_camera_custom(m_handle,
861  depth_image.handle(),
862  custom_image.handle(),
863  transformed_depth_image->handle(),
864  transformed_custom_image->handle(),
865  interpolation_type,
866  invalid_custom_value);
867  if (K4A_RESULT_SUCCEEDED != result)
868  {
869  throw error("Failed to convert depth map and custom image to color camera geometry!");
870  }
871  }
872 
878  void color_image_to_depth_camera(const image &depth_image,
879  const image &color_image,
880  image *transformed_color_image) const
881  {
882  k4a_result_t result = k4a_transformation_color_image_to_depth_camera(m_handle,
883  depth_image.handle(),
884  color_image.handle(),
885  transformed_color_image->handle());
886  if (K4A_RESULT_SUCCEEDED != result)
887  {
888  throw error("Failed to convert color image to depth camera geometry!");
889  }
890  }
891 
897  void depth_image_to_point_cloud(const image &depth_image, k4a_calibration_type_t camera, image *xyz_image) const
898  {
899  k4a_result_t result =
900  k4a_transformation_depth_image_to_point_cloud(m_handle, depth_image.handle(), camera, xyz_image->handle());
901  if (K4A_RESULT_SUCCEEDED != result)
902  {
903  throw error("Failed to transform depth image to point cloud!");
904  }
905  }
906 
907 private:
908  k4a_transformation_t m_handle;
909 };
910 
916 class device
917 {
918 public:
924  device(k4a_device_t handle = nullptr) noexcept : m_handle(handle) {}
925 
928  device(device &&dev) noexcept : m_handle(dev.m_handle)
929  {
930  dev.m_handle = nullptr;
931  }
932 
933  device(const device &) = delete;
934 
935  ~device()
936  {
937  close();
938  }
939 
940  device &operator=(const device &) = delete;
941 
944  device &operator=(device &&dev) noexcept
945  {
946  if (this != &dev)
947  {
948  close();
949  m_handle = dev.m_handle;
950  dev.m_handle = nullptr;
951  }
952  return *this;
953  }
954 
957  operator bool() const noexcept
958  {
959  return m_handle != nullptr;
960  }
961 
966  void close() noexcept
967  {
968  if (m_handle != nullptr)
969  {
970  k4a_device_close(m_handle);
971  m_handle = nullptr;
972  }
973  }
974 
980  bool get_capture(capture *cap, std::chrono::milliseconds timeout)
981  {
982  k4a_capture_t capture_handle = nullptr;
983  int32_t timeout_ms = internal::clamp_cast<int32_t>(timeout.count());
984  k4a_wait_result_t result = k4a_device_get_capture(m_handle, &capture_handle, timeout_ms);
985  if (result == K4A_WAIT_RESULT_FAILED)
986  {
987  throw error("Failed to get capture from device!");
988  }
989  else if (result == K4A_WAIT_RESULT_TIMEOUT)
990  {
991  return false;
992  }
993 
994  *cap = capture(capture_handle);
995  return true;
996  }
997 
1003  bool get_imu_sample(k4a_imu_sample_t *imu_sample, std::chrono::milliseconds timeout)
1004  {
1005  int32_t timeout_ms = internal::clamp_cast<int32_t>(timeout.count());
1006  k4a_wait_result_t result = k4a_device_get_imu_sample(m_handle, imu_sample, timeout_ms);
1007  if (result == K4A_WAIT_RESULT_FAILED)
1008  {
1009  throw error("Failed to get IMU sample from device!");
1010  }
1011  else if (result == K4A_WAIT_RESULT_TIMEOUT)
1012  {
1013  return false;
1014  }
1015 
1016  return true;
1017  }
1018 
1024  void start_cameras(const k4a_device_configuration_t *configuration)
1025  {
1026  k4a_result_t result = k4a_device_start_cameras(m_handle, configuration);
1027  if (K4A_RESULT_SUCCEEDED != result)
1028  {
1029  throw error("Failed to start cameras!");
1030  }
1031  }
1032 
1037  void stop_cameras() noexcept
1038  {
1039  k4a_device_stop_cameras(m_handle);
1040  }
1041 
1047  void start_imu()
1048  {
1049  k4a_result_t result = k4a_device_start_imu(m_handle);
1050  if (K4A_RESULT_SUCCEEDED != result)
1051  {
1052  throw error("Failed to start IMU!");
1053  }
1054  }
1055 
1060  void stop_imu() noexcept
1061  {
1062  k4a_device_stop_imu(m_handle);
1063  }
1064 
1070  std::string get_serialnum() const
1071  {
1072  std::string serialnum;
1073  size_t buffer = 0;
1074  k4a_buffer_result_t result = k4a_device_get_serialnum(m_handle, &serialnum[0], &buffer);
1075 
1076  if (result == K4A_BUFFER_RESULT_TOO_SMALL && buffer > 1)
1077  {
1078  serialnum.resize(buffer);
1079  result = k4a_device_get_serialnum(m_handle, &serialnum[0], &buffer);
1080  if (result == K4A_BUFFER_RESULT_SUCCEEDED && serialnum[buffer - 1] == 0)
1081  {
1082  // std::string expects there to not be as null terminator at the end of its data but
1083  // k4a_device_get_serialnum adds a null terminator, so we drop the last character of the string after we
1084  // get the result back.
1085  serialnum.resize(buffer - 1);
1086  }
1087  }
1088 
1089  if (result != K4A_BUFFER_RESULT_SUCCEEDED)
1090  {
1091  throw error("Failed to read device serial number!");
1092  }
1093 
1094  return serialnum;
1095  }
1096 
1103  {
1104  k4a_result_t result = k4a_device_get_color_control(m_handle, command, mode, value);
1105  if (K4A_RESULT_SUCCEEDED != result)
1106  {
1107  throw error("Failed to read color control!");
1108  }
1109  }
1110 
1117  {
1118  k4a_result_t result = k4a_device_set_color_control(m_handle, command, mode, value);
1119  if (K4A_RESULT_SUCCEEDED != result)
1120  {
1121  throw error("Failed to set color control!");
1122  }
1123  }
1124 
1130  std::vector<uint8_t> get_raw_calibration() const
1131  {
1132  std::vector<uint8_t> calibration;
1133  size_t buffer = 0;
1134  k4a_buffer_result_t result = k4a_device_get_raw_calibration(m_handle, &calibration[0], &buffer);
1135 
1136  if (result == K4A_BUFFER_RESULT_TOO_SMALL && buffer > 1)
1137  {
1138  calibration.resize(buffer);
1139  result = k4a_device_get_raw_calibration(m_handle, &calibration[0], &buffer);
1140  }
1141 
1142  if (result != K4A_BUFFER_RESULT_SUCCEEDED)
1143  {
1144  throw error("Failed to read raw device calibration!");
1145  }
1146 
1147  return calibration;
1148  }
1149 
1156  {
1157  calibration calib;
1158  k4a_result_t result = k4a_device_get_calibration(m_handle, depth_mode, color_resolution, &calib);
1159 
1160  if (K4A_RESULT_SUCCEEDED != result)
1161  {
1162  throw error("Failed to read device calibration!");
1163  }
1164  return calib;
1165  }
1166 
1173  {
1174  bool sync_in_jack_connected, sync_out_jack_connected;
1175  k4a_result_t result = k4a_device_get_sync_jack(m_handle, &sync_in_jack_connected, &sync_out_jack_connected);
1176 
1177  if (K4A_RESULT_SUCCEEDED != result)
1178  {
1179  throw error("Failed to read sync jack status!");
1180  }
1181  return sync_in_jack_connected;
1182  }
1183 
1190  {
1191  bool sync_in_jack_connected, sync_out_jack_connected;
1192  k4a_result_t result = k4a_device_get_sync_jack(m_handle, &sync_in_jack_connected, &sync_out_jack_connected);
1193 
1194  if (K4A_RESULT_SUCCEEDED != result)
1195  {
1196  throw error("Failed to read sync jack status!");
1197  }
1198  return sync_out_jack_connected;
1199  }
1200 
1207  {
1208  k4a_hardware_version_t version;
1209  k4a_result_t result = k4a_device_get_version(m_handle, &version);
1210 
1211  if (K4A_RESULT_SUCCEEDED != result)
1212  {
1213  throw error("Failed to read device firmware information!");
1214  }
1215  return version;
1216  }
1217 
1223  static device open(uint32_t index)
1224  {
1225  k4a_device_t handle = nullptr;
1226  k4a_result_t result = k4a_device_open(index, &handle);
1227 
1228  if (K4A_RESULT_SUCCEEDED != result)
1229  {
1230  throw error("Failed to open device!");
1231  }
1232  return device(handle);
1233  }
1234 
1239  static uint32_t get_installed_count() noexcept
1240  {
1241  return k4a_device_get_installed_count();
1242  }
1243 
1244 private:
1245  k4a_device_t m_handle;
1246 };
1247 
1252 } // namespace k4a
1253 
1254 #endif
bool is_sync_out_connected() const
Get the device jack status for the synchronization out connector Throws error on failure.
Definition: k4a.hpp:1189
k4a_color_resolution_t color_resolution
Color camera resolution for which calibration was obtained.
Definition: k4atypes.h:1111
Calibration type representing device calibration.
Definition: k4atypes.h:1096
The result was successful.
Definition: k4atypes.h:233
transformation(const k4a_calibration_t &calibration) noexcept
Creates a transformation associated with calibration.
Definition: k4a.hpp:774
void reset() noexcept
Releases the underlying k4a_image_t; the image is set to invalid.
Definition: k4a.hpp:193
k4a_float3_t convert_3d_to_3d(const k4a_float3_t &source_point3d, k4a_calibration_type_t source_camera, k4a_calibration_type_t target_camera) const
Transform a 3d point of a source coordinate system into a 3d point of the target coordinate system...
Definition: k4a.hpp:621
capture & operator=(capture &&other) noexcept
Moves another capture into this capture; other is set to invalid.
Definition: k4a.hpp:452
transformation(transformation &&other) noexcept
Moves another tranformation into a new transformation.
Definition: k4a.hpp:785
k4a_image_t handle() const noexcept
Returns the underlying k4a_image_t handle.
Definition: k4a.hpp:186
void set_exposure_time(std::chrono::microseconds exposure) noexcept
Set the image&#39;s exposure time in microseconds (color images only)
Definition: k4a.hpp:370
k4a_depth_mode_t depth_mode
Depth camera mode for which calibration was obtained.
Definition: k4atypes.h:1110
const uint8_t * get_buffer() const noexcept
Get the image buffer.
Definition: k4a.hpp:262
Structure to define hardware version.
Definition: k4atypes.h:1138
int get_stride_bytes() const noexcept
Get the image stride in bytes.
Definition: k4a.hpp:307
k4a_result_t
Result code returned by Azure Kinect APIs.
Definition: k4atypes.h:217
Exception type thrown when a K4A API call fails.
Definition: k4a.hpp:33
void set_color_image(const image &color_image) noexcept
Set / add a color image to the capture.
Definition: k4a.hpp:548
void set_depth_image(const image &depth_image) noexcept
Set / add a depth image to the capture.
Definition: k4a.hpp:557
size_t get_size() const noexcept
Get the image buffer size in bytes.
Definition: k4a.hpp:271
k4a_depth_mode_t
Depth sensor capture modes.
Definition: k4atypes.h:290
Handle to an Azure Kinect capture.
Definition: k4atypes.h:122
bool operator==(std::nullptr_t) const noexcept
Returns false if the capture is valid, true otherwise.
Definition: k4a.hpp:480
uint32_t get_white_balance() const noexcept
Get the image white balance in Kelvin (color images only)
Definition: k4a.hpp:343
k4a_buffer_result_t
Result code returned by Azure Kinect APIs.
Definition: k4atypes.h:231
static device open(uint32_t index)
Open a k4a device.
Definition: k4a.hpp:1223
capture & operator=(const capture &other) noexcept
Sets capture to a shallow copy of other.
Definition: k4a.hpp:436
void depth_image_to_color_camera(const image &depth_image, image *transformed_depth_image) const
Transforms the depth map into the geometry of the color camera.
Definition: k4a.hpp:837
Wrapper for k4a_transformation_t.
Definition: k4a.hpp:767
The operation timed out.
Definition: k4atypes.h:250
image(k4a_image_t handle=nullptr) noexcept
Creates an image from a k4a_image_t.
Definition: k4a.hpp:88
device & operator=(device &&dev) noexcept
Moves another device into this device; other is set to invalid.
Definition: k4a.hpp:944
std::vector< uint8_t > get_raw_calibration() const
Get the raw calibration blob for the entire K4A device.
Definition: k4a.hpp:1130
int get_width_pixels() const noexcept
Get the image width in pixels.
Definition: k4a.hpp:289
IMU sample.
Definition: k4atypes.h:1196
std::chrono::microseconds get_exposure() const noexcept
Get the image exposure time in microseconds.
Definition: k4a.hpp:334
void start_cameras(const k4a_device_configuration_t *configuration)
Starts the K4A device&#39;s cameras Throws error on failure.
Definition: k4a.hpp:1024
bool operator!=(const capture &other) const noexcept
Returns true if two captures wrap different k4a_capture_t instances, false otherwise.
Definition: k4a.hpp:487
bool convert_2d_to_2d(const k4a_float2_t &source_point2d, float source_depth, k4a_calibration_type_t source_camera, k4a_calibration_type_t target_camera, k4a_float2_t *target_point2d) const
Transform a 2d pixel coordinate with an associated depth value of the source camera into a 2d pixel c...
Definition: k4a.hpp:692
k4a_transformation_interpolation_type_t
Transformation interpolation type.
Definition: k4atypes.h:459
transformation & operator=(std::nullptr_t) noexcept
Invalidates this transformation.
Definition: k4a.hpp:813
Definition: k4a.hpp:20
std::chrono::microseconds get_device_timestamp() const noexcept
Get the image&#39;s device timestamp in microseconds.
Definition: k4a.hpp:316
k4a_result_t k4a_calibration_3d_to_2d(const k4a_calibration_t *calibration, const k4a_float3_t *source_point3d_mm, const k4a_calibration_type_t source_camera, const k4a_calibration_type_t target_camera, k4a_float2_t *target_point2d, int *valid)
Transform a 3D point of a source coordinate system into a 2D pixel coordinate of the target camera...
calibration get_calibration(k4a_depth_mode_t depth_mode, k4a_color_resolution_t color_resolution) const
Get the camera calibration for the entire K4A device, which is used for all transformation functions...
Definition: k4a.hpp:1155
void set_iso_speed(uint32_t iso_speed) noexcept
Set the ISO speed of the image (color images only)
Definition: k4a.hpp:388
void set_ir_image(const image &ir_image) noexcept
Set / add an IR image to the capture.
Definition: k4a.hpp:566
image & operator=(const image &other) noexcept
Sets image to a shallow copy of other.
Definition: k4a.hpp:114
static calibration get_from_raw(char *raw_calibration, size_t raw_calibration_size, k4a_depth_mode_t depth_mode, k4a_color_resolution_t color_resolution)
Get the camera calibration for a device from a raw calibration blob.
Definition: k4a.hpp:714
bool get_imu_sample(k4a_imu_sample_t *imu_sample, std::chrono::milliseconds timeout)
Reads an IMU sample.
Definition: k4a.hpp:1003
capture(capture &&other) noexcept
Moves another capture into a new capture.
Definition: k4a.hpp:424
std::chrono::nanoseconds get_system_timestamp() const noexcept
Get the image&#39;s system timestamp in nanoseconds.
Definition: k4a.hpp:325
bool is_sync_in_connected() const
Get the device jack status for the synchronization in connector Throws error on failure.
Definition: k4a.hpp:1172
k4a_calibration_type_t
Calibration types.
Definition: k4atypes.h:658
image get_color_image() const noexcept
Get the color image associated with the capture.
Definition: k4a.hpp:521
static uint32_t get_installed_count() noexcept
Gets the number of connected devices.
Definition: k4a.hpp:1239
bool operator!=(std::nullptr_t) const noexcept
Returns true if the capture is valid, false otherwise.
Definition: k4a.hpp:494
void get_color_control(k4a_color_control_command_t command, k4a_color_control_mode_t *mode, int32_t *value) const
Get the K4A color sensor control value Throws error on failure.
Definition: k4a.hpp:1102
static 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)
Create an image from a pre-allocated buffer Throws error on failure.
Definition: k4a.hpp:223
k4a_result_t k4a_calibration_2d_to_2d(const k4a_calibration_t *calibration, const k4a_float2_t *source_point2d, const float source_depth_mm, const k4a_calibration_type_t source_camera, const k4a_calibration_type_t target_camera, k4a_float2_t *target_point2d, int *valid)
Transform a 2D pixel coordinate with an associated depth value of the source camera into a 2D pixel c...
void set_timestamp(std::chrono::microseconds timestamp) noexcept
Set the image&#39;s timestamp in microseconds.
Definition: k4a.hpp:361
bool convert_3d_to_2d(const k4a_float3_t &source_point3d, k4a_calibration_type_t source_camera, k4a_calibration_type_t target_camera, k4a_float2_t *target_point2d) const
Transform a 3d point of a source coordinate system into a 2d pixel coordinate of the target camera...
Definition: k4a.hpp:668
Wrapper for k4a_capture_t.
Definition: k4a.hpp:402
void depth_image_to_color_camera_custom(const image &depth_image, const image &custom_image, image *transformed_depth_image, image *transformed_custom_image, k4a_transformation_interpolation_type_t interpolation_type, uint32_t invalid_custom_value) const
Transforms depth map and a custom image into the geometry of the color camera.
Definition: k4a.hpp:853
k4a_result_t k4a_calibration_3d_to_3d(const k4a_calibration_t *calibration, const k4a_float3_t *source_point3d_mm, const k4a_calibration_type_t source_camera, const k4a_calibration_type_t target_camera, k4a_float3_t *target_point3d_mm)
Transform a 3D point of a source coordinate system into a 3D point of the target coordinate system...
Three dimensional floating point vector.
Definition: k4atypes.h:1176
static calibration get_from_raw(std::vector< uint8_t > &raw_calibration, k4a_depth_mode_t depth_mode, k4a_color_resolution_t color_resolution)
Get the camera calibration for a device from a raw calibration blob.
Definition: k4a.hpp:751
bool operator!=(std::nullptr_t) const noexcept
Returns true if the image is valid, false otherwise.
Definition: k4a.hpp:172
capture(k4a_capture_t handle=nullptr) noexcept
Creates a capture from a k4a_capture_t Takes ownership of the handle, i.e.
Definition: k4a.hpp:410
static capture create()
Create an empty capture object.
Definition: k4a.hpp:594
transformation(k4a_transformation_t handle=nullptr) noexcept
Creates a transformation from a k4a_transformation_t Takes ownership of the handle, i.e.
Definition: k4a.hpp:781
k4a_color_control_mode_t
Color sensor control mode.
Definition: k4atypes.h:622
std::string get_serialnum() const
Get the K4A device serial number Throws error on failure.
Definition: k4a.hpp:1070
bool operator!=(const image &other) const noexcept
Returns true if two images wrap different k4a_image_t instances, false otherwise. ...
Definition: k4a.hpp:165
capture(const capture &other) noexcept
Creates a shallow copy of another capture.
Definition: k4a.hpp:414
k4a_image_format_t get_format() const noexcept
Get the image format of the image.
Definition: k4a.hpp:280
int get_height_pixels() const noexcept
Get the image height in pixels.
Definition: k4a.hpp:298
Handle to an Azure Kinect transformation context.
Definition: k4atypes.h:195
k4a_color_resolution_t
Color sensor resolutions.
Definition: k4atypes.h:309
float get_temperature_c() const noexcept
Get temperature (in Celsius) associated with the capture.
Definition: k4a.hpp:584
void() k4a_memory_destroy_cb_t(void *buffer, void *context)
Callback function for a memory object being destroyed.
Definition: k4atypes.h:865
void set_white_balance(uint32_t white_balance) noexcept
Set the white balance of the image (color images only)
Definition: k4a.hpp:379
k4a_result_t k4a_calibration_2d_to_3d(const k4a_calibration_t *calibration, const k4a_float2_t *source_point2d, const float source_depth_mm, const k4a_calibration_type_t source_camera, const k4a_calibration_type_t target_camera, k4a_float3_t *target_point3d_mm, int *valid)
Transform a 2D pixel coordinate with an associated depth value of the source camera into a 3D point o...
The result was successful.
Definition: k4atypes.h:219
device(k4a_device_t handle=nullptr) noexcept
Creates a device from a k4a_device_t Takes ownership of the handle, i.e.
Definition: k4a.hpp:924
void destroy() noexcept
Invalidates this transformation.
Definition: k4a.hpp:823
void stop_imu() noexcept
Stops the K4A IMU.
Definition: k4a.hpp:1060
uint32_t get_iso_speed() const noexcept
Get the image&#39;s ISO speed (color images only)
Definition: k4a.hpp:352
image & operator=(image &&other) noexcept
Moves another image into this image; other is set to invalid.
Definition: k4a.hpp:130
Wrapper for k4a_image_t.
Definition: k4a.hpp:80
void set_temperature_c(float temperature_c) noexcept
Set the temperature associated with the capture in Celsius.
Definition: k4a.hpp:575
image get_ir_image() const noexcept
Get the IR image associated with the capture.
Definition: k4a.hpp:539
bool convert_2d_to_3d(const k4a_float2_t &source_point2d, float source_depth, k4a_calibration_type_t source_camera, k4a_calibration_type_t target_camera, k4a_float3_t *target_point3d) const
Transform a 2d pixel coordinate with an associated depth value of the source camera into a 3d point o...
Definition: k4a.hpp:644
device(device &&dev) noexcept
Moves another device into a new device.
Definition: k4a.hpp:928
static calibration get_from_raw(uint8_t *raw_calibration, size_t raw_calibration_size, k4a_depth_mode_t depth_mode, k4a_color_resolution_t color_resolution)
Get the camera calibration for a device from a raw calibration blob.
Definition: k4a.hpp:735
image & operator=(std::nullptr_t) noexcept
Invalidates this image.
Definition: k4a.hpp:143
Handle to an Azure Kinect device.
Definition: k4atypes.h:66
uint8_t * get_buffer() noexcept
Get the image buffer.
Definition: k4a.hpp:253
void color_image_to_depth_camera(const image &depth_image, const image &color_image, image *transformed_color_image) const
Transforms the color image into the geometry of the depth camera.
Definition: k4a.hpp:878
Two dimensional floating point vector.
Definition: k4atypes.h:1157
bool operator==(std::nullptr_t) const noexcept
Returns false if the image is valid, true otherwise.
Definition: k4a.hpp:158
Handle to an Azure Kinect image.
Definition: k4atypes.h:173
image(image &&other) noexcept
Moves another image into a new image.
Definition: k4a.hpp:102
image(const image &other) noexcept
Creates a shallow copy of another image.
Definition: k4a.hpp:92
bool get_capture(capture *cap, std::chrono::milliseconds timeout)
Reads a sensor capture into cap.
Definition: k4a.hpp:980
Wrapper for k4a_device_t.
Definition: k4a.hpp:916
void depth_image_to_point_cloud(const image &depth_image, k4a_calibration_type_t camera, image *xyz_image) const
Transforms the depth image into 3 planar images representing X, Y and Z-coordinates of corresponding ...
Definition: k4a.hpp:897
Configuration parameters for an Azure Kinect device.
Definition: k4atypes.h:914
The result was a failure.
Definition: k4atypes.h:249
void stop_cameras() noexcept
Stops the K4A device&#39;s cameras.
Definition: k4a.hpp:1037
The input buffer was too small.
Definition: k4atypes.h:235
capture & operator=(std::nullptr_t) noexcept
Invalidates this capture.
Definition: k4a.hpp:465
bool operator==(const capture &other) const noexcept
Returns true if two captures refer to the same k4a_capture_t, false otherwise.
Definition: k4a.hpp:473
void set_color_control(k4a_color_control_command_t command, k4a_color_control_mode_t mode, int32_t value)
Set the K4A color sensor control value Throws error on failure.
Definition: k4a.hpp:1116
bool operator==(const image &other) const noexcept
Returns true if two images refer to the same k4a_image_t, false otherwise.
Definition: k4a.hpp:151
k4a_color_control_command_t
Color sensor control commands.
Definition: k4atypes.h:503
k4a_hardware_version_t get_version() const
Get the version numbers of the K4A subsystems&#39; firmware Throws error on failure.
Definition: k4a.hpp:1206
static image create(k4a_image_format_t format, int width_pixels, int height_pixels, int stride_bytes)
Create a blank image Throws error on failure.
Definition: k4a.hpp:207
Wrapper for k4a_calibration_t.
Definition: k4a.hpp:614
void start_imu()
Starts the K4A IMU Throws error on failure.
Definition: k4a.hpp:1047
k4a_wait_result_t
Result code returned by Azure Kinect APIs.
Definition: k4atypes.h:246
transformation & operator=(transformation &&other) noexcept
Moves another image into this image; other is set to invalid.
Definition: k4a.hpp:799
k4a_image_format_t
Image format type.
Definition: k4atypes.h:332
void close() noexcept
Closes a k4a device.
Definition: k4a.hpp:966
image get_depth_image() const noexcept
Get the depth image associated with the capture.
Definition: k4a.hpp:530
void reset() noexcept
Releases the underlying k4a_capture_t; the capture is set to invalid.
Definition: k4a.hpp:508