44 bg_sub_params.
beta = 0.85;
63 BlobDetector::Params blob_det_params;
65 blob_det_params.filterByColor =
true;
66 blob_det_params.blobColor = 255;
67 blob_det_params.thresholdStep = 256;
68 blob_det_params.minThreshold = 127;
69 blob_det_params.maxThreshold = 255;
70 blob_det_params.minRepeatability = 1;
72 blob_det_params.minDistBetweenBlobs = 10;
73 nh.
param(
"min_distance_between_blobs", blob_det_params.minDistBetweenBlobs, blob_det_params.minDistBetweenBlobs);
75 blob_det_params.filterByArea =
true;
76 nh.
param(
"filter_by_area", blob_det_params.filterByArea, blob_det_params.filterByArea);
78 blob_det_params.minArea = 3;
79 nh.
param(
"min_area", blob_det_params.minArea, blob_det_params.minArea);
81 blob_det_params.maxArea = 300;
82 nh.
param(
"max_area", blob_det_params.maxArea, blob_det_params.maxArea);
84 blob_det_params.filterByCircularity =
true;
85 nh.
param(
"filter_by_circularity", blob_det_params.filterByCircularity, blob_det_params.filterByCircularity);
87 blob_det_params.minCircularity = 0.2;
88 nh.
param(
"min_circularity", blob_det_params.minCircularity, blob_det_params.minCircularity);
90 blob_det_params.maxCircularity = 1;
91 nh.
param(
"max_circularity", blob_det_params.maxCircularity, blob_det_params.maxCircularity);
93 blob_det_params.filterByInertia =
true;
94 nh.
param(
"filter_by_intertia", blob_det_params.filterByInertia, blob_det_params.filterByInertia);
96 blob_det_params.minInertiaRatio = 0.2;
97 nh.
param(
"min_inertia_ratio", blob_det_params.minInertiaRatio, blob_det_params.minInertiaRatio);
99 blob_det_params.maxInertiaRatio = 1;
100 nh.
param(
"max_intertia_ratio", blob_det_params.maxInertiaRatio, blob_det_params.maxInertiaRatio);
102 blob_det_params.filterByConvexity =
false;
103 nh.
param(
"filter_by_convexity", blob_det_params.filterByConvexity, blob_det_params.filterByConvexity);
105 blob_det_params.minConvexity = 0;
106 nh.
param(
"min_convexity", blob_det_params.minConvexity, blob_det_params.minConvexity);
108 blob_det_params.maxConvexity = 1;
109 nh.
param(
"max_convexity", blob_det_params.maxConvexity, blob_det_params.maxConvexity);
116 tracker_params.
dt = 0.2;
117 nh.
param(
"dt", tracker_params.
dt, tracker_params.
dt);
133 std::string static_converter_plugin =
"costmap_converter::CostmapToPolygonsDBSMCCH";
134 nh.
param(
"static_converter_plugin", static_converter_plugin, static_converter_plugin);
139 dynamic_recfg_ =
new dynamic_reconfigure::Server<CostmapToDynamicObstaclesConfig>(nh);
174 std::vector<std::vector<cv::Point>> contours =
blob_det_->getContours();
180 std::vector<Point_t> detected_centers(
keypoints_.size());
183 detected_centers.at(i).x =
keypoints_.at(i).pt.x;
184 detected_centers.at(i).y =
keypoints_.at(i).pt.y;
185 detected_centers.at(i).z = 0;
188 tracker_->Update(detected_centers, contours);
209 obstacles->header.frame_id =
"/map";
212 for (
unsigned int i = 0; i < (
unsigned int)
tracker_->tracks.size(); ++i)
214 geometry_msgs::Polygon polygon;
217 std::vector<Point_t> contour;
221 for (
const Point_t& pt : contour)
223 polygon.points.emplace_back();
224 polygon.points.back().x = pt.x;
225 polygon.points.back().y = pt.y;
226 polygon.points.back().z = 0;
229 obstacles->obstacles.emplace_back();
230 obstacles->obstacles.back().polygon = polygon;
233 obstacles->obstacles.back().id =
tracker_->tracks.at(i)->track_id;
236 geometry_msgs::QuaternionStamped orientation;
239 double yaw = std::atan2(vel.y, vel.x);
244 geometry_msgs::TwistWithCovariance velocities;
247 velocities.twist.linear.x = vel.x;
248 velocities.twist.linear.y = vel.y;
249 velocities.twist.linear.z = 0;
250 velocities.twist.angular.x = 0;
251 velocities.twist.angular.y = 0;
252 velocities.twist.angular.z = 0;
255 velocities.covariance = {1, 0, 0, 0, 0, 0,
262 obstacles->obstacles.back().velocities = velocities;
268 uchar* img_data = bg_mat.data;
269 int width = bg_mat.cols;
270 int height = bg_mat.rows;
271 int stride = bg_mat.step;
281 for(
int i = 0; i < height; i++)
283 for(
int j = 0; j < width; j++)
285 static_costmap->setCost(j, i, img_data[i * stride + j]);
295 for (
auto it = static_polygons->begin(); it != static_polygons->end(); ++it)
297 obstacles->obstacles.emplace_back();
298 obstacles->obstacles.back().polygon = *it;
299 obstacles->obstacles.back().velocities.twist.linear.x = 0;
300 obstacles->obstacles.back().velocities.twist.linear.y = 0;
301 obstacles->obstacles.back().id = -1;
307 for(
int i = 0; i < height; i++)
309 for(
int j = 0; j < width; j++)
311 uchar value = img_data[i * stride + j];
315 obstacles->obstacles.emplace_back();
316 geometry_msgs::Point32 pt;
319 obstacles->obstacles.back().polygon.points.push_back(pt);
320 obstacles->obstacles.back().velocities.twist.linear.x = 0;
321 obstacles->obstacles.back().velocities.twist.linear.y = 0;
322 obstacles->obstacles.back().id = -1;
346 ROS_ERROR(
"Cannot update costmap since the mutex pointer is null");
360 boost::mutex::scoped_lock lock(
mutex_);
366 boost::mutex::scoped_lock lock(
mutex_);
405 bg_sub_params.
beta = config.beta;
410 bg_sub_->updateParameters(bg_sub_params);
413 BlobDetector::Params blob_det_params;
415 blob_det_params.filterByColor =
true;
416 blob_det_params.blobColor = 255;
417 blob_det_params.thresholdStep = 256;
418 blob_det_params.minThreshold = 127;
419 blob_det_params.maxThreshold = 255;
420 blob_det_params.minRepeatability = 1;
421 blob_det_params.minDistBetweenBlobs = config.min_distance_between_blobs;
422 blob_det_params.filterByArea = config.filter_by_area;
423 blob_det_params.minArea = config.min_area;
424 blob_det_params.maxArea = config.max_area;
425 blob_det_params.filterByCircularity = config.filter_by_circularity;
426 blob_det_params.minCircularity = config.min_circularity;
427 blob_det_params.maxCircularity = config.max_circularity;
428 blob_det_params.filterByInertia = config.filter_by_inertia;
429 blob_det_params.minInertiaRatio = config.min_inertia_ratio;
430 blob_det_params.maxInertiaRatio = config.max_inertia_ratio;
431 blob_det_params.filterByConvexity = config.filter_by_convexity;
432 blob_det_params.minConvexity = config.min_convexity;
433 blob_det_params.maxConvexity = config.max_convexity;
434 blob_det_->updateParameters(blob_det_params);
438 tracking_params.
dt = config.dt;
442 tracker_->updateParameters(tracking_params);
452 std::vector<cv::Point> contour2i =
tracker_->tracks.at(idx)->getLastContour();
454 contour.reserve(contour2i.size());
458 for (std::size_t i = 0; i < contour2i.size(); ++i)
470 cv::Mat im = image.clone();
472 cv::imshow(name, im);
dynamic_reconfigure::Server< CostmapToDynamicObstaclesConfig > * dynamic_recfg_
std::unique_ptr< CTracker > tracker_
void convertStaticObstacles()
Apply the underlying plugin for static costmap conversion.
#define ROS_INFO_ONCE(...)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
int max_allowed_skipped_frames
ObstacleArrayPtr obstacles_
void odomCallback(const nav_msgs::Odometry::ConstPtr &msg)
modifications at runtime
double alpha_fast
Filter constant (learning rate) of the fast filter part.
PLUGINLIB_EXPORT_CLASS(BAGReader, nodelet::Nodelet)
cv::Point3_< track_t > Point_t
double getOriginX() const
virtual void setCostmap2D(costmap_2d::Costmap2D *costmap)
Pass a pointer to the costmap to the plugin.
virtual void updateCostmap2D()
Get updated data from the previously set Costmap2D.
virtual void initialize(ros::NodeHandle nh)
Initialize the plugin.
double alpha_slow
Filter constant (learning rate) of the slow filter part.
unsigned char * getCharMap() const
double min_sep_between_fast_and_slow_filter
double max_occupancy_neighbors
void updateObstacleContainer(ObstacleArrayPtr obstacles)
Thread-safe update of the internal obstacle container (that is shared using getObstacles() from outsi...
TFSIMD_FORCE_INLINE const tfScalar & x() const
void loadStaticCostmapConverterPlugin(const std::string &plugin_name, ros::NodeHandle nh_parent)
Load underlying static costmap conversion plugin via plugin-loader.
Point_t getEstimatedVelocityOfObject(unsigned int idx)
Converts the estimated velocity of a tracked object to m/s and returns it.
static void vector3MsgToTF(const geometry_msgs::Vector3 &msg_v, Vector3 &bt_v)
TFSIMD_FORCE_INLINE const tfScalar & z() const
static void quaternionMsgToTF(const geometry_msgs::Quaternion &msg, Quaternion &bt)
virtual void compute()
This method performs the actual work (conversion of the costmap to obstacles)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
This abstract class defines the interface for plugins that convert the costmap into polygon types...
TFSIMD_FORCE_INLINE const tfScalar & y() const
virtual ~CostmapToDynamicObstacles()
Destructor.
void setStaticCostmap(boost::shared_ptr< costmap_2d::Costmap2D > static_costmap)
Set the costmap for the underlying plugin.
TFSIMD_FORCE_INLINE Vector3 quatRotate(const Quaternion &rotation, const Vector3 &v)
This class converts the costmap_2d into dynamic obstacles.
double getOriginY() const
ros::Subscriber odom_sub_
static cv::Ptr< BlobDetector > create(const BlobDetector::Params ¶ms)
Create shared instance of the blob detector with given parameters.
unsigned int getSizeInCellsY() const
Perform background subtraction to extract the "moving" foreground.
bool publish_static_obstacles_
double min_occupancy_probability
unsigned int getSizeInCellsX() const
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
ObstacleArrayConstPtr getObstacles()
Get a shared instance of the current obstacle container.
costmap_2d::Costmap2D * costmap_
void getContour(unsigned int idx, std::vector< Point_t > &contour)
Gets the last observed contour of a object and converts it from [px] to [m].
std::vector< cv::KeyPoint > keypoints_
cv::Ptr< BlobDetector > blob_det_
void reconfigureCB(CostmapToDynamicObstaclesConfig &config, uint32_t level)
Callback for the dynamic_reconfigure node.
double getResolution() const
void visualize(const std::string &name, const cv::Mat &image)
OpenCV Visualization.
PolygonContainerConstPtr getStaticPolygons()
Get the converted polygons from the underlying plugin.
std::unique_ptr< BackgroundSubtractor > bg_sub_
bool stackedCostmapConversion()
Determines whether an additional plugin for subsequent costmap conversion is specified.