10 #include <json/json.h>
12 #include <k4arecord/playback.h>
13 #include <k4arecord/record.h>
14 #include <turbojpeg.h>
30 std::string MKVReader::GetTagInMetadata(
const std::string &tag_name) {
32 size_t res_size = 256;
35 handle_, tag_name.c_str(), res_buffer, &res_size);
36 if (K4A_BUFFER_RESULT_SUCCEEDED ==
result) {
38 }
else if (K4A_BUFFER_RESULT_TOO_SMALL ==
result) {
50 if (K4A_RESULT_SUCCEEDED !=
64 Json::Value MKVReader::GetMetadataJson() {
65 static const std::unordered_map<std::string, std::pair<int, int>>
79 k4a_calibration_t calibration;
80 if (K4A_RESULT_SUCCEEDED !=
86 auto color_camera_calibration = calibration.color_camera_calibration;
87 auto param = color_camera_calibration.intrinsics.parameters.param;
88 pinhole_camera.
SetIntrinsics(color_camera_calibration.resolution_width,
89 color_camera_calibration.resolution_height,
90 param.fx, param.fy, param.cx, param.cy);
93 value[
"serial_number"] = GetTagInMetadata(
"K4A_DEVICE_SERIAL_NUMBER");
94 value[
"depth_mode"] = GetTagInMetadata(
"K4A_DEPTH_MODE");
95 value[
"color_mode"] = GetTagInMetadata(
"K4A_COLOR_MODE");
97 value[
"stream_length_usec"] =
99 auto color_mode = value[
"color_mode"].asString();
100 size_t pos = color_mode.find(
'_');
101 if (pos == std::string::npos) {
104 std::string resolution =
105 std::string(color_mode.begin() + pos + 1, color_mode.end());
106 if (resolution_to_width_height.count(resolution) == 0) {
110 auto width_height = resolution_to_width_height.at(resolution);
111 value[
"width"] = width_height.first;
112 value[
"height"] = width_height.second;
132 if (K4A_RESULT_SUCCEEDED !=
134 K4A_PLAYBACK_SEEK_BEGIN)) {
146 k4a_capture_t k4a_capture;
147 k4a_stream_result_t res =
149 if (K4A_STREAM_RESULT_EOF == res) {
153 }
else if (K4A_STREAM_RESULT_FAILED == res) {
Contains the pinhole camera intrinsic parameters.
bool ConvertToJsonValue(Json::Value &value) const override
void SetIntrinsics(int width, int height, double fx, double fy, double cx, double cy)
Set camera intrinsic parameters.
static std::shared_ptr< geometry::RGBDImage > DecompressCapture(_k4a_capture_t *capture, _k4a_transformation_t *transformation)
std::shared_ptr< geometry::RGBDImage > NextFrame()
Get next frame from the mkv playback and returns the RGBD object.
bool IsOpened()
Check If the mkv file is opened.
bool Open(const std::string &filename)
bool SeekTimestamp(size_t timestamp)
Seek to the timestamp (in us).
void Close()
Close the opened mkv playback.
MKVReader()
Default Constructor.
CLOUDVIEWER_HOST_DEVICE Pair< First, Second > make_pair(const First &_first, const Second &_second)
void k4a_capture_release(k4a_capture_t capture_handle)
k4a_result_t k4a_playback_get_calibration(k4a_playback_t playback_handle, k4a_calibration_t *calibration)
k4a_buffer_result_t k4a_playback_get_tag(k4a_playback_t playback_handle, const char *name, char *value, size_t *value_size)
void k4a_playback_close(k4a_playback_t playback_handle)
k4a_transformation_t k4a_transformation_create(const k4a_calibration_t *calibration)
k4a_result_t k4a_playback_open(const char *path, k4a_playback_t *playback_handle)
uint64_t k4a_playback_get_last_timestamp_usec(k4a_playback_t playback_handle)
k4a_result_t k4a_playback_seek_timestamp(k4a_playback_t playback_handle, int64_t offset_usec, k4a_playback_seek_origin_t origin)
k4a_stream_result_t k4a_playback_get_next_capture(k4a_playback_t playback_handle, k4a_capture_t *capture_handle)
Generic file read and write utility for python interface.