37 #include <boost/assign.hpp> 41 #include <opencv2/opencv.hpp> 42 #if ( CV_MAJOR_VERSION >= 4) 43 #include <opencv2/imgproc/imgproc_c.h> 51 DiagnosticNodelet::onInit();
70 const sensor_msgs::Image::ConstPtr& image_msg)
72 std::vector<std::vector<cv::Point> > contours;
73 std::vector<std::vector<cv::Point> > convex_contours(1);
74 std::vector<cv::Vec4i> hierarchy;
78 cv::findContours(input, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
79 cv::Mat drawing = cv::Mat::zeros(input.size(), CV_8UC3);
80 for(
int i = 0; i< contours.size(); i++ )
82 cv::Scalar color = cv::Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
83 cv::drawContours(drawing, contours, i, color, CV_FILLED, 8, hierarchy, 0, cv::Point());
90 std::vector<cv::Point> all_contours;
91 for (
size_t i = 0; i < contours.size(); i++) {
92 for (
size_t j = 0; j < contours[i].size(); j++) {
93 all_contours.push_back(contours[i][j]);
97 cv::convexHull(cv::Mat(all_contours), convex_contours[0]);
98 cv::Mat convex_image = cv::Mat::zeros(input.size(), CV_8UC1);
99 cv::drawContours(convex_image, convex_contours, 0, cv::Scalar(255), CV_FILLED);
void publish(const boost::shared_ptr< M > &message) const
ros::Publisher pub_debug_image_
virtual void segment(const sensor_msgs::Image::ConstPtr &image_msg)
std::vector< std::string > V_string
PLUGINLIB_EXPORT_CLASS(jsk_perception::ContourFinder, nodelet::Nodelet)
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
ros::Publisher pub_convex_image_
virtual void unsubscribe()
sensor_msgs::ImagePtr toImageMsg() const