37 #include <boost/assign.hpp> 39 #include <opencv2/opencv.hpp> 47 DiagnosticNodelet::onInit();
48 pub_ = advertise<sensor_msgs::Image>(*
pnh_,
"output", 1);
65 const sensor_msgs::Image::ConstPtr& mask_msg)
70 cv::Mat mask = cv_ptr->image;
73 std::vector<std::vector<cv::Point> > contours;
74 cv::findContours(mask, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
76 cv::Mat object_mask = cv::Mat::zeros(mask_msg->height, mask_msg->width, CV_8UC1);
78 if (contours.size() != 0) {
80 boost::tuple<int, double> max_area;
81 for (
size_t i = 0; i < contours.size(); i++) {
82 double area = cv::contourArea(contours[i]);
83 if (area > max_area.get<1>()) {
84 max_area = boost::make_tuple<int, double>(i, area);
87 cv::drawContours(object_mask, contours, max_area.get<0>(), cv::Scalar(255), CV_FILLED);
virtual void convert(const sensor_msgs::Image::ConstPtr &mask_msg)
void publish(const boost::shared_ptr< M > &message) const
virtual void unsubscribe()
std::vector< std::string > V_string
PLUGINLIB_EXPORT_CLASS(jsk_perception::BoundingObjectMaskImage, nodelet::Nodelet)
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
sensor_msgs::ImagePtr toImageMsg() const