18 #include <message_filters/subscriber.h> 19 #include <message_filters/time_synchronizer.h> 20 #include <opencv2/opencv.hpp> 22 #include <object_msgs/Object.h> 23 #include <object_msgs/Objects.h> 25 #define LINESPACING 50 30 static boost::posix_time::ptime duration_start = boost::posix_time::microsec_clock::local_time();
31 static int frame_cnt = 0;
35 boost::posix_time::ptime current = boost::posix_time::microsec_clock::local_time();
36 boost::posix_time::time_duration msdiff = current - duration_start;
38 if (msdiff.total_milliseconds() > 1000)
42 duration_start = current;
48 void syncCb(
const sensor_msgs::ImageConstPtr& img,
const object_msgs::Objects::ConstPtr& objs)
53 for (
auto obj : objs->objects_vector)
56 ss << obj.object_name <<
": " << obj.probability * 100 <<
'%';
58 cv::Scalar(0, 255, 0));
66 cv::Scalar(0, 255, 0));
67 cv::imshow(
"image_viewer", cvImage);
69 int key = cv::waitKey(5);
70 if (key == 13 || key == 27 || key == 32 || key == 113)
76 int main(
int argc,
char** argv)
78 ros::init(argc, argv,
"movidius_ncs_example_stream");
81 message_filters::Subscriber<sensor_msgs::Image> camSub(nh,
"/camera/color/image_raw", 1);
82 message_filters::Subscriber<object_msgs::Objects> objSub(nh,
"/movidius_ncs_nodelet/classified_objects", 1);
84 message_filters::TimeSynchronizer<sensor_msgs::Image, object_msgs::Objects> sync(camSub, objSub, 60);
85 sync.registerCallback(boost::bind(&
syncCb, _1, _2));
CvImageConstPtr toCvShare(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
void syncCb(const sensor_msgs::ImageConstPtr &img, const object_msgs::Objects::ConstPtr &objs)
ROSCPP_DECL void shutdown()