Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <vector>
00041 #include <boost/foreach.hpp>
00042
00043 #include <ecto/ecto.hpp>
00044 #include <opencv2/core/core.hpp>
00045
00046
00047 #include <sensor_msgs/Image.h>
00048 #include <object_recognition_msgs/RecognizedObjectArray.h>
00049 #include <pcl_conversions/pcl_conversions.h>
00050
00051 namespace object_recognition_clusters
00052 {
00055 struct PointCloudMsgAssembler {
00056 static void
00057 declare_params(ecto::tendrils& params) {}
00058
00059 static void
00060 declare_io(const ecto::tendrils& params, ecto::tendrils& inputs, ecto::tendrils& outputs) {
00061 inputs.declare(&PointCloudMsgAssembler::clusters3d_,
00062 "clusters3d", "The 3dpoints as a cv::Mat_<cv::Vec3f>").required(true);
00063 inputs.declare(&PointCloudMsgAssembler::image_message_,
00064 "image_message", "the image message to get the header").required(true);
00065
00066 outputs.declare(&PointCloudMsgAssembler::output_msg_, "msg", "Pointcloud ROS message");
00067 }
00068
00069 void
00070 configure(const ecto::tendrils& params, const ecto::tendrils& inputs, const ecto::tendrils& outputs) {
00071 }
00072
00073 int
00074 process(const ecto::tendrils& inputs, const ecto::tendrils& outputs) {
00075
00076 ros::Time time = ros::Time::now();
00077 object_recognition_msgs::RecognizedObjectArrayPtr msg(new object_recognition_msgs::RecognizedObjectArray());
00078
00079 std::string frame_id;
00080 if (*image_message_) {
00081 frame_id = (*image_message_)->header.frame_id;
00082 time = (*image_message_)->header.stamp;
00083 }
00084
00085
00086
00087
00088
00089 msg->header.stamp = time;
00090
00091 for (size_t i = 0; i < clusters3d_->size(); ++i){
00092
00093 std::vector<std::vector<cv::Vec3f> > &clusters = (*clusters3d_)[i];
00094 for (size_t j = 0; j < clusters.size(); j++){
00095
00096 object_recognition_msgs::RecognizedObject object;
00097
00098
00099 object.header.stamp = time;
00100
00101 pcl::PointCloud<pcl::PointXYZ> pcl_cloud;
00102 pcl_cloud.reserve(clusters[j].size());
00103 BOOST_FOREACH(const cv::Vec3f& point, clusters[j])
00104 {
00105 pcl_cloud.push_back(pcl::PointXYZ(point[0], point[1], point[2]));
00106 }
00107
00108 sensor_msgs::PointCloud2 cloud;
00109 pcl::toROSMsg(pcl_cloud, cloud);
00110 cloud.header.frame_id = frame_id;
00111 cloud.header.stamp = time;
00112
00113 object.point_clouds.push_back(cloud);
00114 msg->objects.push_back(object);
00115 }
00116 }
00117
00118 *output_msg_ = msg;
00119 return ecto::OK;
00120 }
00121 private:
00123 ecto::spore<sensor_msgs::ImageConstPtr> image_message_;
00125 ecto::spore<std::vector<std::vector<std::vector<cv::Vec3f> > > > clusters3d_;
00127 ecto::spore<object_recognition_msgs::RecognizedObjectArrayConstPtr> output_msg_;
00128 };
00129 }
00130
00131 ECTO_CELL(io_clusters, object_recognition_clusters::PointCloudMsgAssembler, "PointCloudMsgAssembler",
00132 "Given object ids and poses, fill the object recognition message.");