41 #if ( CV_MAJOR_VERSION >= 4)
42 #include <opencv2/imgproc/imgproc_c.h>
52 ConnectionBasedNodelet::onInit();
54 srv_ = boost::make_shared<dynamic_reconfigure::Server<Config> >(*pnh_);
55 typename dynamic_reconfigure::Server<Config>::CallbackType
f =
59 pub_image_ = advertise<sensor_msgs::Image>(*pnh_,
"output", 1);
88 async_ = boost::make_shared<message_filters::Synchronizer<AsyncPolicy> >(
queue_size_);
95 sync_ = boost::make_shared<message_filters::Synchronizer<SyncPolicy> >(
queue_size_);
116 bool need_resubscribe =
false;
120 need_resubscribe =
true;
137 #if ROS_VERSION_MINIMUM(1, 11, 4)
139 if (need_resubscribe && isSubscribed()) {
147 const jsk_recognition_msgs::RectArray::ConstPtr& rects)
149 jsk_recognition_msgs::ClassificationResult classes;
150 classes.header = rects->header;
152 boost::make_shared<jsk_recognition_msgs::ClassificationResult>(classes));
156 const sensor_msgs::Image::ConstPtr& image,
157 const jsk_recognition_msgs::RectArray::ConstPtr& rects,
158 const jsk_recognition_msgs::ClassificationResult::ConstPtr& classes)
171 cv::resize(cv_img->image, img, cv::Size(),
176 use_classification_result_ ? classes->target_names.size() : rects->rects.size();
178 for (
size_t i = 0;
i < rects->rects.size(); ++
i) {
186 std::ostringstream oss;
187 oss << classes->label_names[
i];
188 if (
show_proba_ && classes->label_proba.size() > i) {
189 oss << std::fixed << std::setprecision(2);
190 oss <<
" (" << classes->label_proba[
i] <<
")";
192 drawLabel(img, rects->rects[i], color, oss.str());
200 cv::Mat& img,
const jsk_recognition_msgs::Rect& orig_rect,
const cv::Scalar& color)
210 cv::Mat& img,
const jsk_recognition_msgs::Rect& rect,
211 const cv::Scalar& color,
const std::string& label)
214 cv::Size label_size = cv::getTextSize(label,
label_font_,
228 cv::putText(img, label,
233 cv::Scalar(text_color, text_color, text_color),
240 static const float colors[6][3] = { {1,0,1}, {0,0,1},{0,1,1},{0,1,0},{1,1,0},{1,0,0} };
241 float ratio = ((
float)(index * 123457 % label_num) / label_num) * 5;
242 int i = std::floor(
ratio);
243 int j = std::ceil(
ratio);
245 for (
int c = 0; c < 3; ++c)
246 color[c] = (
int)(((1-
ratio) * colors[i][c] +
ratio * colors[j][c]) * 255);