diff --git a/include/librealsense2/h/rs_device.h b/include/librealsense2/h/rs_device.h index 7fb559f670..fc3ca8996e 100644 --- a/include/librealsense2/h/rs_device.h +++ b/include/librealsense2/h/rs_device.h @@ -598,40 +598,21 @@ float rs2_calculate_target_z_cpp(rs2_device* device, rs2_frame_queue* queue1, rs float rs2_calculate_target_z(rs2_device* device, rs2_frame_queue* queue1, rs2_frame_queue* queue2, rs2_frame_queue* queue3, float target_width, float target_height, rs2_update_progress_callback_ptr progress_callback, void* client_data, rs2_error** error); - /** * rs2_get_calibration_config -* \param[in] device The device -* \param[out] calib_config Calibration Configuration struct to be filled -* \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored -*/ -void rs2_get_calibration_config(rs2_device* device, rs2_calibration_config* calib_config, rs2_error** error); - -/** -* rs2_set_calibration_config -* \param[in] device The device -* \param[in] calib_config Calibration Configuration struct to set -* \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored -*/ -void rs2_set_calibration_config(rs2_device* device, rs2_calibration_config const* calib_config, rs2_error** error); - -/** -* rs2_json_string_to_calibration_config -* \param[in] device The device -* \param[in] json_str JSON string to convert -* \param[out] calib_config Calibration config struct result +* \param[in] device Device * \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored +* \return JSON string representing the calibration config as rs2_raw_data_buffer */ -void rs2_json_string_to_calibration_config(rs2_device* device, const char* json_str, rs2_calibration_config* calib_config, rs2_error** error); +const rs2_raw_data_buffer* rs2_get_calibration_config(rs2_device* device, rs2_error** error); /** -* rs2_calibration_config_to_json_string -* \param[in] device The device -* \param[in] calib_config Calibration config to convert -* \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored -* \return JSON string representing the calibration config as rs2_raw_data_buffer +* rs2_set_calibration_config +* \param[in] sensor Safety sensor +* \param[in] calibration_config_json_str Calibration config as JSON string +* \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored */ -const rs2_raw_data_buffer* rs2_calibration_config_to_json_string(rs2_device* device, rs2_calibration_config const* calib_config, rs2_error** error); +void rs2_set_calibration_config(rs2_device* device, const char* calibration_config_json_str, rs2_error** error); #ifdef __cplusplus } diff --git a/include/librealsense2/hpp/rs_device.hpp b/include/librealsense2/hpp/rs_device.hpp index b43218ce16..4068dc5a53 100644 --- a/include/librealsense2/hpp/rs_device.hpp +++ b/include/librealsense2/hpp/rs_device.hpp @@ -695,48 +695,6 @@ namespace rs2 error::handle(e); } - /** - * json_string_to_calibration_config - * \param[in] json_str JSON string to convert to calibration config struct - * \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored - * \return calib_config Calibration Configuration struct to be filled - */ - rs2_calibration_config json_string_to_calibration_config(const std::string& json_str) const - { - rs2_error* e = nullptr; - rs2_calibration_config calib_config; - rs2_json_string_to_calibration_config(_dev.get(), json_str.c_str(), &calib_config, &e); - error::handle(e); - return calib_config; - } - - /** - * calibration_config_to_json_string - * \param[in] calib_config Calibration config struct to convert to JSON string - * \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored - * \return calib_config Calibration Configuration struct to be filled - */ - std::string calibration_config_to_json_string(const rs2_calibration_config& calib_config) const - { - std::vector result; - - rs2_error* e = nullptr; - auto buffer = rs2_calibration_config_to_json_string(_dev.get(), &calib_config, &e); - - std::shared_ptr list(buffer, rs2_delete_raw_data); - error::handle(e); - - auto size = rs2_get_raw_data_size(list.get(), &e); - error::handle(e); - - auto start = rs2_get_raw_data(list.get(), &e); - error::handle(e); - - result.insert(result.begin(), start, start + size); - - return std::string(result.begin(), result.end()); - } - /** * Run target-based focal length calibration for D400 Stereo Cameras * \param[in] left_queue: container for left IR frames with resoluton of 1280x720 and the target in the center of 320x240 pixels ROI. @@ -910,30 +868,31 @@ namespace rs2 return result; } - /** - * get_calibration_config - * \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored - * \return calib_config Calibration Configuration struct to be filled - */ - rs2_calibration_config get_calibration_config() const + std::string get_calibration_config() const { + std::vector result; + rs2_error* e = nullptr; - rs2_calibration_config calib_config; - rs2_get_calibration_config(_dev.get(), &calib_config, &e); + auto buffer = rs2_get_calibration_config(_dev.get(), &e); + + std::shared_ptr list(buffer, rs2_delete_raw_data); error::handle(e); - return calib_config; + + auto size = rs2_get_raw_data_size(list.get(), &e); + error::handle(e); + + auto start = rs2_get_raw_data(list.get(), &e); + error::handle(e); + + result.insert(result.begin(), start, start + size); + + return std::string(result.begin(), result.end()); } - - /** - * set_calibration_config - * \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored - * \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored - * \return calib_config Calibration Configuration struct to be filled - */ - void set_calibration_config(const rs2_calibration_config& calib_config) + + void set_calibration_config(const std::string& calibration_config_json_str) const { rs2_error* e = nullptr; - rs2_set_calibration_config(_dev.get(), &calib_config, &e); + rs2_set_calibration_config(_dev.get(), calibration_config_json_str.c_str(), &e); error::handle(e); } }; diff --git a/src/auto-calibrated-device.h b/src/auto-calibrated-device.h index 21e2465344..50b2ff6dc6 100644 --- a/src/auto-calibrated-device.h +++ b/src/auto-calibrated-device.h @@ -25,10 +25,8 @@ namespace librealsense float* const health, int health_size, rs2_update_progress_callback_sptr progress_callback) = 0; virtual float calculate_target_z(rs2_frame_queue* queue1, rs2_frame_queue* queue2, rs2_frame_queue* queue3, float target_w, float target_h, rs2_update_progress_callback_sptr progress_callback) = 0; - virtual rs2_calibration_config get_calibration_config() const = 0; - virtual void set_calibration_config(const rs2_calibration_config& calib_config) = 0; - virtual std::string calibration_config_to_json_string(const rs2_calibration_config& calib_config) const = 0; - virtual rs2_calibration_config json_string_to_calibration_config(const std::string& json_str) const = 0; + virtual std::string get_calibration_config() const = 0; + virtual void set_calibration_config(const std::string& calibration_config_json_str) const = 0; }; MAP_EXTENSION(RS2_EXTENSION_AUTO_CALIBRATED_DEVICE, auto_calibrated_interface); } diff --git a/src/ds/d400/d400-auto-calibration.cpp b/src/ds/d400/d400-auto-calibration.cpp index 79a574b0d4..780f26a582 100644 --- a/src/ds/d400/d400-auto-calibration.cpp +++ b/src/ds/d400/d400-auto-calibration.cpp @@ -2567,22 +2567,12 @@ namespace librealsense throw std::runtime_error("Failed to extract target dimension info!"); } - rs2_calibration_config auto_calibrated::get_calibration_config() const + std::string auto_calibrated::get_calibration_config() const { throw std::runtime_error(rsutils::string::from() << "Calibration Config not applicable for this device"); } - void auto_calibrated::set_calibration_config(const rs2_calibration_config& calib_config) - { - throw std::runtime_error(rsutils::string::from() << "Calibration Config not applicable for this device"); - } - - std::string auto_calibrated::calibration_config_to_json_string(const rs2_calibration_config& calib_config) const - { - throw std::runtime_error(rsutils::string::from() << "Calibration Config not applicable for this device"); - } - - rs2_calibration_config auto_calibrated::json_string_to_calibration_config(const std::string& json_str) const + void auto_calibrated::set_calibration_config(const std::string& calibration_config_json_str) const { throw std::runtime_error(rsutils::string::from() << "Calibration Config not applicable for this device"); } diff --git a/src/ds/d400/d400-auto-calibration.h b/src/ds/d400/d400-auto-calibration.h index e7cb9c035b..476b5163fd 100644 --- a/src/ds/d400/d400-auto-calibration.h +++ b/src/ds/d400/d400-auto-calibration.h @@ -60,11 +60,8 @@ namespace librealsense float* const health, int health_size, rs2_update_progress_callback_sptr progress_callback) override; float calculate_target_z(rs2_frame_queue* queue1, rs2_frame_queue* queue2, rs2_frame_queue* queue3, float target_width, float target_height, rs2_update_progress_callback_sptr progress_callback) override; - rs2_calibration_config get_calibration_config() const override; - void set_calibration_config(const rs2_calibration_config& calib_config) override; - std::string calibration_config_to_json_string(const rs2_calibration_config& calib_config) const override; - rs2_calibration_config json_string_to_calibration_config(const std::string& json_str) const override; - + std::string get_calibration_config() const override; + void set_calibration_config(const std::string& calibration_config_json_str) const override; void set_hw_monitor_for_auto_calib(std::shared_ptr hwm); private: diff --git a/src/ds/d500/d500-auto-calibration.cpp b/src/ds/d500/d500-auto-calibration.cpp index 97d7d5e80f..c546d379c4 100644 --- a/src/ds/d500/d500-auto-calibration.cpp +++ b/src/ds/d500/d500-auto-calibration.cpp @@ -6,7 +6,7 @@ #include "d500-private.h" #include #include - +#include "d500-types/calibration-config.h" namespace librealsense { @@ -301,47 +301,51 @@ namespace librealsense throw std::runtime_error(rsutils::string::from() << "Calculate T not applicable for this device"); } - rs2_calibration_config d500_auto_calibrated::get_calibration_config() const + std::string d500_auto_calibrated::get_calibration_config() const { - rs2_calibration_config_with_header* calib_config_with_header; + calibration_config_with_header* result; // prepare command - using namespace ds; - command cmd(GET_HKR_CONFIG_TABLE, - static_cast(d500_calib_location::d500_calib_flash_memory), - static_cast(d500_calibration_table_id::calib_cfg_id), - static_cast(d500_calib_type::d500_calib_dynamic)); - auto res = _hw_monitor->send(cmd); - - if (res.size() < sizeof(rs2_calibration_config_with_header)) + command cmd(ds::GET_HKR_CONFIG_TABLE, + static_cast(ds::d500_calib_location::d500_calib_flash_memory), + static_cast(ds::d500_calibration_table_id::calib_cfg_id), + static_cast(ds::d500_calib_type::d500_calib_dynamic)); + cmd.require_response = true; + + // send command to device and get response (safety_interface_config entry + header) + std::vector< uint8_t > response = _hw_monitor->send(cmd); + if (response.size() < sizeof(calibration_config_with_header)) { - throw io_exception(rsutils::string::from() << "Calibration config reading failed"); + throw io_exception(rsutils::string::from() << "Calibration Config Read Failed"); } - calib_config_with_header = reinterpret_cast(res.data()); - // check CRC before returning result - auto computed_crc32 = rsutils::number::calc_crc32(res.data() + sizeof(rs2_calibration_config_header), sizeof(rs2_calibration_config)); - if (computed_crc32 != calib_config_with_header->header.crc32) + // check CRC before returning result + auto computed_crc32 = rsutils::number::calc_crc32(response.data() + sizeof(table_header), + sizeof(calibration_config)); + result = reinterpret_cast(response.data()); + if (computed_crc32 != result->get_table_header().get_crc32()) { - throw invalid_value_exception(rsutils::string::from() << "Invalid CRC value for calibration config table"); + throw invalid_value_exception(rsutils::string::from() << "Calibration Config Invalid CRC Value"); } - return calib_config_with_header->payload; + rsutils::json j = result->get_calibration_config().to_json(); + return j.dump(); } - void d500_auto_calibrated::set_calibration_config(const rs2_calibration_config& calib_config) + void d500_auto_calibrated::set_calibration_config(const std::string& calibration_config_json_str) const { + rsutils::json json_data = rsutils::json::parse(calibration_config_json_str); + calibration_config calib_config(json_data["calibration_config"]); + // calculate CRC - uint32_t computed_crc32 = rsutils::number::calc_crc32(reinterpret_cast(&calib_config), - sizeof(rs2_calibration_config)); + uint32_t computed_crc32 = rsutils::number::calc_crc32(reinterpret_cast(&calib_config), sizeof(calibration_config)); - // prepare vector of data to be sent (header + sp) - rs2_calibration_config_with_header calib_config_with_header; + // prepare vector of data to be sent (header + calibration_config) uint16_t version = ((uint16_t)0x01 << 8) | 0x01; // major=0x01, minor=0x01 --> ver = major.minor uint32_t calib_version = 0; // ignoring this field, as requested by sw architect - calib_config_with_header.header = { version, static_cast(ds::d500_calibration_table_id::calib_cfg_id), - sizeof(rs2_calibration_config), calib_version, computed_crc32 }; - calib_config_with_header.payload = calib_config; + table_header header(version, static_cast(ds::d500_calibration_table_id::calib_cfg_id), sizeof(calibration_config), + calib_version, computed_crc32); + calibration_config_with_header calib_config_with_header(header, calib_config); auto data_as_ptr = reinterpret_cast(&calib_config_with_header); // prepare command @@ -349,93 +353,13 @@ namespace librealsense static_cast(ds::d500_calib_location::d500_calib_flash_memory), static_cast(ds::d500_calibration_table_id::calib_cfg_id), static_cast(ds::d500_calib_type::d500_calib_dynamic)); - cmd.data.insert(cmd.data.end(), data_as_ptr, data_as_ptr + sizeof(rs2_calibration_config_with_header)); + cmd.data.insert(cmd.data.end(), data_as_ptr, data_as_ptr + sizeof(calibration_config_with_header)); cmd.require_response = false; // send command _hw_monitor->send(cmd); } - std::string d500_auto_calibrated::calibration_config_to_json_string(const rs2_calibration_config& calib_config) const - { - - rsutils::json json_data; - json_data["calibration_config"]["calib_roi_num_of_segments"] = calib_config.calib_roi_num_of_segments; - - for (int roi_index = 0; roi_index < 4; roi_index++) - { - for (int mask_index = 0; mask_index < 4; mask_index++) - { - json_data["calibration_config"]["roi"][roi_index][mask_index][0] = calib_config.roi[roi_index].mask_pixel[mask_index][0]; - json_data["calibration_config"]["roi"][roi_index][mask_index][1] = calib_config.roi[roi_index].mask_pixel[mask_index][1]; - } - } - - auto& rotation = json_data["calibration_config"]["camera_position"]["rotation"]; - rotation[0][0] = calib_config.camera_position.rotation.x.x; - rotation[0][1] = calib_config.camera_position.rotation.x.y; - rotation[0][2] = calib_config.camera_position.rotation.x.z; - rotation[1][0] = calib_config.camera_position.rotation.y.x; - rotation[1][1] = calib_config.camera_position.rotation.y.y; - rotation[1][2] = calib_config.camera_position.rotation.y.z; - rotation[2][0] = calib_config.camera_position.rotation.z.x; - rotation[2][1] = calib_config.camera_position.rotation.z.y; - rotation[2][2] = calib_config.camera_position.rotation.z.z; - - auto& translation = json_data["calibration_config"]["camera_position"]["translation"]; - translation[0] = calib_config.camera_position.translation.x; - translation[1] = calib_config.camera_position.translation.y; - translation[2] = calib_config.camera_position.translation.z; - - // fill crypto signature array - size_t number_of_elements = sizeof(calib_config.crypto_signature) / sizeof(calib_config.crypto_signature[0]); - std::vector crypto_signature_byte_array(number_of_elements); - memcpy(crypto_signature_byte_array.data(), calib_config.crypto_signature, sizeof(calib_config.crypto_signature)); - json_data["calibration_config"]["crypto_signature"] = crypto_signature_byte_array; - - return json_data.dump(); - - } - - rs2_calibration_config d500_auto_calibrated::json_string_to_calibration_config(const std::string& json_str) const - { - rsutils::json json_data = rsutils::json::parse(json_str); - rs2_calibration_config calib_config; - - calib_config.calib_roi_num_of_segments = json_data["calibration_config"]["calib_roi_num_of_segments"]; - - for (int roi_index = 0; roi_index < 4; roi_index++) - { - for (int mask_index = 0; mask_index < 4; mask_index++) - { - calib_config.roi[roi_index].mask_pixel[mask_index][0] = json_data["calibration_config"]["roi"][roi_index][mask_index][0]; - calib_config.roi[roi_index].mask_pixel[mask_index][1] = json_data["calibration_config"]["roi"][roi_index][mask_index][1]; - } - } - - auto& rotation = json_data["calibration_config"]["camera_position"]["rotation"]; - calib_config.camera_position.rotation.x.x = rotation[0][0]; - calib_config.camera_position.rotation.x.y = rotation[0][1]; - calib_config.camera_position.rotation.x.z = rotation[0][2]; - calib_config.camera_position.rotation.y.x = rotation[1][0]; - calib_config.camera_position.rotation.y.y = rotation[1][1]; - calib_config.camera_position.rotation.y.z = rotation[1][2]; - calib_config.camera_position.rotation.z.x = rotation[2][0]; - calib_config.camera_position.rotation.z.y = rotation[2][1]; - calib_config.camera_position.rotation.z.z = rotation[2][2]; - - auto& translation = json_data["calibration_config"]["camera_position"]["translation"]; - calib_config.camera_position.translation.x = translation[0]; - calib_config.camera_position.translation.y = translation[1]; - calib_config.camera_position.translation.z = translation[2]; - - // fill crypto signature array - std::vector crypto_signature_vector = json_data["calibration_config"]["crypto_signature"].get>(); - std::memcpy(calib_config.crypto_signature, crypto_signature_vector.data(), crypto_signature_vector.size() * sizeof(uint8_t)); - - return calib_config; - } - void d500_auto_calibrated::set_hw_monitor_for_auto_calib(std::shared_ptr hwm) { _hw_monitor = hwm; diff --git a/src/ds/d500/d500-auto-calibration.h b/src/ds/d500/d500-auto-calibration.h index 2233068ad1..8039c7e0e0 100644 --- a/src/ds/d500/d500-auto-calibration.h +++ b/src/ds/d500/d500-auto-calibration.h @@ -26,10 +26,8 @@ namespace librealsense float* const health, int health_size, rs2_update_progress_callback_sptr progress_callback) override; float calculate_target_z(rs2_frame_queue* queue1, rs2_frame_queue* queue2, rs2_frame_queue* queue3, float target_width, float target_height, rs2_update_progress_callback_sptr progress_callback) override; - rs2_calibration_config get_calibration_config() const override; - void set_calibration_config(const rs2_calibration_config& calib_config) override; - std::string calibration_config_to_json_string(const rs2_calibration_config& calib_config) const override; - rs2_calibration_config json_string_to_calibration_config(const std::string& json_str) const override; + std::string get_calibration_config() const override; + void set_calibration_config(const std::string& calibration_config_json_str) const override; void set_hw_monitor_for_auto_calib(std::shared_ptr hwm); diff --git a/src/ds/d500/d500-types/calibration-config.h b/src/ds/d500/d500-types/calibration-config.h new file mode 100644 index 0000000000..8ef24348b2 --- /dev/null +++ b/src/ds/d500/d500-types/calibration-config.h @@ -0,0 +1,372 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2024 Intel Corporation. All Rights Reserved. + +#pragma once + +#include "common.h" + +namespace librealsense +{ + +#pragma pack(push, 1) + + /* + vertex class + handles JSON representing 2D Vertex (x,y) + JSON schema: [ float, float ] + */ + class vertex + { + public: + vertex() : m_x(0), m_y(0) {} + + vertex(const json &j) + { + validate_json(j); + m_x = j[0].get(); + m_y = j[1].get(); + } + + json to_json() const + { + return json::array({m_x, m_y}); + } + + private: + void validate_json(const json &j) const + { + if (!j.is_array() || j.size() != 2) + { + throw std::invalid_argument("Invalid Vertex format: each vertex should be an array of size=2"); + } + if (!j[0].is_number_unsigned() || !j[1].is_number_unsigned()) + { + throw std::invalid_argument("Invalid Vertex type: Each vertex must include only unsigned integers"); + } + } + + private: + uint16_t m_x; + uint16_t m_y; + }; + + /* + roi class + handles JSON of 4 vertices representing region of interest + JSON schema: + { + "vertex_0": [0, 0], + "vertex_1": [0, 0], + "vertex_2": [0, 0], + "vertex_3": [0, 0] + } + */ + class roi + { + public: + roi() = default; + + roi(const json &j) + { + validate_json(j); + m_vertex_0 = vertex(j.at("vertex_0")); + m_vertex_1 = vertex(j.at("vertex_1")); + m_vertex_2 = vertex(j.at("vertex_2")); + m_vertex_3 = vertex(j.at("vertex_3")); + } + + json to_json() const + { + return { + {"vertex_0", m_vertex_0.to_json()}, + {"vertex_1", m_vertex_1.to_json()}, + {"vertex_2", m_vertex_2.to_json()}, + {"vertex_3", m_vertex_3.to_json()}}; + } + + private: + void validate_json(const json &j) const + { + if (!j.is_object()) + { + throw std::invalid_argument("Invalid ROI format"); + } + for (const auto &field : {"vertex_0", "vertex_1", "vertex_2", "vertex_3"}) + { + if (!j.contains(field)) + { + throw std::invalid_argument(std::string("Invalid ROI format: missing field: ") + field); + } + } + } + + private: + vertex m_vertex_0; + vertex m_vertex_1; + vertex m_vertex_2; + vertex m_vertex_3; + }; + + /* + camera_position class + handles JSON of representing the camera positon: rotation row major 3x3 matrix and translation vector + all values are floats. + JSON schema: + { + "rotation": + [ + [a, b, c], + [d, e, f], + [g, h, i] + ], + "translation": {x, y, z} + } + */ + class camera_position + { + + public: + camera_position() = default; + + camera_position(const json &j) + { + validate_json(j); + for (size_t i = 0; i < 3; ++i) + { + for (size_t k = 0; k < 3; ++k) + { + m_rotation[i][k] = j.at("rotation")[i][k].get(); + } + } + for (size_t i = 0; i < 3; ++i) + { + m_translation[i] = j.at("translation")[i].get(); + } + } + + json to_json() const + { + json j; + j["rotation"] = json::array(); + for (size_t i = 0; i < 3; ++i) + { + j["rotation"].push_back(json::array()); + for (size_t k = 0; k < 3; ++k) + { + j["rotation"][i].push_back(m_rotation[i][k]); + } + } + j["translation"] = m_translation; + return j; + } + + private: + void validate_json(const json &j) const + { + if (!j.is_object() || j.size() != 2 || !j.contains("rotation") || !j.contains("translation")) + { + throw std::invalid_argument("Invalid camera_position format: camera_position must include rotation and translation fields"); + } + if (!j.at("rotation").is_array() || j.at("rotation").size() != 3) + { + throw std::invalid_argument("Invalid rotation format: rotation must be a 3x3 matrix"); + } + for (size_t i = 0; i < 3; ++i) + { + if (!j.at("rotation")[i].is_array() || j.at("rotation")[i].size() != 3) + { + throw std::invalid_argument("Invalid rotation row format: rotation must be a 3x3 matrix"); + } + for (size_t k = 0; k < 3; ++k) + { + if (!j.at("rotation")[i][k].is_number_float() && !j.at("rotation")[i][k].is_number_integer()) + { + throw std::invalid_argument("Invalid rotation type: all rotation values must be floats."); + } + } + } + if (!j.at("translation").is_array() || j.at("translation").size() != 3) + { + throw std::invalid_argument("Invalid translation format: translation vector should be an array of size=3"); + } + for (size_t i = 0; i < 3; ++i) + { + if (!j.at("translation")[i].is_number_float()) + { + throw std::invalid_argument("Invalid translation type: translation vector values should be floats"); + } + } + } + + private: + std::array, 3> m_rotation; // row major order + std::array m_translation; + }; + + /* + calibration_config class + Handles JSONS represnting calibration config table + JSON schema: + { + "roi_num_of_segments": 0, + "roi_0": + { + "vertex_0": [0, 0], + "vertex_1": [0, 0], + "vertex_2": [0, 0], + "vertex_3": [0, 0] + }, + "roi_1": + { + "vertex_0": [0, 0], + "vertex_1": [0, 0], + "vertex_2": [0, 0], + "vertex_3": [0, 0] + }, + "roi_2": + { + "vertex_0": [0, 0], + "vertex_1": [0, 0], + "vertex_2": [0, 0], + "vertex_3": [0, 0] + }, + "roi_3": + { + "vertex_0": [0, 0], + "vertex_1": [0, 0], + "vertex_2": [0, 0], + "vertex_3": [0, 0] + }, + "camera_position": + { + "rotation": + [ + [ 0.0, 0.0, 1.0], + [-1.0, 0.0, 0.0], + [ 0.0, -1.0, 0.0] + ], + "translation": [0.0, 0.0, 0.4] + }, + "crypto_signature": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + } + */ + class calibration_config + { + public: + calibration_config(const json &j) + { + validate_json(j); + + m_roi_num_of_segments = j.at("roi_num_of_segments").get(); + + for (size_t i = 0; i < 4; ++i) + { + std::string roi_field = "roi_" + std::to_string(i); + m_rois[i] = roi(j.at(roi_field)); + } + + m_camera_position = camera_position(j.at("camera_position")); + + for (size_t i = 0; i < 32; ++i) + { + m_crypto_signature[i] = j.at("crypto_signature")[i].get(); + } + } + + json to_json() const + { + json j; + auto &calib_config = j["calibration_config"]; + calib_config["roi_num_of_segments"] = m_roi_num_of_segments; + for (size_t i = 0; i < 4; ++i) + { + std::string roi_field = "roi_" + std::to_string(i); + calib_config[roi_field] = m_rois[i].to_json(); + } + calib_config["camera_position"] = m_camera_position.to_json(); + calib_config["crypto_signature"] = m_crypto_signature; + return j; + } + + private: + void validate_json(const json &j) const + { + if (!j.is_object() || j.size() != 7) + { + throw std::invalid_argument( + "Invalid calibration_config format: calibration_config must include 'roi_num_of_segments', " + "'roi_0', 'roi_1', 'roi_2', 'roi_3', 'camera_position', and 'crypto_signature'"); + } + if (!j.at("roi_num_of_segments").is_number_unsigned()) + { + throw std::invalid_argument("Invalid roi_num_of_segments type: roi_num_of_segments must be unsigned integer"); + } + for (size_t i = 0; i < 4; ++i) + { + std::string roi_field = "roi_" + std::to_string(i); + if (!j.at(roi_field).is_object()) + { + throw std::invalid_argument("Invalid " + roi_field + " format"); + } + } + if (!j.at("camera_position").is_object()) + { + throw std::invalid_argument("Invalid camera_position format"); + } + if (!j.at("crypto_signature").is_array() || j.at("crypto_signature").size() != 32) + { + throw std::invalid_argument("Invalid crypto_signature format: crypto_signature must be an array of size=32"); + } + for (size_t i = 0; i < 32; ++i) + { + if (!j.at("crypto_signature")[i].is_number_unsigned()) + { + throw std::invalid_argument("Invalid crypto_signature type: all elements in crypto_signature array must be unsigned integers"); + } + } + } + + private: + uint8_t m_roi_num_of_segments; // Calibration ROI number of segments + std::array m_rois; // Calibration 4 ROIs + std::array m_reserved1 = {0}; + + camera_position m_camera_position; // Camera extrinsics: rotation 3x3 matrix (row major) + translation vecotr + std::array m_reserved2 = {0}; + + std::array m_crypto_signature; // SHA2 or similar + std::array m_reserved3 = {0}; + }; + + /*** + * calibration_config_with_header class + * Consists of calibration config table and a table header + * According to flash 0.92: + * Version major.minor: 0x01 0x01 + * table type ctCalibCFG(0xC0DD) + * table size 496 + */ + class calibration_config_with_header + { + public: + calibration_config_with_header(table_header header, const calibration_config &calib_config) : m_header(header), m_calib_config(calib_config) + { + } + + calibration_config get_calibration_config() const + { + return m_calib_config; + } + + table_header get_table_header() const + { + return m_header; + } + + private: + table_header m_header; + calibration_config m_calib_config; + }; + +#pragma pack(pop) +} diff --git a/src/ds/d500/d500-types/common.h b/src/ds/d500/d500-types/common.h new file mode 100644 index 0000000000..534b42e55a --- /dev/null +++ b/src/ds/d500/d500-types/common.h @@ -0,0 +1,45 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2024 Intel Corporation. All Rights Reserved. + +#pragma once + +#include +#include +#include +#include + +namespace librealsense +{ + using rsutils::json; + +#pragma pack(push, 1) + + class table_header + { + public: + table_header(uint16_t version, uint16_t table_type, uint32_t table_size, uint32_t calib_version, uint32_t crc32) : m_version(version), m_table_type(table_type), m_table_size(table_size), m_calib_version(calib_version), m_crc32(crc32) + { + } + + uint32_t get_crc32() const + { + return m_crc32; + } + + private: + uint16_t m_version; // major.minor. Big-endian + uint16_t m_table_type; // type + uint32_t m_table_size; // full size including: header footer + uint32_t m_calib_version; // major.minor.index + uint32_t m_crc32; // crc of all the data in table excluding this header/CRC + }; + +#pragma pack(pop) + + // helper function + template + std::vector native_arr_to_std_vector(const T (&arr)[N]) + { + return std::vector(std::begin(arr), std::end(arr)); + } +} \ No newline at end of file diff --git a/src/realsense.def b/src/realsense.def index 14de1fb873..06f4507611 100644 --- a/src/realsense.def +++ b/src/realsense.def @@ -438,5 +438,3 @@ EXPORTS rs2_project_color_pixel_to_depth_pixel rs2_get_calibration_config rs2_set_calibration_config - rs2_calibration_config_to_json_string - rs2_json_string_to_calibration_config diff --git a/src/rs.cpp b/src/rs.cpp index aa9e6e490a..dfb43569ad 100644 --- a/src/rs.cpp +++ b/src/rs.cpp @@ -4389,50 +4389,27 @@ float rs2_calculate_target_z(rs2_device* device, rs2_frame_queue* queue1, rs2_fr } } HANDLE_EXCEPTIONS_AND_RETURN(-1.f, device, queue1, queue2, queue3, target_width, target_height) -void rs2_get_calibration_config(rs2_device* device, rs2_calibration_config* calib_config, rs2_error** error) BEGIN_API_CALL -{ - VALIDATE_NOT_NULL(device); - VALIDATE_NOT_NULL(calib_config); - - auto auto_calib = VALIDATE_INTERFACE(device->device, librealsense::auto_calibrated_interface); - *calib_config = auto_calib->get_calibration_config(); -} -HANDLE_EXCEPTIONS_AND_RETURN(, device, calib_config) -void rs2_set_calibration_config(rs2_device* device, rs2_calibration_config const* calib_config, rs2_error** error) BEGIN_API_CALL -{ - VALIDATE_NOT_NULL(device); - VALIDATE_NOT_NULL(calib_config); - - auto auto_calib = VALIDATE_INTERFACE(device->device, librealsense::auto_calibrated_interface); - auto_calib->set_calibration_config(*calib_config); -} -HANDLE_EXCEPTIONS_AND_RETURN(, device, calib_config) - -void rs2_json_string_to_calibration_config( +const rs2_raw_data_buffer* rs2_get_calibration_config( rs2_device* device, - const char* json_str, - rs2_calibration_config* calib_config, rs2_error** error) BEGIN_API_CALL { VALIDATE_NOT_NULL(device); - VALIDATE_NOT_NULL(calib_config); auto auto_calib = VALIDATE_INTERFACE(device->device, librealsense::auto_calibrated_interface); - *calib_config = auto_calib->json_string_to_calibration_config(json_str); + auto ret_str = auto_calib->get_calibration_config(); + std::vector vec(ret_str.begin(), ret_str.end()); + return new rs2_raw_data_buffer{ std::move(vec) }; } -HANDLE_EXCEPTIONS_AND_RETURN(, device, calib_config) +HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device) -const rs2_raw_data_buffer* rs2_calibration_config_to_json_string( +void rs2_set_calibration_config( rs2_device* device, - rs2_calibration_config const* calib_config, + const char* calibration_config_json_str, rs2_error** error) BEGIN_API_CALL { VALIDATE_NOT_NULL(device); - VALIDATE_NOT_NULL(calib_config); + VALIDATE_NOT_NULL(calibration_config_json_str); auto auto_calib = VALIDATE_INTERFACE(device->device, librealsense::auto_calibrated_interface); - auto ret_str = auto_calib->calibration_config_to_json_string(*calib_config); - std::vector vec(ret_str.begin(), ret_str.end()); - return new rs2_raw_data_buffer{ std::move(vec) }; + auto_calib->set_calibration_config(calibration_config_json_str); } -HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device, calib_config) - +HANDLE_EXCEPTIONS_AND_RETURN(, device, calibration_config_json_str) diff --git a/unit-tests/live/d500/test-get-set-calib-config-table-api.py b/unit-tests/live/d500/test-get-set-calib-config-table-api.py new file mode 100644 index 0000000000..e4466eb94a --- /dev/null +++ b/unit-tests/live/d500/test-get-set-calib-config-table-api.py @@ -0,0 +1,242 @@ +# License: Apache 2.0. See LICENSE file in root directory. +# Copyright(c) 2024 Intel Corporation. All Rights Reserved. + +# test:donotrun + +import pyrealsense2 as rs +from rspy import test, log +from rspy import tests_wrapper as tw +import json + +############################################################################################# +# Tests +############################################################################################# + +test.start("Verify auto calibrated device extension") +ctx = rs.context() +dev = ctx.query_devices()[0] +ac_dev = dev.as_auto_calibrated_device() + +test.finish() + +############################################################################################# + +tw.start_wrapper(dev) + + +test.start("Writing calibration config, then reading and comparing calibration config JSONs") + +# save current calibration config json in order to restore it at the end +original_calib_config = ac_dev.get_calibration_config() + +# calibration config JSON String to be written +new_calib_config = ''' +{ + "calibration_config": + { + "roi_num_of_segments": 0, + "roi_0": + { + "vertex_0": [ 0, 0 ], + "vertex_1": [ 0, 0 ], + "vertex_2": [ 0, 0 ], + "vertex_3": [ 0, 0 ] + }, + "roi_1": + { + "vertex_0": [ 0, 0 ], + "vertex_1": [ 0, 0 ], + "vertex_2": [ 0, 0 ], + "vertex_3": [ 0, 0 ] + }, + "roi_2": + { + "vertex_0": [ 0, 0 ], + "vertex_1": [ 0, 0 ], + "vertex_2": [ 0, 0 ], + "vertex_3": [ 0, 0 ] + }, + "roi_3": + { + "vertex_0": [ 0, 0 ], + "vertex_1": [ 0, 0 ], + "vertex_2": [ 0, 0 ], + "vertex_3": [ 0, 0 ] + }, + "camera_position": + { + "rotation": + [ + [ 0.0, 0.0, 1.0], + [-1.0, 0.0, 0.0], + [ 0.0, -1.0, 0.0] + ], + "translation": [0.0, 0.0, 1.0] + }, + "crypto_signature": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + } +} +''' + +# write the above calib config table to the device +ac_dev.set_calibration_config(new_calib_config) + +# read the current calib config table from the device +read_result = ac_dev.get_calibration_config() + +# verify the JSON objects are equal (comparing JSON object because +# the JSON string can have different order of inner fields +test.check_equal(json.loads(read_result), json.loads(new_calib_config)) + +test.finish() + +# ############################################################################################# + +test.start("Trying to write bad calib config with a missing field") + +original_json = json.loads(new_calib_config) + +# List of keys in the top-level JSON object +keys = list(original_json["calibration_config"].keys()) + +# Generate JSON dictionaries, each missing a different key +json_variants = [] +for key in keys: + variant = original_json.copy() + del variant["calibration_config"][key] + json_variants.append(variant) + +for i, variant in enumerate(json_variants): + try: + log.d("Testing set calibration config with a missing field:", keys[i]) + # try to write the above calib config table to the device + ac_dev.set_calibration_config(json.dumps(variant)) + log.d("Test failed: Exception was expected while setting calibration config with a missing field:" + keys[i]) + test.fail() + except Exception as e: + test.check_equal(str(e), "Invalid calibration_config format: calibration_config must include 'roi_num_of_segments', 'roi_0', 'roi_1', 'roi_2', 'roi_3', 'camera_position', and 'crypto_signature'") + +test.finish() + +############################################################################################# + +test.start("Trying to write bad calib config with a missing field from camera position") + +original_json = json.loads(new_calib_config) + +keys = list(original_json["calibration_config"]["camera_position"].keys()) + +# Generate JSON dictionaries, each missing a different key from the camera_position section +json_variants = [] +for key in keys: + variant = original_json.copy() + del variant["calibration_config"]["camera_position"][key] + json_variants.append(variant) + +for i, variant in enumerate(json_variants): + try: + log.d("Testing set calibration config with a missing field:", keys[i]) + # try to write the above calib config table to the device + ac_dev.set_calibration_config(json.dumps(variant)) + log.d("Test failed: Exception was expected while setting calibration config with a missing field:" + keys[i]) + test.fail() + except Exception as e: + test.check_equal(str(e), "Invalid camera_position format: camera_position must include rotation and translation fields") + +test.finish() + +############################################################################################ + +test.start("Trying to write bad calib config with a missing roi values, or wrong roi types") + +log.d("Testing set calibration config with a missing element in roi_0") +original_json = json.loads(new_calib_config) +variant = original_json.copy() +del variant["calibration_config"]["roi_0"]["vertex_0"] +try: + # try to write the above calib config table to the device + ac_dev.set_calibration_config(json.dumps(variant)) + log.d("Test failed: Exception was expected while setting calibration config with a missing field in roi_0") + test.fail() +except Exception as e: + test.check_equal(str(e), "Invalid ROI format: missing field: vertex_0") + + +log.d("Testing set calibration config with a missing element in roi_0[vertex_0]") +original_json = json.loads(new_calib_config) +variant = original_json.copy() +del variant["calibration_config"]["roi_0"]["vertex_0"][0] +try: + # try to write the above calib config table to the device + ac_dev.set_calibration_config(json.dumps(variant)) + log.d("Test failed: Exception was expected while setting calibration config with a missing field in roi") + test.fail() +except Exception as e: + test.check_equal(str(e), "Invalid Vertex format: each vertex should be an array of size=2") + + +log.d("Testing set calibration config with an invalid type in roi") +original_json = json.loads(new_calib_config) +variant = original_json.copy() +variant["calibration_config"]["roi_0"]["vertex_0"][0] = 1.2 +try: + # try to write the above calib config table to the device + ac_dev.set_calibration_config(json.dumps(variant)) + log.d("Test failed: Exception was expected while setting calibration config with an invalid type in roi_0[vertex_0]") + test.fail() +except Exception as e: + test.check_equal(str(e), "Invalid Vertex type: Each vertex must include only unsigned integers") + +test.finish() + +############################################################################################ + +test.start("Trying to write bad calib config with a wrong crypto_signature values") + +log.d("Testing set calibration config with a missing element in crypto_signature") +original_json = json.loads(new_calib_config) +variant = original_json.copy() +del variant["calibration_config"]["crypto_signature"][0] +try: + # try to write the above calib config table to the device + ac_dev.set_calibration_config(json.dumps(variant)) + log.d("Test failed: Exception was expected while setting calibration config with a missing element in crypto_signature") + test.fail() +except Exception as e: + test.check_equal(str(e), "Invalid crypto_signature format: crypto_signature must be an array of size=32") + + +log.d("Testing set calibration config with a wrong element type in crypto_signature") +original_json = json.loads(new_calib_config) +variant = original_json.copy() +variant["calibration_config"]["crypto_signature"][0] = 0.5 +try: + # try to write the above calib config table to the device + ac_dev.set_calibration_config(json.dumps(variant)) + log.d("Test failed: Exception was expected while setting calibration config with a wrong element type in crypto_signature") + test.fail() +except Exception as e: + test.check_equal(str(e), "Invalid crypto_signature type: all elements in crypto_signature array must be unsigned integers") + + +test.finish() +############################################################################################ + +test.start("Restore original calibration config table") + +# restore original calibration config table +ac_dev.set_calibration_config(original_calib_config) + +# read the current calib config table from the device +read_result = ac_dev.get_calibration_config() + +# verify the JSON objects are equal (comparing JSON object because +# the JSON string can have different order of inner fields +test.check_equal(json.loads(read_result), json.loads(original_calib_config)) + +test.finish() + +############################################################################################# +tw.stop_wrapper(dev) + +test.print_results_and_exit() diff --git a/unit-tests/live/d500/test-get-set-calib-config-table-json.py b/unit-tests/live/d500/test-get-set-calib-config-table-json.py deleted file mode 100644 index 2b0b308b34..0000000000 --- a/unit-tests/live/d500/test-get-set-calib-config-table-json.py +++ /dev/null @@ -1,74 +0,0 @@ -# License: Apache 2.0. See LICENSE file in root directory. -# Copyright(c) 2024 Intel Corporation. All Rights Reserved. - -# test:donotrun - -import pyrealsense2 as rs -from rspy import test, log -import json - -############################################################################################# -# Tests -############################################################################################# - -test.start("Verify auto calibrated device extension") -ctx = rs.context() -dev = ctx.query_devices()[0] -ac_dev = dev.as_auto_calibrated_device() -test.finish() - -############################################################################################# - -test.start("Writing calibration config, then reading and comparing calibration config JSONs") - -# save current calibration config in order to restore it at the end -previous_result = ac_dev.get_calibration_config() - -# calibration config JSON String to be written -calib_config_json_str = ''' -{ - "calibration_config": - { - "calib_roi_num_of_segments": 0, - "roi": [ [[0,0], [0,0], [0,0], [0,0]], [[0,0], [0,0], [0,0], [0,0]], [[0,0], [0,0], [0,0], [0,0]], [[0,0], [0,0], [0,0], [0,0]] ], - "camera_position": - { - "rotation": - [ - [ 0.0, 0.0, 1.0], - [-1.0, 0.0, 0.0], - [ 0.0, -1.0, 0.0] - ], - "translation": [0.0, 0.0, 0.27] - }, - "crypto_signature": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] - } -} -''' - -# generate calibration config struct from JSON string -new_calib_config = ac_dev.json_string_to_calibration_config(calib_config_json_str) - -# write the above new_calib_config table to the device -ac_dev.set_calibration_config(new_calib_config) - -# read the current calib config table from the device -read_result = ac_dev.get_calibration_config() - -# verify the tables are equal -test.check_equal(read_result, new_calib_config) - -# verify the JSON objects are equal (comparing JSON object because -# the JSON string can have different order of inner fields -read_result_json_str = ac_dev.calibration_config_to_json_string(read_result) -new_calib_config_json_str = ac_dev.calibration_config_to_json_string(new_calib_config) -test.check_equal(json.loads(new_calib_config_json_str), json.loads(read_result_json_str)) - -# restore original calibration config table -ac_dev.set_calibration_config(previous_result) - -test.finish() - -############################################################################################# - -test.print_results_and_exit() diff --git a/unit-tests/live/d500/test-get-set-calib-config-table.py b/unit-tests/live/d500/test-get-set-calib-config-table.py deleted file mode 100644 index 956232fd9f..0000000000 --- a/unit-tests/live/d500/test-get-set-calib-config-table.py +++ /dev/null @@ -1,97 +0,0 @@ -# License: Apache 2.0. See LICENSE file in root directory. -# Copyright(c) 2024 Intel Corporation. All Rights Reserved. - -# test:donotrun - -import pyrealsense2 as rs -from rspy import test, log - - -def generate_camera_position(): - # rotation matrix - rx = rs.float3(0.0, 0.0, 1.0) - ry = rs.float3(-1.0, 0.0, 0.0) - rz = rs.float3(0.0, -1.0, 0.0) - rotation = rs.float3x3(rx, ry, rz) - # translation vector [m] - translation = rs.float3(0.0, 0.0, 0.27) - return rs.extrinsics_table(rotation, translation) - - -def generate_calib_config_table(): - calib_roi = rs.calibration_roi(0, 0, 0, 0, 0, 0, 0, 0) - calib_config = rs.calibration_config() - calib_config.calib_roi_num_of_segments = 0 - calib_config.roi = [calib_roi, calib_roi, calib_roi, calib_roi] - calib_config.reserved1 = [3] * 12 - calib_config.camera_position = generate_camera_position() - calib_config.reserved2 = [0] * 300 - calib_config.crypto_signature = [0] * 32 - calib_config.reserved3 = [0] * 39 - return calib_config - - -def is_equal_roi(first, second): - for i in range(0, 4): - for j in range(0, 4): - for k in range(0, 2): - if first[i].mask_pixel[j][k] != second[i].mask_pixel[j][k]: - return False - return True - - -def is_float3_equal(first, second): - return first.x == second.x and first.y == second.y and first.z == second.z - - -def is_float3x3_equal(first, second): - return (is_float3_equal(first.x, second.x) and is_float3_equal(first.y, second.y) - and is_float3_equal(first.z, second.z)) - - -def is_equal_extrinsics_table(first, second): - if not is_float3x3_equal(first.rotation, second.rotation): - return False - if not is_float3_equal(first.translation, second.translation): - return False - return True - - -def is_equal_calib_configs(first, second): - if first.calib_roi_num_of_segments != second.calib_roi_num_of_segments: - print("calib_roi_num_of_segments is different") - return False - if not is_equal_roi(first.roi, second.roi): - print("roi is different") - return False - if first.reserved1 != second.reserved1: - print("reserved1 is different") - return False - if not is_equal_extrinsics_table(first.camera_position, second.camera_position): - print("camera_position is different") - return False - if first.reserved2 != second.reserved2: - print("calib_roi_num_of_segments is different") - return False - if first.crypto_signature != second.crypto_signature: - print("crypto_signature is different") - return False - if first.reserved3 != second.reserved3: - print("reserved3 is different") - return False - return True - - -dev = test.find_first_device_or_exit() -ac_dev = dev.as_auto_calibrated_device() - -############################################################################################# -with test.closure("Set / Get calib config table"): - generated_calib_config = generate_calib_config_table() - ac_dev.set_calibration_config(generated_calib_config) - current_calib_config = ac_dev.get_calibration_config() - test.check(is_equal_calib_configs(generated_calib_config, current_calib_config)) - -############################################################################################# - -test.print_results_and_exit() diff --git a/wrappers/python/pyrs_device.cpp b/wrappers/python/pyrs_device.cpp index 3505b47f7b..447d2e94a3 100644 --- a/wrappers/python/pyrs_device.cpp +++ b/wrappers/python/pyrs_device.cpp @@ -192,9 +192,7 @@ void init_device(py::module &m) { .def("set_calibration_table", &rs2::auto_calibrated_device::set_calibration_table, "Set current table to dynamic area.") .def("reset_to_factory_calibration", &rs2::auto_calibrated_device::reset_to_factory_calibration, "Reset device to factory calibration.") .def("get_calibration_config", &rs2::auto_calibrated_device::get_calibration_config, "Get Calibration Config Table", py::call_guard()) - .def("set_calibration_config", &rs2::auto_calibrated_device::set_calibration_config, "Set Calibration Config Table", "calibration_config"_a, py::call_guard()) - .def("calibration_config_to_json_string", &rs2::auto_calibrated_device::calibration_config_to_json_string, "Convert calibration config to JSON string", "calibration_config"_a, py::call_guard()) - .def("json_string_to_calibration_config", &rs2::auto_calibrated_device::json_string_to_calibration_config, "Convert JSON string to calibration config", "json_str"_a, py::call_guard()); + .def("set_calibration_config", &rs2::auto_calibrated_device::set_calibration_config, "Set Calibration Config Table", "calibration_config_json_str"_a, py::call_guard()); py::class_ device_calibration( m, "device_calibration" ); device_calibration.def( py::init(), "device"_a ) diff --git a/wrappers/python/pyrs_types.cpp b/wrappers/python/pyrs_types.cpp index ddb9f2654e..e053dae7f2 100644 --- a/wrappers/python/pyrs_types.cpp +++ b/wrappers/python/pyrs_types.cpp @@ -64,44 +64,5 @@ void init_types(py::module &m) { .def_readwrite("max_x", &rs2::region_of_interest::max_x) .def_readwrite("max_y", &rs2::region_of_interest::max_y); - py::class_ calibration_roi(m, "calibration_roi"); // No docstring in C++ - calibration_roi.def(py::init<>()) - .def(py::init()) - .def_property(BIND_RAW_2D_ARRAY_PROPERTY(rs2_calibration_roi, mask_pixel, uint16_t, 4, 2), - "Array of four corners in Deph Frame Coordinate system that define a closed simple quadrangle"); - - py::class_ float3(m, "float3"); // No docstring in C++ - float3.def(py::init<>()) - .def(py::init()) - .def_readwrite("x", &float3_row_major::x, "x") - .def_readwrite("y", &float3_row_major::y, "y") - .def_readwrite("z", &float3_row_major::z, "z"); - - py::class_ float3x3(m, "float3x3"); // No docstring in C++ - float3x3.def(py::init<>()) - .def(py::init()) - .def_readwrite("x", &float3x3_row_major::x, "x") - .def_readwrite("y", &float3x3_row_major::y, "y") - .def_readwrite("z", &float3x3_row_major::z, "z"); - - py::class_ extrinsics_table(m, "extrinsics_table"); // No docstring in C++ - extrinsics_table.def(py::init<>()) - .def(py::init()) - .def_readwrite("rotation", &rs2_extrinsics_row_major::rotation, "Rotation Value") - .def_readwrite("translation", &rs2_extrinsics_row_major::translation, "Translation Value"); - - py::class_ calibration_config(m, "calibration_config"); // No docstring in C++ - calibration_config.def(py::init<>()) - .def_readwrite("calib_roi_num_of_segments", &rs2_calibration_config::calib_roi_num_of_segments, "calib_roi_num_of_segments") - .def_property(BIND_RAW_ARRAY_PROPERTY(rs2_calibration_config, roi, rs2_calibration_roi, 4), "roi") - .def_property(BIND_RAW_ARRAY_PROPERTY(rs2_calibration_config, reserved1, uint8_t, sizeof(rs2_calibration_config::reserved1)), "reserved1") - .def_readwrite("camera_position", &rs2_calibration_config::camera_position, "camera_position") - .def_property(BIND_RAW_ARRAY_PROPERTY(rs2_calibration_config, reserved2, uint8_t, sizeof(rs2_calibration_config::reserved2)), "reserved2") - .def_property(BIND_RAW_ARRAY_PROPERTY(rs2_calibration_config, crypto_signature, uint8_t, sizeof(rs2_calibration_config::crypto_signature)), "crypto_signature") - .def_property(BIND_RAW_ARRAY_PROPERTY(rs2_calibration_config, reserved3, uint8_t, sizeof(rs2_calibration_config::reserved3)), "reserved3") - .def("__eq__", [](const rs2_calibration_config& self, const rs2_calibration_config& other) { - return self == other; - }); - /** end rs_types.hpp **/ }