Skip to content

Commit

Permalink
depth_anything: Only publish if topic valid
Browse files Browse the repository at this point in the history
  • Loading branch information
marcojob committed Nov 11, 2024
1 parent adc70f9 commit 7abc401
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions include/usb_cam/learning/depth_anything_v2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ class DepthAnythingV2 : public LearningInterface {
}

void publish() override {
cv::Mat depth_prediction = cv::Mat(_HEIGHT, _WIDTH, CV_32FC1, _output_data);

cv_bridge::CvImage depth_image;
depth_image.header.stamp = ros::Time::now(); // Set the timestamp
depth_image.header.frame_id = "depth_frame"; // Set the frame ID (update as needed)
depth_image.encoding = sensor_msgs::image_encodings::TYPE_32FC1; // Depth is typically float32, single channel
depth_image.image = depth_prediction;

if (_depth_publication.getTopic() != "") {
cv::Mat depth_prediction = cv::Mat(_HEIGHT, _WIDTH, CV_32FC1, _output_data);

cv_bridge::CvImage depth_image;
depth_image.header.stamp = ros::Time::now();
depth_image.header.frame_id = "depth_frame";
depth_image.encoding = sensor_msgs::image_encodings::TYPE_32FC1;
depth_image.image = depth_prediction;
_depth_publication.publish(depth_image.toImageMsg());
}
}
Expand Down

0 comments on commit 7abc401

Please sign in to comment.