blobs_2_3d.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include "sensor_msgs/PointCloud2.h"
00003 #include <pcl_ros/point_cloud.h>
00004 #include <pcl/point_types.h>
00005 #include <cmvision/Blobs.h>
00006 #include <cmvision/Blob.h>
00007 #include <boost/foreach.hpp>
00008 #include <cv_bridge/cv_bridge.h>
00009 
00010 bool g_cloud_ready = false;
00011 bool g_blobs_ready = false;
00012 std::string g_cloud_frame;
00013 typedef pcl::PointCloud<pcl::PointXYZRGB> PointCloud;
00014 PointCloud depth;
00015 cmvision::Blobs blobs;
00016 
00017 cv_bridge::CvImagePtr cv_ptr;
00018 
00019 void imageCallback(const sensor_msgs::ImageConstPtr& msg) {
00020         //pcl::fromROSMsg(*msg, cloud);
00021         
00022         g_cloud_frame = msg->header.frame_id;
00023         g_cloud_ready = true;
00024 }
00025 
00026 void blobCallback(const cmvision::Blobs::ConstPtr& msg) {
00027         blobs = *msg;
00028         g_blobs_ready = true;
00029 }
00030 
00031 int main(int argc, char* argv[])
00032 {
00033         ros::init(argc, argv, "blobs_2_3d");
00034         ros::NodeHandle nh;
00035         
00036         image_transport::ImageTransport it(nh);
00037         //ros::Subscriber cloud_sub = nh.subscribe<sensor_msgs::PointCloud2>("cloud", 1, cloudCallback);
00038         image_transport::Subscriber depth_sub = it.subscribe("image", 1, depthCallback);
00039         ros::Subscriber blob_sub  = nh.subscribe<cmvision::Blobs>("blobs", 1, blobCallback);
00040         
00041         ros::Publisher cloud_pub = nh.advertise<PointCloud>("blob_cloud", 1);
00042                 
00043         ros::Rate rate(10);     
00044         while(ros::ok()) {
00045                 PointCloud::Ptr out (new PointCloud);
00046                 out->header.stamp = ros::Time::now();
00047                 out->header.frame_id = g_cloud_frame;
00048                 ros::spinOnce();
00049                 BOOST_FOREACH(cmvision::Blob blob, blobs.blobs) {
00050                         out->points.push_back(cloud.at(blob.x, blob.y));
00051                 }
00052                 cloud_pub.publish(out);
00053                 rate.sleep();
00054         }       
00055         return 0;
00056 }


blob3d
Author(s): robotics
autogenerated on Mon Oct 6 2014 10:21:51