Skip to content

Commit

Permalink
Enabling dynamic_reconfigure in private nodelet handler
Browse files Browse the repository at this point in the history
  • Loading branch information
iory committed Aug 18, 2016
1 parent 0051f7b commit 8e826a4
Show file tree
Hide file tree
Showing 17 changed files with 151 additions and 100 deletions.
15 changes: 9 additions & 6 deletions src/nodelet/camshift_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ class CamShiftNodelet : public opencv_apps::Nodelet

boost::shared_ptr<image_transport::ImageTransport> it_;

camshift::CamShiftConfig config_;
dynamic_reconfigure::Server<camshift::CamShiftConfig> srv;
typedef camshift::CamShiftConfig Config;
typedef dynamic_reconfigure::Server<Config> ReconfigureServer;
Config config_;
boost::shared_ptr<ReconfigureServer> reconfigure_server_;

bool debug_view_;
ros::Time prev_stamp_;
Expand Down Expand Up @@ -102,7 +104,7 @@ class CamShiftNodelet : public opencv_apps::Nodelet
on_mouse_y_ = y;
}

void reconfigureCallback(camshift::CamShiftConfig &new_config, uint32_t level)
void reconfigureCallback(Config &new_config, uint32_t level)
{
config_ = new_config;
vmin_ = config_.vmin;
Expand Down Expand Up @@ -161,7 +163,7 @@ class CamShiftNodelet : public opencv_apps::Nodelet
config_.vmin = vmin_;
config_.vmax = vmax_;
config_.smin = smin_;
srv.updateConfig(config_);
reconfigure_server_->updateConfig(config_);
need_config_update_ = false;
}
}
Expand Down Expand Up @@ -374,9 +376,10 @@ class CamShiftNodelet : public opencv_apps::Nodelet
phranges = hranges;
histimg = cv::Mat::zeros(200, 320, CV_8UC3);

dynamic_reconfigure::Server<camshift::CamShiftConfig>::CallbackType f =
reconfigure_server_ = boost::make_shared<dynamic_reconfigure::Server<Config> >(*pnh_);
dynamic_reconfigure::Server<Config>::CallbackType f =
boost::bind(&CamShiftNodelet::reconfigureCallback, this, _1, _2);
srv.setCallback(f);
reconfigure_server_->setCallback(f);


img_pub_ = advertiseImage(*pnh_, "image", 1);
Expand Down
13 changes: 8 additions & 5 deletions src/nodelet/contour_moments_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ class ContourMomentsNodelet : public opencv_apps::Nodelet

boost::shared_ptr<image_transport::ImageTransport> it_;

contour_moments::ContourMomentsConfig config_;
dynamic_reconfigure::Server<contour_moments::ContourMomentsConfig> srv;
typedef contour_moments::ContourMomentsConfig Config;
typedef dynamic_reconfigure::Server<Config> ReconfigureServer;
Config config_;
boost::shared_ptr<ReconfigureServer> reconfigure_server_;

bool debug_view_;
ros::Time prev_stamp_;
Expand All @@ -75,7 +77,7 @@ class ContourMomentsNodelet : public opencv_apps::Nodelet
std::string window_name_;
static bool need_config_update_;

