add yolo + mot cpp into driver
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
#include <pcl/point_cloud.h>
|
||||
#include <pcl/point_types.h>
|
||||
|
||||
#include "cloud_reprojector.hpp"
|
||||
|
||||
namespace odin_ros_driver {
|
||||
|
||||
cv::Mat resize_to_height(const cv::Mat& src, int target_h);
|
||||
|
||||
cv::Mat decode_compressed_to_bgr(const uint8_t* data, size_t len);
|
||||
|
||||
cv::Mat overlay_projected_cloud_on_image(
|
||||
const cv::Mat& camera_bgr,
|
||||
const pcl::PointCloud<pcl::PointXYZRGB>& cloud_in_cam,
|
||||
const CloudReprojector::CameraParams& cam_params,
|
||||
int point_radius = 2,
|
||||
float min_depth = 0.5f,
|
||||
float max_depth = 30.0f);
|
||||
|
||||
} // namespace odin_ros_driver
|
||||
@@ -15,10 +15,13 @@ limitations under the License.
|
||||
|
||||
#ifdef ROS2
|
||||
#include <rclcpp/rclcpp.hpp>
|
||||
#include <geometry_msgs/msg/point_stamped.hpp>
|
||||
#include <sensor_msgs/msg/point_cloud2.hpp>
|
||||
#include <sensor_msgs/msg/image.hpp>
|
||||
#include <sensor_msgs/msg/compressed_image.hpp>
|
||||
#include <nav_msgs/msg/odometry.hpp>
|
||||
#include <std_msgs/msg/float32_multi_array.hpp>
|
||||
#include <std_msgs/msg/int32.hpp>
|
||||
#include <cv_bridge/cv_bridge.h>
|
||||
#include <message_filters/subscriber.h>
|
||||
#include <message_filters/sync_policies/approximate_time.h>
|
||||
@@ -42,6 +45,10 @@ limitations under the License.
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#ifdef ODIN_ROS_DRIVER_HAS_TARGET_OBSERVATION
|
||||
#include "target_observation_processing.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef ROS2
|
||||
class CloudReprojectionRosNode : public rclcpp::Node
|
||||
{
|
||||
@@ -80,6 +87,10 @@ private:
|
||||
std::string sync_wiwc_topic_;
|
||||
std::string sync_image_topic_;
|
||||
std::string sync_overlay_image_topic_;
|
||||
std::string sync_target_track_id_topic_;
|
||||
std::string sync_target_observation_topic_;
|
||||
std::string sync_target_pos_cam_topic_;
|
||||
std::string sync_target_pos_world_topic_;
|
||||
|
||||
rclcpp::Publisher<PointCloud2>::SharedPtr sync_cloud_pub_;
|
||||
rclcpp::Publisher<PointCloud2>::SharedPtr sync_cloud_slam_pub_;
|
||||
@@ -89,8 +100,17 @@ private:
|
||||
|
||||
rclcpp::Publisher<CompressedImage>::SharedPtr overlay_compressed_pub_; // optional if send_overlay_
|
||||
rclcpp::Publisher<CompressedImage>::SharedPtr combined_pub_; // optional if publish_combined_compressed_
|
||||
rclcpp::Publisher<std_msgs::msg::Int32>::SharedPtr target_track_id_pub_;
|
||||
rclcpp::Publisher<std_msgs::msg::Float32MultiArray>::SharedPtr target_observation_pub_;
|
||||
rclcpp::Publisher<geometry_msgs::msg::PointStamped>::SharedPtr target_pos_cam_pub_;
|
||||
rclcpp::Publisher<geometry_msgs::msg::PointStamped>::SharedPtr target_pos_world_pub_;
|
||||
|
||||
std::unique_ptr<CloudReprojector> reprojector_;
|
||||
#ifdef ODIN_ROS_DRIVER_HAS_TARGET_OBSERVATION
|
||||
std::unique_ptr<odin_ros_driver::TargetObservationProcessor> target_observation_processor_;
|
||||
bool enable_target_observation_ = false;
|
||||
bool debug_target_observation_ = false;
|
||||
#endif
|
||||
|
||||
void loadParameters();
|
||||
void syncCallback(const PointCloud2::ConstSharedPtr& cloud_msg,
|
||||
|
||||
@@ -65,6 +65,12 @@ public:
|
||||
cv::Mat reprojectCloudDepth(const pcl::PointCloud<pcl::PointXYZRGB>& cloud_odom,
|
||||
const OdomPose& odom_pose);
|
||||
|
||||
Eigen::Vector2d projectCameraPointToPixel(const Eigen::Vector3d& point_cam) const;
|
||||
Eigen::Vector3d pixelToCameraRay(double u, double v) const;
|
||||
Eigen::Vector3d pixelToCameraPoint(double u, double v, double depth_z) const;
|
||||
Eigen::Vector3d cameraPointToWorld(const Eigen::Vector3d& point_cam,
|
||||
const OdomPose& odom_pose) const;
|
||||
|
||||
void setPointRadius(int radius) { point_radius_ = radius; }
|
||||
int getPointRadius() const { return point_radius_; }
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <Eigen/Dense>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <pcl/point_cloud.h>
|
||||
#include <pcl/point_types.h>
|
||||
|
||||
#include "cloud_reprojector.hpp"
|
||||
#include "motcpp/trackers/bytetrack.hpp"
|
||||
#include "yolos/tasks/pose.hpp"
|
||||
|
||||
namespace odin_ros_driver {
|
||||
|
||||
struct TargetObservationConfig {
|
||||
std::string yolo_engine_path;
|
||||
std::string yolo_labels_path;
|
||||
float yolo_conf = 0.45f;
|
||||
float yolo_nms = 0.50f;
|
||||
float min_depth = 0.5f;
|
||||
float max_depth = 12.0f;
|
||||
float search_radius_px = 25.0f;
|
||||
bool debug = false;
|
||||
};
|
||||
|
||||
struct TargetObservation {
|
||||
bool valid = false;
|
||||
int track_id = -1;
|
||||
int detection_index = -1;
|
||||
float confidence = 0.0f;
|
||||
float depth = -1.0f;
|
||||
float depth_confidence = 0.0f;
|
||||
std::array<float, 4> bbox_xyxy{0.0f, 0.0f, 0.0f, 0.0f};
|
||||
std::array<float, 17 * 3> keypoints_xyc{};
|
||||
Eigen::Vector3f target_pos_cam = Eigen::Vector3f::Zero();
|
||||
Eigen::Vector3f target_pos_world = Eigen::Vector3f::Zero();
|
||||
};
|
||||
|
||||
struct TargetObservationDebugInfo {
|
||||
int current_target_id_before = -1;
|
||||
int poses_count = 0;
|
||||
int tracks_count = 0;
|
||||
int selected_track_id = -1;
|
||||
int detection_index = -1;
|
||||
int projected_cloud_points = 0;
|
||||
int depth_sample_count = 0;
|
||||
bool found_existing_target = false;
|
||||
bool target_selected = false;
|
||||
float yolo_ms = 0.0f;
|
||||
float mot_ms = 0.0f;
|
||||
float depth_ms = 0.0f;
|
||||
float total_ms = 0.0f;
|
||||
};
|
||||
|
||||
class TargetObservationProcessor {
|
||||
public:
|
||||
TargetObservationProcessor() = default;
|
||||
|
||||
void initialize(const TargetObservationConfig& config);
|
||||
|
||||
TargetObservation process(
|
||||
const cv::Mat& camera_bgr,
|
||||
const pcl::PointCloud<pcl::PointXYZRGB>& cloud_in_cam,
|
||||
const CloudReprojector& reprojector,
|
||||
const CloudReprojector::OdomPose& odom_pose,
|
||||
TargetObservationDebugInfo* debug_info = nullptr);
|
||||
|
||||
bool initialized() const { return initialized_; }
|
||||
|
||||
private:
|
||||
Eigen::MatrixXf format_detections(
|
||||
const std::vector<yolos::pose::PoseResult>& poses) const;
|
||||
|
||||
TargetObservation select_target(
|
||||
const std::vector<yolos::pose::PoseResult>& poses,
|
||||
const Eigen::MatrixXf& tracks,
|
||||
int image_width,
|
||||
int image_height,
|
||||
TargetObservationDebugInfo* debug_info);
|
||||
|
||||
TargetObservation enrich_target_with_cloud(
|
||||
const TargetObservation& target,
|
||||
const std::vector<yolos::pose::PoseResult>& poses,
|
||||
const pcl::PointCloud<pcl::PointXYZRGB>& cloud_in_cam,
|
||||
const CloudReprojector& reprojector,
|
||||
const CloudReprojector::OdomPose& odom_pose,
|
||||
TargetObservationDebugInfo* debug_info) const;
|
||||
|
||||
TargetObservationConfig config_;
|
||||
std::unique_ptr<yolos::pose::YOLOPoseDetector> yolo_;
|
||||
std::unique_ptr<motcpp::trackers::ByteTrack> tracker_;
|
||||
int current_target_id_ = -1;
|
||||
bool initialized_ = false;
|
||||
};
|
||||
|
||||
void draw_target_observation_overlay(
|
||||
cv::Mat& image_bgr,
|
||||
const TargetObservation& observation);
|
||||
|
||||
} // namespace odin_ros_driver
|
||||
Reference in New Issue
Block a user