feature0d_view.cpp
Go to the documentation of this file.
00001 // Copyright (C) 2008-2009 Rosen Diankov
00002 // 
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //     http://www.apache.org/licenses/LICENSE-2.0
00007 // 
00008 // Unless required by applicable law or agreed to in writing, software
00009 // distributed under the License is distributed on an "AS IS" BASIS,
00010 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00011 // See the License for the specific language governing permissions and
00012 // limitations under the License.
00013 #include "posedetection_msgs/feature0d_view.h"
00014 #include "posedetection_msgs/feature0d_to_image.h"
00015 #include <ros/node_handle.h>
00016 #include <ros/master.h>
00017 #include <posedetection_msgs/ImageFeature0D.h>
00018 
00019 #include <opencv2/highgui/highgui.hpp>
00020 #include <boost/shared_ptr.hpp>
00021 
00022 #include <cv_bridge/cv_bridge.h>
00023 
00024 namespace posedetection_msgs
00025 {
00026     Feature0DView::Feature0DView()
00027     { 
00028         std::string topic = _node.resolveName("ImageFeature0D");
00029         ros::NodeHandle local_nh("~");
00030         local_nh.param("window_name", _window_name, topic);
00031         bool autosize;
00032         local_nh.param("autosize", autosize, false);
00033 
00034         _sub = _node.subscribe("ImageFeature0D",1,&Feature0DView::image_cb,this);
00035         cvNamedWindow(_window_name.c_str(), autosize ? CV_WINDOW_AUTOSIZE : 0);
00036         cvStartWindowThread();
00037     }
00038     Feature0DView::~Feature0DView() {}
00039 
00040     void Feature0DView::image_cb(const posedetection_msgs::ImageFeature0DConstPtr& msg_ptr)
00041     {
00042         cv_bridge::CvImagePtr cv_ptr;
00043         try {
00044             cv_ptr = cv_bridge::toCvCopy(msg_ptr->image, "bgr8");
00045             cv::Mat image = draw_features(cv_ptr->image,
00046                                           msg_ptr->features.positions,
00047                                           msg_ptr->features.scales,
00048                                           msg_ptr->features.orientations);
00049             cv::imshow(_window_name.c_str(), image);
00050         }
00051         catch (cv_bridge::Exception error) {
00052             ROS_WARN("bad frame");
00053             return;
00054         }
00055     }
00056 };
00057 
00058 int main(int argc, char **argv)
00059 {
00060     ros::init(argc,argv,"feature0d_view");
00061     if( !ros::master::check() )
00062         return 1;
00063     
00064     boost::shared_ptr<posedetection_msgs::Feature0DView> node(new posedetection_msgs::Feature0DView());
00065     ros::spin();
00066     node.reset();
00067     return 0;
00068 }


posedetection_msgs
Author(s): Rosen Diankov
autogenerated on Sat Jun 8 2019 19:19:23