20 #include <boost/filesystem/operations.hpp> 23 #include <opencv2/opencv.hpp> 25 #include <sensor_msgs/RegionOfInterest.h> 26 #include <object_msgs/Objects.h> 27 #include <object_msgs/ObjectsInBoxes.h> 40 : ncs_manager_handle_(nullptr)
43 , max_device_number_(255)
44 , start_device_index_(0)
45 , log_level_(
Device::Errors)
47 , graph_file_path_(
"")
48 , category_file_path_(
"")
49 , network_dimension_(0)
68 ROS_WARN(
"param max_device_number not set, use default");
74 throw std::exception();
81 ROS_WARN(
"param start_device_index not set, use default");
87 throw std::exception();
94 ROS_WARN(
"param log_level not set, use default");
97 if (log_level_ < Device::Nothing || log_level_ > Device::Verbose)
100 throw std::exception();
107 ROS_WARN(
"param graph_file_path not set, use default");
113 throw std::exception();
120 ROS_WARN(
"param category_file_path not set, use default");
126 throw std::exception();
133 ROS_WARN(
"param cnn_type not set, use default");
142 throw std::exception();
149 ROS_WARN(
"param network_dimension not set, use default");
155 throw std::exception();
160 for (
int i = 0; i < 3; i++)
162 std::ostringstream oss;
163 oss <<
"channel" << (i + 1) <<
"_mean";
164 std::string mean_param_name = oss.str();
168 ROS_WARN_STREAM(
"param " << mean_param_name <<
"not set, use default");
171 mean_.push_back(mean_val);
176 ROS_WARN(
"param top_n not set, use default");
182 throw std::exception();
189 ROS_WARN(
"param scale not set, use default");
194 throw std::exception();
208 std::shared_ptr<ImageTransport> it = std::make_shared<ImageTransport>(
nh_);
237 ncs_manager_handle_->classifyStream(camera_data, classification_result_callback, image_msg);
260 object_msgs::Objects objs;
262 for (
auto item : result->items)
264 object_msgs::Object obj;
265 obj.object_name = item.category;
266 obj.probability = item.probability;
267 objs.objects_vector.push_back(obj);
270 objs.header = header;
271 objs.inference_time_ms = result->time_taken;
277 object_msgs::ObjectsInBoxes objs_in_boxes;
279 for (
auto item : result->items_in_boxes)
281 object_msgs::ObjectInBox obj;
282 obj.object.object_name = item.item.category;
283 obj.object.probability = item.item.probability;
284 obj.roi.x_offset = item.bbox.x;
285 obj.roi.y_offset = item.bbox.y;
286 obj.roi.width = item.bbox.width;
287 obj.roi.height = item.bbox.height;
288 objs_in_boxes.objects_vector.push_back(obj);
291 objs_in_boxes.header = header;
292 objs_in_boxes.inference_time_ms = result->time_taken;
303 impl_.reset(
new NCSImpl(nh, pnh));
312 ROS_ERROR(
"exception caught while starting NCSNodelet");
std::vector< float > mean_
std::shared_ptr< DetectionResult > DetectionResultPtr
void publish(const boost::shared_ptr< M > &message) const
PLUGINLIB_EXPORT_CLASS(movidius_ncs_stream::NCSNodelet, nodelet::Nodelet)
boost::function< void(movidius_ncs_lib::DetectionResultPtr result, std_msgs::Header header)> FUNP_D
const char * what() const noexcept
NCSImpl(ros::NodeHandle &nh, ros::NodeHandle &pnh)
void cbGetClassificationResult(movidius_ncs_lib::ClassificationResultPtr result, std_msgs::Header header)
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::string graph_file_path_
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
void cbGetDetectionResult(movidius_ncs_lib::DetectionResultPtr result, std_msgs::Header header)
boost::function< void(movidius_ncs_lib::ClassificationResultPtr result, std_msgs::Header header)> FUNP_C
std::shared_ptr< ClassificationResult > ClassificationResultPtr
uint32_t getNumSubscribers() const
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
ROSCPP_DECL void shutdown()
void cbClassify(const sensor_msgs::ImageConstPtr &image)
void cbDetect(const sensor_msgs::ImageConstPtr &image)
#define ROS_ERROR_STREAM(args)
image_transport::Subscriber sub_
std::string category_file_path_
std::shared_ptr< movidius_ncs_lib::NCSManager > ncs_manager_handle_