mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-10 22:49:51 +08:00
Calculate xy LUT only once
This commit is contained in:
@@ -398,6 +398,8 @@ class OBCameraNode {
|
|||||||
std::string ir_info_url_;
|
std::string ir_info_url_;
|
||||||
std::optional<OBCameraParam> camera_param_;
|
std::optional<OBCameraParam> camera_param_;
|
||||||
std::optional<OBCalibrationParam> calibration_param_;
|
std::optional<OBCalibrationParam> calibration_param_;
|
||||||
|
std::optional<OBXYTables> xy_tables_;
|
||||||
|
std::optional<float *> xy_table_data_;
|
||||||
bool enable_d2c_viewer_ = false;
|
bool enable_d2c_viewer_ = false;
|
||||||
std::unique_ptr<D2CViewer> d2c_viewer_ = nullptr;
|
std::unique_ptr<D2CViewer> d2c_viewer_ = nullptr;
|
||||||
std::map<stream_index_pair, std::atomic_bool> save_images_;
|
std::map<stream_index_pair, std::atomic_bool> save_images_;
|
||||||
|
|||||||
@@ -743,31 +743,31 @@ void OBCameraNode::publishDepthPointCloud(const std::shared_ptr<ob::FrameSet> &f
|
|||||||
RCLCPP_ERROR_STREAM(logger_, "camera_param_ is null");
|
RCLCPP_ERROR_STREAM(logger_, "camera_param_ is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!calibration_param_) {
|
|
||||||
calibration_param_ = pipeline_->getCalibrationParam(pipeline_config_);
|
|
||||||
}
|
|
||||||
if (!calibration_param_) {
|
|
||||||
RCLCPP_ERROR_STREAM(logger_, "calibration_param_ is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto depth_frame = frame_set->depthFrame();
|
auto depth_frame = frame_set->depthFrame();
|
||||||
if (!depth_frame) {
|
if (!depth_frame) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto width = depth_frame->width();
|
auto width = depth_frame->width();
|
||||||
auto height = depth_frame->height();
|
auto height = depth_frame->height();
|
||||||
const auto *depth_data = (uint16_t *)depth_frame->data();
|
|
||||||
if (depth_data == nullptr) {
|
if (!xy_tables_.has_value()) {
|
||||||
return;
|
calibration_param_ = pipeline_->getCalibrationParam(pipeline_config_);
|
||||||
|
|
||||||
|
uint32_t tableSize = width * height * 2; // one for x-coordinate and one for y-coordinate LUT
|
||||||
|
xy_table_data_ = new float[tableSize];
|
||||||
|
|
||||||
|
xy_tables_ = OBXYTables();
|
||||||
|
if (!ob::CoordinateTransformHelper::transformationInitXYTables(
|
||||||
|
*calibration_param_, OB_SENSOR_DEPTH, *xy_table_data_,
|
||||||
|
&tableSize, &(*xy_tables_))) {
|
||||||
|
xy_tables_.reset();
|
||||||
|
RCLCPP_ERROR_STREAM(logger_, "Failed to init xy tables");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t tableSize = width * height * 2; // one for x-coordinate and one for y-coordinate LUT
|
const auto *depth_data = (uint16_t *)depth_frame->data();
|
||||||
float * data = new float[tableSize];
|
if (depth_data == nullptr) {
|
||||||
|
|
||||||
OBXYTables xyTables;
|
|
||||||
if (!ob::CoordinateTransformHelper::transformationInitXYTables(
|
|
||||||
*calibration_param_, OB_SENSOR_DEPTH, data,
|
|
||||||
&tableSize, &xyTables)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -777,7 +777,7 @@ void OBCameraNode::publishDepthPointCloud(const std::shared_ptr<ob::FrameSet> &f
|
|||||||
OBPoint * pointPixel = (OBPoint *)pointcloudData;
|
OBPoint * pointPixel = (OBPoint *)pointcloudData;
|
||||||
|
|
||||||
ob::CoordinateTransformHelper::transformationDepthToPointCloud(
|
ob::CoordinateTransformHelper::transformationDepthToPointCloud(
|
||||||
&xyTables,
|
&(*xy_tables_),
|
||||||
depth_data,
|
depth_data,
|
||||||
pointPixel);
|
pointPixel);
|
||||||
|
|
||||||
@@ -836,8 +836,6 @@ void OBCameraNode::publishDepthPointCloud(const std::shared_ptr<ob::FrameSet> &f
|
|||||||
RCLCPP_INFO_STREAM(logger_, "Saving point cloud to " << filename);
|
RCLCPP_INFO_STREAM(logger_, "Saving point cloud to " << filename);
|
||||||
saveDepthPointsToPly(point_cloud_msg_, filename);
|
saveDepthPointsToPly(point_cloud_msg_, filename);
|
||||||
}
|
}
|
||||||
delete[] data;
|
|
||||||
data = nullptr;
|
|
||||||
delete[] pointcloudData;
|
delete[] pointcloudData;
|
||||||
pointcloudData = nullptr;
|
pointcloudData = nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user