-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[jsk_pcl_ros_utils] add PolygonArrayLikelihoodFilter #2054
Merged
k-okada
merged 4 commits into
jsk-ros-pkg:master
from
furushchev:polygonarray-unwrapper
Jun 14, 2017
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
22fecd1
[jsk_pcl_ros_utils] add polygon_array_likelihood_filter
furushchev ac1345d
[jsk_pcl_ros_utils][polygon_array_likelihood_filter] fix
furushchev 2e58758
Merge remote-tracking branch 'origin/master' into polygonarray-unwrapper
furushchev 00eeedc
[jsk_pcl_ros_utils] add sample / test for polygon_array_likelihood_fi…
furushchev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+449 KB
doc/jsk_pcl_ros_utils/nodes/images/polygon_array_likelihood_filter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions
48
doc/jsk_pcl_ros_utils/nodes/polygon_array_likelihood_filter.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
PolygonArrayLikelihoodFilter | ||
===================== | ||
|
||
.. image:: ./images/polygon_array_likelihood_filter.png | ||
|
||
Filter ``jsk_recognition_msgs/PolygonArray`` by likelihood. | ||
|
||
|
||
Subscribing Topics | ||
------------------ | ||
|
||
* ``~input_polygons`` (``jsk_recognition_msgs/PolygonArray``) | ||
|
||
Input polygon array. | ||
|
||
* ``~input_coefficients`` (``jsk_recognition_msgs/ModelCoefficientsArray``) | ||
|
||
Input coefficients array. | ||
(Enabled if ``use_coefficients`` is ``true``. Expected the same order with input polygons) | ||
|
||
|
||
Publishing Topics | ||
----------------- | ||
|
||
* ``~output_polygon`` (``jsk_recognition_msgs/PolygonArray``) | ||
|
||
Filtered polygon array. (Polygons are sorted by their likelihood.) | ||
|
||
* ``~output_coefficients`` (``jsk_recognition_msgs/ModelCoefficientsArray``) | ||
|
||
Filtered coefficients array. (Published only if ``use_coefficients`` is ``true``.) | ||
|
||
|
||
Parameters | ||
---------- | ||
|
||
* ``~use_coefficients`` (Bool, default: ``true``) | ||
|
||
If ``true``, polygons and coefficients are subscribed and published synchronously. | ||
|
||
* ``~threshold`` (Double, default: ``0.5``) | ||
|
||
Threshold for filtering polygons. | ||
See also description of ``~negative`` below for more detail. | ||
|
||
* ``~negative`` (Bool, default: ``false``) | ||
|
||
If ``false``, published polygons whose likelihood is higher than ``~threshold``, lower otherwise. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env python | ||
|
||
PACKAGE = 'jsk_pcl_ros_utils' | ||
|
||
from dynamic_reconfigure.parameter_generator_catkin import * | ||
|
||
gen = ParameterGenerator() | ||
|
||
# variable type level description default min max | ||
gen.add("queue_size", int_t, 0, "queue size", 100, 1, 1000) | ||
gen.add("threshold", double_t, 0, "Minimum likelihood", 0.5, 0.0, 1.0) | ||
gen.add("negative", bool_t, 0, "Choose negative value", False) | ||
exit(gen.generate(PACKAGE, PACKAGE, "PolygonArrayLikelihoodFilter")) |
89 changes: 89 additions & 0 deletions
89
jsk_pcl_ros_utils/include/jsk_pcl_ros_utils/polygon_array_likelihood_filter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// -*- mode: c++ -*- | ||
/********************************************************************* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Copyright (c) 2017, JSK Lab | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/o2r other materials provided | ||
* with the distribution. | ||
* * Neither the name of the JSK Lab nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*********************************************************************/ | ||
|
||
|
||
#ifndef JSK_PCL_ROS_UTILS_POLYGON_ARRAY_LIKELIHOOD_FILTER_H_ | ||
#define JSK_PCL_ROS_UTILS_POLYGON_ARRAY_LIKELIHOOD_FILTER_H_ | ||
|
||
#include <message_filters/subscriber.h> | ||
#include <message_filters/time_synchronizer.h> | ||
#include <message_filters/synchronizer.h> | ||
|
||
#include <dynamic_reconfigure/server.h> | ||
#include <jsk_pcl_ros_utils/PolygonArrayLikelihoodFilterConfig.h> | ||
#include <jsk_recognition_msgs/PolygonArray.h> | ||
#include <jsk_recognition_msgs/ModelCoefficientsArray.h> | ||
#include <jsk_topic_tools/diagnostic_nodelet.h> | ||
|
||
|
||
namespace jsk_pcl_ros_utils | ||
{ | ||
class PolygonArrayLikelihoodFilter: public jsk_topic_tools::DiagnosticNodelet | ||
{ | ||
public: | ||
typedef PolygonArrayLikelihoodFilterConfig Config; | ||
typedef message_filters::sync_policies::ExactTime< | ||
jsk_recognition_msgs::PolygonArray, | ||
jsk_recognition_msgs::ModelCoefficientsArray> | ||
SyncPolicy; | ||
PolygonArrayLikelihoodFilter(): DiagnosticNodelet("PolygonArrayLikelihoodFilter") {} | ||
protected: | ||
virtual void onInit(); | ||
virtual void subscribe(); | ||
virtual void unsubscribe(); | ||
virtual void configCallback(Config &config, uint32_t level); | ||
virtual void filter( | ||
const jsk_recognition_msgs::PolygonArray::ConstPtr& polygons); | ||
virtual void filter( | ||
const jsk_recognition_msgs::PolygonArray::ConstPtr& polygons, | ||
const jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr& coefficients); | ||
boost::mutex mutex_; | ||
boost::shared_ptr<dynamic_reconfigure::Server<Config> > srv_; | ||
boost::shared_ptr<message_filters::Synchronizer<SyncPolicy> >sync_; | ||
message_filters::Subscriber<jsk_recognition_msgs::PolygonArray> sub_polygons_; | ||
message_filters::Subscriber<jsk_recognition_msgs::ModelCoefficientsArray> sub_coefficients_; | ||
ros::Subscriber sub_polygons_alone_; | ||
ros::Publisher pub_polygons_; | ||
ros::Publisher pub_coefficients_; | ||
bool negative_; | ||
bool use_coefficients_; | ||
double threshold_; | ||
size_t queue_size_; | ||
private: | ||
|
||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
jsk_pcl_ros_utils/sample/sample_polygon_array_likelihood_filter.launch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<launch> | ||
<include file="$(find jsk_recognition_utils)/sample/sample_polygon_array_publisher.launch"> | ||
<arg name="gui" value="false" /> | ||
</include> | ||
|
||
<node name="polygon_array_likelihood_filter" | ||
pkg="jsk_pcl_ros_utils" type="polygon_array_likelihood_filter"> | ||
<remap from="~input_polygons" to="/polygon_array_publisher/output" /> | ||
<rosparam> | ||
use_coefficients: false | ||
threshold: 0.8 | ||
</rosparam> | ||
</node> | ||
</launch> |
166 changes: 166 additions & 0 deletions
166
jsk_pcl_ros_utils/src/polygon_array_likelihood_filter_nodelet.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
// -*- mode: c++ -*- | ||
/********************************************************************* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Copyright (c) 2017, JSK Lab | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/o2r other materials provided | ||
* with the distribution. | ||
* * Neither the name of the JSK Lab nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*********************************************************************/ | ||
|
||
#include <algorithm> | ||
#include <jsk_pcl_ros_utils/polygon_array_likelihood_filter.h> | ||
|
||
namespace jsk_pcl_ros_utils | ||
{ | ||
void PolygonArrayLikelihoodFilter::onInit() | ||
{ | ||
DiagnosticNodelet::onInit(); | ||
|
||
srv_ = boost::make_shared<dynamic_reconfigure::Server<Config> >(*pnh_); | ||
dynamic_reconfigure::Server<Config>::CallbackType f = | ||
boost::bind(&PolygonArrayLikelihoodFilter::configCallback, this, _1, _2); | ||
srv_->setCallback(f); | ||
|
||
pub_polygons_ = advertise<jsk_recognition_msgs::PolygonArray>( | ||
*pnh_, "output_polygons", 1); | ||
|
||
pnh_->param<bool>("use_coefficients", use_coefficients_, true); | ||
if (use_coefficients_) { | ||
pub_coefficients_ = advertise<jsk_recognition_msgs::ModelCoefficientsArray>( | ||
*pnh_, "output_coefficients", 1); | ||
} | ||
|
||
onInitPostProcess(); | ||
} | ||
|
||
void PolygonArrayLikelihoodFilter::subscribe() | ||
{ | ||
if (use_coefficients_) { | ||
sync_ = boost::make_shared<message_filters::Synchronizer<SyncPolicy> >(queue_size_); | ||
sub_polygons_.subscribe(*pnh_, "input_polygons", 1); | ||
sub_coefficients_.subscribe(*pnh_, "input_coefficients", 1); | ||
sync_->connectInput(sub_polygons_, sub_coefficients_); | ||
sync_->registerCallback(boost::bind( | ||
&PolygonArrayLikelihoodFilter::filter, | ||
this, _1, _2)); | ||
} else { | ||
sub_polygons_alone_ = pnh_->subscribe( | ||
"input_polygons", 1, &PolygonArrayLikelihoodFilter::filter, this); | ||
} | ||
} | ||
|
||
void PolygonArrayLikelihoodFilter::unsubscribe() | ||
{ | ||
if (use_coefficients_) { | ||
sub_polygons_.unsubscribe(); | ||
sub_coefficients_.unsubscribe(); | ||
} else { | ||
sub_polygons_alone_.shutdown(); | ||
} | ||
} | ||
|
||
void PolygonArrayLikelihoodFilter::configCallback(Config& config, uint32_t level) | ||
{ | ||
boost::mutex::scoped_lock lock(mutex_); | ||
threshold_ = config.threshold; | ||
negative_ = config.negative; | ||
if (queue_size_ != config.queue_size) { | ||
queue_size_ = config.queue_size; | ||
unsubscribe(); | ||
subscribe(); | ||
} | ||
} | ||
|
||
void PolygonArrayLikelihoodFilter::filter( | ||
const jsk_recognition_msgs::PolygonArray::ConstPtr& polygons) | ||
{ | ||
jsk_recognition_msgs::ModelCoefficientsArray::Ptr dummy; | ||
dummy.reset(); | ||
filter(polygons, dummy); | ||
} | ||
|
||
void PolygonArrayLikelihoodFilter::filter( | ||
const jsk_recognition_msgs::PolygonArray::ConstPtr& polygons, | ||
const jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr& coefficients) | ||
{ | ||
boost::mutex::scoped_lock lock(mutex_); | ||
if (polygons->polygons.size() != polygons->likelihood.size()) { | ||
ROS_ERROR_STREAM_THROTTLE(1.0, "The size of polygons " << polygons->polygons.size() | ||
<< " must be same as the size of likelihood " | ||
<< polygons->likelihood.size()); | ||
return; | ||
} | ||
if (use_coefficients_ && | ||
polygons->polygons.size() != coefficients->coefficients.size()) { | ||
ROS_ERROR_STREAM_THROTTLE(1.0, "The size of polygons " << polygons->polygons.size() | ||
<< "must be same as the size of coeeficients " | ||
<< coefficients->coefficients.size()); | ||
return; | ||
} | ||
vital_checker_->poke(); | ||
|
||
bool use_labels = polygons->polygons.size() == polygons->labels.size(); | ||
|
||
std::vector<std::pair<double, int> > lookup_table; | ||
lookup_table.resize(polygons->polygons.size()); | ||
for (int i = 0; i < polygons->polygons.size(); ++i) { | ||
lookup_table[i] = std::pair<double, int>(polygons->likelihood[i], i); | ||
} | ||
std::sort(lookup_table.rbegin(), lookup_table.rend()); | ||
|
||
jsk_recognition_msgs::PolygonArray ret_polygons; | ||
jsk_recognition_msgs::ModelCoefficientsArray ret_coefficients; | ||
|
||
for (int i = 0; i < lookup_table.size(); ++i) { | ||
double likelihood = lookup_table[i].first; | ||
int idx = lookup_table[i].second; | ||
if ((!negative_ && likelihood >= threshold_) || | ||
(negative_ && likelihood < threshold_)) { | ||
ret_polygons.polygons.push_back(polygons->polygons[idx]); | ||
ret_polygons.likelihood.push_back(polygons->likelihood[idx]); | ||
if (use_labels) { | ||
ret_polygons.labels.push_back(polygons->labels[idx]); | ||
} | ||
if (use_coefficients_) { | ||
ret_coefficients.coefficients.push_back(coefficients->coefficients[idx]); | ||
} | ||
} | ||
} | ||
|
||
ret_polygons.header = polygons->header; | ||
pub_polygons_.publish(ret_polygons); | ||
if (use_coefficients_) { | ||
ret_coefficients.header = coefficients->header; | ||
pub_coefficients_.publish(ret_coefficients); | ||
} | ||
} | ||
} | ||
|
||
#include <pluginlib/class_list_macros.h> | ||
PLUGINLIB_EXPORT_CLASS (jsk_pcl_ros_utils::PolygonArrayLikelihoodFilter, nodelet::Nodelet); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<launch> | ||
<include file="$(find jsk_pcl_ros_utils)/sample/sample_polygon_array_likelihood_filter.launch"/> | ||
<test test-name="test_polygon_array_likelihood_filter" | ||
pkg="jsk_pcl_ros_utils" type="test_polygon_array_likelihood_filter.py" /> | ||
</launch> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sub_polygons_.registerCallback(&PolygonArrayLIkelihoodFilter::fileter, this);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wkentaro Why this is not allowed?
sub_polygons_alone
is just aros::Suscriber
not amessage_filters::Subscriber
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean just it seems better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wkentaro
Sorry, I didn't know about that. What is difference between two calls? Is there any performance improvement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is the necessity of definition of
sub_polygons_alone_
, and with my method, you don't need to define it, leading less number of member varaibles.I'm not sure about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is not usual way of message_filers, I think...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a stereotype:
http://wiki.ros.org/message_filters#Example_.28C.2B-.2B-.29
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this method by my own necessity in https://github.com/jsk-ros-pkg/jsk_recognition/pull/2062/files#diff-0305e61af9efa1e83947d88c19e4ec73R81.