12 const static char *
const DEFAULT_URI =
"device/default";
16 template<
typename F,
typename T>
17 bool is_available(F &&f,
const T &stream)
19 bool is_available =
false;
20 return f(stream, &is_available) == ASTRA_STATUS_SUCCESS && is_available;
23 bool initialized =
false;
27 if (initialized)
return;
37 return std::shared_ptr<Device>(
new Device(configuration));
43 astra_status_t status = astra_update();
44 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
46 bool new_frame =
false;
47 astra_reader_has_new_frame(
reader_, &new_frame);
48 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
51 if (!new_frame)
return;
55 astra_reader_frame_t astra_frame;
57 status = astra_reader_open_frame(
reader_, 3, &astra_frame);
58 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
65 astra_colorframe_t color_frame;
66 status = astra_frame_get_colorframe(astra_frame, &color_frame);
67 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
70 status = astra_colorframe_get_data_ptr(color_frame, &color.
data, &color.
data_length);
71 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
73 astra_image_metadata_t metadata;
74 status = astra_colorframe_get_metadata(color_frame, &metadata);
75 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
85 astra_colorframe_t ir_frame;
86 status = astra_frame_get_infraredframe(astra_frame, &ir_frame);
87 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
90 status = astra_infraredframe_get_data_ptr(ir_frame, &ir.
data, &ir.
data_length);
91 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
93 astra_image_metadata_t metadata;
94 status = astra_infraredframe_get_metadata(ir_frame, &metadata);
95 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
105 astra_depthframe_t depth_frame;
106 status = astra_frame_get_depthframe(astra_frame, &depth_frame);
107 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
110 status = astra_depthframe_get_data_ptr(depth_frame, &depth.
data, &depth.
data_length);
111 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
113 astra_image_metadata_t metadata;
114 status = astra_depthframe_get_metadata(depth_frame, &metadata);
115 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
120 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
123 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
131 astra_bodyframe_t body_frame;
132 status = astra_frame_get_bodyframe(astra_frame, &body_frame);
133 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
136 status = astra_bodyframe_body_list(body_frame, &body.
body_list);
137 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
139 status = astra_bodyframe_bodymask(body_frame, &body.
body_mask);
140 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
142 status = astra_bodyframe_floor_info_ptr(body_frame, &body.
floor_info);
143 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
151 astra_colorizedbodyframe_t colorized_body_frame;
152 status = astra_frame_get_colorizedbodyframe(astra_frame, &colorized_body_frame);
153 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
156 status = astra_colorizedbodyframe_get_data_ptr(colorized_body_frame, &colorized_body.
data, &colorized_body.
data_length);
157 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
159 astra_image_metadata_t metadata;
160 status = astra_colorizedbodyframe_get_metadata(colorized_body_frame, &metadata);
161 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
171 astra_handframe_t hand_frame;
172 status = astra_frame_get_handframe(astra_frame, &hand_frame);
173 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
182 astra_maskedcolorframe_t masked_color_frame;
183 status = astra_frame_get_maskedcolorframe(astra_frame, &masked_color_frame);
184 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
187 status = astra_maskedcolorframe_get_data_ptr(masked_color_frame, &masked_color.
data, &masked_color.
data_length);
188 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
190 astra_image_metadata_t metadata;
191 status = astra_maskedcolorframe_get_metadata(masked_color_frame, &metadata);
192 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
201 astra_pointframe_t point_frame;
202 status = astra_frame_get_pointframe(astra_frame, &point_frame);
203 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
206 status = astra_pointframe_get_data_ptr(point_frame, &point.
data, &point.
data_length);
207 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
213 status = astra_reader_close_frame(&astra_frame);
214 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
218 : configuration_(configuration)
233 std::cout <<
"Configured license" << std::endl;
234 orbbec_body_tracking_set_license(license->c_str());
238 astra_status_t status = astra_streamset_open(uri, &
stream_set_);
239 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
242 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
246 const auto check_status = [
this](
const astra_status_t status) {
247 if (status == ASTRA_STATUS_SUCCESS)
return;
255 astra_reader_destroy(&
reader_);
264 astra_colorstream_t stream;
265 check_status(astra_reader_get_colorstream(
reader_, &stream));
281 astra_imagestream_set_mirroring(stream, **mirrored);
289 check_status(astra_stream_start(stream));
296 astra_infraredstream_t stream;
297 check_status(astra_reader_get_infraredstream(
reader_, &stream));
313 astra_imagestream_set_mirroring(stream, **mirrored);
321 check_status(astra_stream_start(stream));
328 astra_depthstream_t stream;
329 check_status(astra_reader_get_depthstream(
reader_, &stream));
345 astra_imagestream_set_mirroring(stream, **mirrored);
353 astra_depthstream_set_d2c_resolution(stream, **d2c_mode);
361 astra_depthstream_set_registration(stream, **registration);
369 check_status(astra_stream_start(stream));
377 astra_bodystream_t stream;
378 check_status(astra_reader_get_bodystream(
reader_, &stream));
410 check_status(astra_stream_start(stream));
417 astra_colorizedbodystream_t stream;
418 check_status(astra_reader_get_colorizedbodystream(
reader_, &stream));
426 check_status(astra_stream_start(stream));
433 astra_handstream_t stream;
434 check_status(astra_reader_get_handstream(
reader_, &stream));
442 check_status(astra_stream_start(stream));
451 astra_pointstream_t stream;
452 check_status(astra_reader_get_pointstream(
reader_, &stream));
460 check_status(astra_stream_start(stream));
468 const bool should_start = started && !started_prev;
469 const bool should_stop = !started && started_prev;
473 const astra_status_t status = astra_stream_start(stream);
474 if (status != ASTRA_STATUS_SUCCESS)
476 std::cerr <<
"astra_stream_start failed (status: " <<
statusToString(status) <<
")" << std::endl;
478 return status == ASTRA_STATUS_SUCCESS;
483 const astra_status_t status = astra_stream_stop(stream);
484 if (status != ASTRA_STATUS_SUCCESS)
486 std::cerr <<
"astra_stream_stop failed (status: " <<
statusToString(status) <<
")" << std::endl;
488 return status == ASTRA_STATUS_SUCCESS;
497 const astra_status_t status = astra_depthstream_set_registration(stream, registration);
498 if (status != ASTRA_STATUS_SUCCESS)
500 std::cerr <<
"astra_depthstream_set_registration failed (status: " <<
statusToString(status) <<
")" << std::endl;
503 return status == ASTRA_STATUS_SUCCESS;
508 const astra_status_t status = astra_depthstream_set_d2c_resolution(stream, d2c_mode);
509 if (status != ASTRA_STATUS_SUCCESS)
511 std::cerr <<
"astra_depthstream_set_d2c_resolution failed (status: " <<
statusToString(status) <<
")" << std::endl;
514 return status == ASTRA_STATUS_SUCCESS;
520 const astra_status_t status = astra_bodystream_set_skeleton_optimization(body_stream, optimization);
521 if (status != ASTRA_STATUS_SUCCESS)
523 std::cerr <<
"astra_bodystream_set_skeleton_optimization failed (status: " <<
statusToString(status) <<
")" << std::endl;
526 return status == ASTRA_STATUS_SUCCESS;
531 const astra_status_t status = astra_bodystream_set_body_orientation(body_stream, orientation);
532 if (status != ASTRA_STATUS_SUCCESS)
534 std::cerr <<
"astra_bodystream_set_body_orientation failed (status: " <<
statusToString(status) <<
")" << std::endl;
537 return status == ASTRA_STATUS_SUCCESS;
542 const astra_status_t status = astra_bodystream_set_skeleton_profile(body_stream, profile);
543 if (status != ASTRA_STATUS_SUCCESS)
545 std::cerr <<
"astra_bodystream_set_skeleton_profile failed (status: " <<
statusToString(status) <<
")" << std::endl;
548 return status == ASTRA_STATUS_SUCCESS;
553 const astra_status_t status = astra_imagestream_set_mirroring(stream, mirrored);
554 if (status != ASTRA_STATUS_SUCCESS)
556 std::cerr <<
"astra_imagestream_set_mirroring failed (status: " <<
statusToString(status) <<
")" << std::endl;
559 return status == ASTRA_STATUS_SUCCESS;
565 astra_result_token_t token;
566 std::uint32_t count = 0;
567 astra_status_t status = astra_imagestream_request_modes(stream, &token, &count);
568 if (status != ASTRA_STATUS_SUCCESS)
570 std::cerr <<
"astra_imagestream_request_modes failed (status: " <<
statusToString(status) <<
")" << std::endl;
574 astra_imagestream_mode_t *
const modes =
new astra_imagestream_mode_t[count];
575 status = astra_imagestream_get_modes_result(stream, token, modes, count);
576 if (status != ASTRA_STATUS_SUCCESS)
578 std::cerr <<
"astra_imagestream_get_modes_result failed (status: " <<
statusToString(status) <<
")" << std::endl;
583 const astra_imagestream_mode_t *match =
nullptr;
584 for (std::uint32_t i = 0; i < count; ++i)
587 (!mode.
fps || modes[i].fps == *mode.
fps) &&
588 (!mode.
width || modes[i].width == *mode.
width) &&
601 std::cerr <<
"Failed to find compatible mode for stream" << std::endl;
606 astra_imagestream_set_mode(stream, match);
614 orbbec_camera_params ret;
615 const astra_status_t status = astra_get_orbbec_camera_params(
stream_set_, &ret);
616 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
627 const astra_status_t status = astra_depthstream_get_serialnumber(*
depth_stream_, buffer,
sizeof(buffer));
628 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
630 return std::string(buffer, buffer +
sizeof(buffer));
637 std::uint32_t chip_id;
638 const astra_status_t status = astra_depthstream_get_chip_id(*
depth_stream_, &chip_id);
639 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
648 astra_usb_info_t ret;
649 const astra_status_t status = astra_colorstream_get_usb_info(*
color_stream_, &ret);
650 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
658 astra_usb_info_t ret;
659 const astra_status_t status = astra_depthstream_get_usb_info(*
depth_stream_, &ret);
660 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
668 astra_usb_info_t ret;
669 const astra_status_t status = astra_infraredstream_get_usb_info(*
ir_stream_, &ret);
670 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
694 astra_result_token_t token;
695 std::uint32_t count = 0;
696 astra_status_t status = astra_imagestream_request_modes(stream, &token, &count);
697 if (status != ASTRA_STATUS_SUCCESS)
throw Exception(status);
699 astra_imagestream_mode_t *
const modes =
new astra_imagestream_mode_t[count];
700 status = astra_imagestream_get_modes_result(stream, token, modes, count);
701 if (status != ASTRA_STATUS_SUCCESS)
707 std::vector<ImageStreamMode> ret;
709 for (std::uint32_t i = 0; i < count; ++i)
711 const auto &mode = modes[i];
714 .height = mode.height,
715 .pixel_format = mode.pixelFormat,
728 std::ostream &
operator <<(std::ostream &o,
const boost::optional<T> &value)
732 return o << value.get();
735 return o <<
"Not Present / Default";
739 std::string to_string(
const T &t)
741 std::ostringstream o;
746 std::string indent(
const std::string &str,
const std::size_t spaces)
748 std::ostringstream o;
749 for (std::size_t i = 0; i < spaces; ++i) o <<
" ";
750 const std::string indention = o.str();
752 std::ostringstream ret;
753 std::string::size_type last = 0;
754 for (std::string::size_type i = 0; i != std::string::npos; i = str.find(
"\n", i + 1))
756 ret << indention << str.substr(last, i - last);
796 o <<
"Device::Configuration {" << std::endl
797 <<
" URI: " << value.
uri << std::endl
798 <<
" Color Stream: " << std::endl;