void reconfigureCallback(contour_moments::ContourMomentsConfig &new_config, uint32_t level)
void reconfigureCallback(Config &new_config, uint32_t level)
{
config_ = new_config;
low_threshold_ = config_.canny_low_threshold;
Expand Down Expand Up @@ -251,9 +253,10 @@ class ContourMomentsNodelet : public opencv_apps::Nodelet
window_name_ = "Contours";
low_threshold_ = 100; // only for canny

dynamic_reconfigure::Server<contour_moments::ContourMomentsConfig>::CallbackType f =
reconfigure_server_ = boost::make_shared<dynamic_reconfigure::Server<Config> >(*pnh_);
dynamic_reconfigure::Server<Config>::CallbackType f =
boost::bind(&ContourMomentsNodelet::reconfigureCallback, this, _1, _2);
srv.setCallback(f);
reconfigure_server_->setCallback(f);

img_pub_ = advertiseImage(*pnh_, "image", 1);
msg_pub_ = advertise<opencv_apps::MomentArrayStamped>(*pnh_, "moments", 1);
Expand Down
15 changes: 9 additions & 6 deletions src/nodelet/convex_hull_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ class ConvexHullNodelet : public opencv_apps::Nodelet

boost::shared_ptr<image_transport::ImageTransport> it_;

convex_hull::ConvexHullConfig config_;
dynamic_reconfigure::Server<convex_hull::ConvexHullConfig> srv;
typedef convex_hull::ConvexHullConfig Config;
typedef dynamic_reconfigure::Server<Config> ReconfigureServer;
Config config_;
boost::shared_ptr<ReconfigureServer> reconfigure_server_;

bool debug_view_;
ros::Time prev_stamp_;
Expand All @@ -75,7 +77,7 @@ class ConvexHullNodelet : public opencv_apps::Nodelet
std::string window_name_;
static bool need_config_update_;

void reconfigureCallback(convex_hull::ConvexHullConfig &new_config, uint32_t level)
void reconfigureCallback(Config &new_config, uint32_t level)
{
config_ = new_config;
threshold_ = config_.threshold;
Expand Down Expand Up @@ -170,7 +172,7 @@ class ConvexHullNodelet : public opencv_apps::Nodelet
if( debug_view_) {
if (need_config_update_) {
config_.threshold = threshold_;
srv.updateConfig(config_);
reconfigure_server_->updateConfig(config_);
need_config_update_ = false;
}
cv::createTrackbar( "Threshold:", window_name_, &threshold_, max_thresh, trackbarCallback);
Expand Down Expand Up @@ -224,9 +226,10 @@ class ConvexHullNodelet : public opencv_apps::Nodelet
window_name_ = "Hull Demo";
threshold_ = 100;

dynamic_reconfigure::Server<convex_hull::ConvexHullConfig>::CallbackType f =
reconfigure_server_ = boost::make_shared<dynamic_reconfigure::Server<Config> >(*pnh_);
dynamic_reconfigure::Server<Config>::CallbackType f =
boost::bind(&ConvexHullNodelet::reconfigureCallback, this, _1, _2);
srv.setCallback(f);
reconfigure_server_->setCallback(f);

img_pub_ = advertiseImage(*pnh_, "image", 1);
msg_pub_ = advertise<opencv_apps::ContourArrayStamped>(*pnh_, "hulls", 1);
Expand Down
15 changes: 9 additions & 6 deletions src/nodelet/edge_detection_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ class EdgeDetectionNodelet : public opencv_apps::Nodelet

boost::shared_ptr<image_transport::ImageTransport> it_;

edge_detection::EdgeDetectionConfig config_;
dynamic_reconfigure::Server<edge_detection::EdgeDetectionConfig> srv;
typedef edge_detection::EdgeDetectionConfig Config;
typedef dynamic_reconfigure::Server<Config> ReconfigureServer;
Config config_;
boost::shared_ptr<ReconfigureServer> reconfigure_server_;

bool debug_view_;
ros::Time prev_stamp_;
Expand All @@ -90,7 +92,7 @@ class EdgeDetectionNodelet : public opencv_apps::Nodelet
std::string window_name_;
static bool need_config_update_;

void reconfigureCallback(edge_detection::EdgeDetectionConfig &new_config, uint32_t level)
void reconfigureCallback(Config &new_config, uint32_t level)
{
config_ = new_config;
canny_threshold1_ = config_.canny_threshold1;
Expand Down Expand Up @@ -221,7 +223,7 @@ class EdgeDetectionNodelet : public opencv_apps::Nodelet
if (need_config_update_) {
config_.canny_threshold1 = canny_threshold1_;
config_.canny_threshold2 = canny_threshold2_;
srv.updateConfig(config_);
reconfigure_server_->updateConfig(config_);
need_config_update_ = false;
}
if( window_name_ == new_window_name) {
Expand Down Expand Up @@ -288,9 +290,10 @@ class EdgeDetectionNodelet : public opencv_apps::Nodelet
canny_threshold1_ = 100; // only for canny
canny_threshold2_ = 200; // only for canny

dynamic_reconfigure::Server<edge_detection::EdgeDetectionConfig>::CallbackType f =
reconfigure_server_ = boost::make_shared<dynamic_reconfigure::Server<Config> >(*pnh_);
dynamic_reconfigure::Server<Config>::CallbackType f =
boost::bind(&EdgeDetectionNodelet::reconfigureCallback, this, _1, _2);
srv.setCallback(f);
reconfigure_server_->setCallback(f);

img_pub_ = advertiseImage(*pnh_, "image", 1);
//msg_pub_ = local_nh_.advertise<opencv_apps::LineArrayStamped>("lines", 1, msg_connect_cb, msg_disconnect_cb);
Expand Down
13 changes: 8 additions & 5 deletions src/nodelet/face_detection_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,18 @@ class FaceDetectionNodelet : public opencv_apps::Nodelet

boost::shared_ptr<image_transport::ImageTransport> it_;

face_detection::FaceDetectionConfig config_;
dynamic_reconfigure::Server<face_detection::FaceDetectionConfig> srv;
typedef face_detection::FaceDetectionConfig Config;
typedef dynamic_reconfigure::Server<Config> ReconfigureServer;
Config config_;
boost::shared_ptr<ReconfigureServer> reconfigure_server_;

bool debug_view_;
ros::Time prev_stamp_;

cv::CascadeClassifier face_cascade_;
cv::CascadeClassifier eyes_cascade_;

void reconfigureCallback(face_detection::FaceDetectionConfig &new_config, uint32_t level)
void reconfigureCallback(Config &new_config, uint32_t level)
{
config_ = new_config;
}
Expand Down Expand Up @@ -207,9 +209,10 @@ class FaceDetectionNodelet : public opencv_apps::Nodelet
}
prev_stamp_ = ros::Time(0, 0);

dynamic_reconfigure::Server<face_detection::FaceDetectionConfig>::CallbackType f =
reconfigure_server_ = boost::make_shared<dynamic_reconfigure::Server<Config> >(*pnh_);
dynamic_reconfigure::Server<Config>::CallbackType f =
boost::bind(&FaceDetectionNodelet::reconfigureCallback, this, _1, _2);
srv.setCallback(f);
reconfigure_server_->setCallback(f);

img_pub_ = advertiseImage(*pnh_, "image", 1);
msg_pub_ = advertise<opencv_apps::FaceArrayStamped>(*pnh_, "faces", 1);
Expand Down
15 changes: 9 additions & 6 deletions src/nodelet/fback_flow_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ class FBackFlowNodelet : public opencv_apps::Nodelet

boost::shared_ptr<image_transport::ImageTransport> it_;

fback_flow::FBackFlowConfig config_;
dynamic_reconfigure::Server<fback_flow::FBackFlowConfig> srv;
typedef fback_flow::FBackFlowConfig Config;
typedef dynamic_reconfigure::Server<Config> ReconfigureServer;
Config config_;
boost::shared_ptr<ReconfigureServer> reconfigure_server_;

bool debug_view_;
ros::Time prev_stamp_;
Expand All @@ -72,7 +74,7 @@ class FBackFlowNodelet : public opencv_apps::Nodelet

cv::Mat prevgray, gray, flow, cflow;

void reconfigureCallback(fback_flow::FBackFlowConfig &new_config, uint32_t level)
void reconfigureCallback(Config &new_config, uint32_t level)
{
config_ = new_config;
}
Expand Down Expand Up @@ -114,7 +116,7 @@ class FBackFlowNodelet : public opencv_apps::Nodelet
if( debug_view_) {
cv::namedWindow( window_name_, cv::WINDOW_AUTOSIZE );
if (need_config_update_) {
srv.updateConfig(config_);
reconfigure_server_->updateConfig(config_);
need_config_update_ = false;
}
}
Expand Down Expand Up @@ -205,9 +207,10 @@ class FBackFlowNodelet : public opencv_apps::Nodelet

window_name_ = "flow";

dynamic_reconfigure::Server<fback_flow::FBackFlowConfig>::CallbackType f =
reconfigure_server_ = boost::make_shared<dynamic_reconfigure::Server<Config> >(*pnh_);
dynamic_reconfigure::Server<Config>::CallbackType f =
boost::bind(&FBackFlowNodelet::reconfigureCallback, this, _1, _2);
srv.setCallback(f);
reconfigure_server_->setCallback(f);

img_pub_ = advertiseImage(*pnh_, "image", 1);
msg_pub_ = advertise<opencv_apps::FlowArrayStamped>(*pnh_, "flows", 1);
Expand Down
15 changes: 9 additions & 6 deletions src/nodelet/find_contours_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ class FindContoursNodelet : public opencv_apps::Nodelet

boost::shared_ptr<image_transport::ImageTransport> it_;

find_contours::FindContoursConfig config_;
dynamic_reconfigure::Server<find_contours::FindContoursConfig> srv;
typedef find_contours::FindContoursConfig Config;
typedef dynamic_reconfigure::Server<Config> ReconfigureServer;
Config config_;
boost::shared_ptr<ReconfigureServer> reconfigure_server_;

bool debug_view_;
ros::Time prev_stamp_;
Expand All @@ -75,7 +77,7 @@ class FindContoursNodelet : public opencv_apps::Nodelet
std::string window_name_;
static bool need_config_update_;

void reconfigureCallback(find_contours::FindContoursConfig &new_config, uint32_t level)
void reconfigureCallback(Config &new_config, uint32_t level)
{
config_ = new_config;
low_threshold_ = config_.canny_low_threshold;
Expand Down Expand Up @@ -167,7 +169,7 @@ class FindContoursNodelet : public opencv_apps::Nodelet
if( debug_view_) {
if (need_config_update_) {
config_.canny_low_threshold = low_threshold_;
srv.updateConfig(config_);
reconfigure_server_->updateConfig(config_);
need_config_update_ = false;
}
cv::createTrackbar( "Canny thresh:", window_name_, &low_threshold_, max_thresh, trackbarCallback);
Expand Down Expand Up @@ -220,9 +222,10 @@ class FindContoursNodelet : public opencv_apps::Nodelet
window_name_ = "Demo code to find contours in an image";
low_threshold_ = 100; // only for canny

dynamic_reconfigure::Server<find_contours::FindContoursConfig>::CallbackType f =
reconfigure_server_ = boost::make_shared<dynamic_reconfigure::Server<Config> >(*pnh_);
dynamic_reconfigure::Server<Config>::CallbackType f =
boost::bind(&FindContoursNodelet::reconfigureCallback, this, _1, _2);
srv.setCallback(f);
reconfigure_server_->setCallback(f);

img_pub_ = advertiseImage(*pnh_, "image", 1);
msg_pub_ = advertise<opencv_apps::ContourArrayStamped>(*pnh_, "contours", 1);
Expand Down
15 changes: 9 additions & 6 deletions src/nodelet/general_contours_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ class GeneralContoursNodelet : public opencv_apps::Nodelet

boost::shared_ptr<image_transport::ImageTransport> it_;

general_contours::GeneralContoursConfig config_;
dynamic_reconfigure::Server<general_contours::GeneralContoursConfig> srv;
typedef general_contours::GeneralContoursConfig Config;
typedef dynamic_reconfigure::Server<Config> ReconfigureServer;
Config config_;
boost::shared_ptr<ReconfigureServer> reconfigure_server_;

bool debug_view_;
ros::Time prev_stamp_;
Expand All @@ -75,7 +77,7 @@ class GeneralContoursNodelet : public opencv_apps::Nodelet
std::string window_name_;
static bool need_config_update_;

void reconfigureCallback(general_contours::GeneralContoursConfig &new_config, uint32_t level)
void reconfigureCallback(Config &new_config, uint32_t level)
{
config_ = new_config;
threshold_ = config_.threshold;
Expand Down Expand Up @@ -197,7 +199,7 @@ class GeneralContoursNodelet : public opencv_apps::Nodelet
if( debug_view_) {
if (need_config_update_) {
config_.threshold = threshold_;
srv.updateConfig(config_);
reconfigure_server_->updateConfig(config_);
need_config_update_ = false;
}
cv::createTrackbar( "Threshold:", window_name_, &threshold_, max_thresh, trackbarCallback);
Expand Down Expand Up @@ -251,9 +253,10 @@ class GeneralContoursNodelet : public opencv_apps::Nodelet
window_name_ = "Contours";
threshold_ = 100;

dynamic_reconfigure::Server<general_contours::GeneralContoursConfig>::CallbackType f =
reconfigure_server_ = boost::make_shared<dynamic_reconfigure::Server<Config> >(*pnh_);
dynamic_reconfigure::Server<Config>::CallbackType f =
boost::bind(&GeneralContoursNodelet::reconfigureCallback, this, _1, _2);
srv.setCallback(f);
reconfigure_server_->setCallback(f);

img_pub_ = advertiseImage(*pnh_, "image", 1);
rects_pub_ = advertise<opencv_apps::RotatedRectArrayStamped>(*pnh_, "rectangles", 1);
Expand Down
15 changes: 9 additions & 6 deletions src/nodelet/goodfeature_track_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ class GoodfeatureTrackNodelet : public opencv_apps::Nodelet

boost::shared_ptr<image_transport::ImageTransport> it_;

goodfeature_track::GoodfeatureTrackConfig config_;
dynamic_reconfigure::Server<goodfeature_track::GoodfeatureTrackConfig> srv;
typedef goodfeature_track::GoodfeatureTrackConfig Config;
typedef dynamic_reconfigure::Server<Config> ReconfigureServer;
Config config_;
boost::shared_ptr<ReconfigureServer> reconfigure_server_;

bool debug_view_;
ros::Time prev_stamp_;
Expand All @@ -73,7 +75,7 @@ class GoodfeatureTrackNodelet : public opencv_apps::Nodelet

int max_corners_;

void reconfigureCallback(goodfeature_track::GoodfeatureTrackConfig &new_config, uint32_t level)
void reconfigureCallback(Config &new_config, uint32_t level)
{
config_ = new_config;
max_corners_ = config_.max_corners;
Expand Down Expand Up @@ -130,7 +132,7 @@ class GoodfeatureTrackNodelet : public opencv_apps::Nodelet
cv::createTrackbar( "Max corners", window_name_, &max_corners_, maxTrackbar, trackbarCallback);
if (need_config_update_) {
config_.max_corners = max_corners_;
srv.updateConfig(config_);
reconfigure_server_->updateConfig(config_);
need_config_update_ = false;
}
}
Expand Down Expand Up @@ -223,9 +225,10 @@ class GoodfeatureTrackNodelet : public opencv_apps::Nodelet
window_name_ = "Image";
max_corners_ = 23;

dynamic_reconfigure::Server<goodfeature_track::GoodfeatureTrackConfig>::CallbackType f =
reconfigure_server_ = boost::make_shared<dynamic_reconfigure::Server<Config> >(*pnh_);
dynamic_reconfigure::Server<Config>::CallbackType f =
boost::bind(&GoodfeatureTrackNodelet::reconfigureCallback, this, _1, _2);
srv.setCallback(f);
reconfigure_server_->setCallback(f);

img_pub_ = advertiseImage(*pnh_, "image", 1);
msg_pub_ = advertise<opencv_apps::Point2DArrayStamped>(*pnh_, "corners", 1);
Expand Down
Loading

0 comments on commit 8e826a4

Please sign in to comment.