ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
roi_to_position_converter.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include <ros/ros.h>
9 
10 #include <cv_bridge/cv_bridge.h>
11 
12 #include <image_transport/image_transport.h>
13 
14 #include <sensor_msgs/CameraInfo.h>
15 #include <sensor_msgs/Image.h>
16 #include <sensor_msgs/RegionOfInterest.h>
17 
18 #include <Eigen/Dense>
19 
20 #include <boost/thread/mutex.hpp>
21 
26 public:
32  RoiToPositionConverter(ros::NodeHandle &nh)
33  : BaseTracker(new SimpleTrackingStrategy()), it_(nh),
34  roi_subscriber_(nh.subscribe(
35  "roi", 10, &RoiToPositionConverter::roiCallback, this)),
36  camera_info_subscriber_(
37  nh.subscribe("camera_info", 1,
38  &RoiToPositionConverter::cameraInfoCallback, this)),
39  depth_subscriber_(nh.subscribe(
40  "depth", 1, &RoiToPositionConverter::depthCallback, this)),
41  image_subscriber_(it_.subscribe(
42  "image", 1, &RoiToPositionConverter::imageCallback, this)) {}
43 
49  bool getTrackingVectors(std::unordered_map<uint32_t, Position> &pos);
60  static void computeTrackingVector(const sensor_msgs::RegionOfInterest &roi,
61  const cv::Mat &depth,
62  const sensor_msgs::CameraInfo &cam_info,
63  double max_distance,
64  double foreground_percent, Position &pos);
69  bool trackingIsValid();
70 
75  bool isConnected();
76 
77 private:
82  bool cameraInfoIsValid();
87  bool roiIsValid();
92  void roiCallback(const sensor_msgs::RegionOfInterest &roi_msg);
93 
98  void imageCallback(const sensor_msgs::ImageConstPtr &img_msg);
99 
104  void cameraInfoCallback(const sensor_msgs::CameraInfo &cam_info_msg);
105 
110  void depthCallback(const sensor_msgs::ImageConstPtr &depth_msg);
111 
118  static bool compare(Eigen::Vector3d a, Eigen::Vector3d b);
119 
123  image_transport::ImageTransport it_;
127  ros::Subscriber roi_subscriber_;
131  ros::Subscriber camera_info_subscriber_;
135  ros::Subscriber depth_subscriber_;
139  image_transport::Subscriber image_subscriber_;
143  Atomic<sensor_msgs::CameraInfo> camera_info_;
151  Atomic<Position> object_position_;
156  double max_object_distance_ = 3.0;
161  double foreground_percent_ = 0.25;
162 
166  Atomic<ros::Time> last_roi_update_time_;
167 };
A strategy that simply returns the first element in the list of tracking vectors Should be used if yo...
Definition: simple_tracking_strategy.h:10
Converts a ROI in image to vector in camera frame.
Definition: roi_to_position_converter.h:25
static void computeTrackingVector(const sensor_msgs::RegionOfInterest &roi, const cv::Mat &depth, const sensor_msgs::CameraInfo &cam_info, double max_distance, double foreground_percent, Position &pos)
Get the 3D position of the ROI (in the frame of the camera)
Definition: roi_to_position_converter.cpp:88
Interface for classes that provide a vector to a tracked target.
Definition: base_tracker.h:13
bool isConnected()
Check whether topics are connected.
Definition: roi_to_position_converter.cpp:7
bool trackingIsValid()
Check whether tracking is valid.
Definition: roi_to_position_converter.cpp:60
bool getTrackingVectors(std::unordered_map< uint32_t, Position > &pos)
Get the stored tracking vector.
Definition: roi_to_position_converter.cpp:78
RoiToPositionConverter(ros::NodeHandle &nh)
Constructor.
Definition: roi_to_position_converter.h:32
Store 3D position.
Definition: position.h:8