30 #include <find_object_2d/ObjectsStamped.h> 32 #include <opencv2/core/core.hpp> 33 #include <rtabmap_ros/UserData.h> 36 #include <visualization_msgs/MarkerArray.h> 59 if(msg->objects.data.size())
61 cv::Mat
data(msg->objects.data.size()/12, 9, CV_64FC1);
62 for(
unsigned int i=0; i<msg->objects.data.size(); i+=12)
65 int id = (int)msg->objects.data[i];
80 data.at<
double>(i, 0) =
double(
id);
91 rtabmap_ros::UserData dataMsg;
92 dataMsg.header.frame_id = msg->header.frame_id;
93 dataMsg.header.stamp = msg->header.stamp;
102 std::map<int, rtabmap::Signature> signatures;
103 std::map<int, rtabmap::Transform> poses;
104 std::multimap<int, rtabmap::Link> links;
109 for(std::map<int, rtabmap::Signature>::iterator iter=signatures.begin(); iter!=signatures.end(); ++iter)
111 int id = iter->first;
119 ROS_ASSERT(data.cols == 9 && data.type() == CV_64FC1);
120 ROS_INFO(
"Node %d has %d object(s)",
id, data.rows);
127 std::map<double, int> nodeStamps;
130 std::map<int, rtabmap::Transform>::const_iterator jter = poses.find(iter->second);
131 if(jter != poses.end())
133 nodeStamps.insert(*iter);
138 std::map<int, float> objectsAdded;
143 for(std::map<int, rtabmap::Transform>::iterator iter=poses.lower_bound(1); iter!=poses.end(); ++iter)
148 for(
int i=0; i<data.rows; ++i)
150 int objId = int(data.at<
double>(i,0));
151 double stamp = data.at<
double>(i,1);
154 std::map<double, int>::iterator previousNode = nodeStamps.lower_bound(stamp);
155 if(previousNode!=nodeStamps.end() && previousNode->first > stamp && previousNode != nodeStamps.begin())
159 std::map<double, int>::iterator nextNode = nodeStamps.upper_bound(stamp);
161 if(previousNode != nodeStamps.end() &&
162 nextNode != nodeStamps.end() &&
163 previousNode->second != nextNode->second &&
164 poses.find(previousNode->second)!=poses.end() && poses.find(nextNode->second)!=poses.end())
168 double stampA = previousNode->first;
169 double stampB = nextNode->first;
170 UASSERT(stamp>=stampA && stamp <=stampB);
172 double ratio = (stamp-stampA)/(stampB-stampA);
177 data.at<
double>(i,2), data.at<
double>(i,3), data.at<
double>(i,4),
178 data.at<
double>(i,5), data.at<
double>(i,6), data.at<
double>(i,7), data.at<
double>(i,8));
179 float distanceFromNode = objPose.
getNorm();
180 objPose = robotPose * objPose;
182 if(objectsAdded.find(objId) == objectsAdded.end())
184 visualization_msgs::Marker marker;
185 marker.header.frame_id = msg->header.frame_id;
186 marker.header.stamp = msg->header.stamp;
187 marker.ns =
"objects";
189 marker.action = visualization_msgs::Marker::ADD;
190 marker.pose.position.
x = objPose.x();
191 marker.pose.position.y = objPose.y();
192 marker.pose.position.z = objPose.z();
193 Eigen::Quaterniond
q = objPose.getQuaterniond();
194 marker.pose.orientation.x = q.x();
195 marker.pose.orientation.y = q.y();
196 marker.pose.orientation.z = q.z();
197 marker.pose.orientation.w = q.w();
198 marker.scale.x = 0.3;
199 marker.scale.y = 0.3;
200 marker.scale.z = 0.3;
201 marker.color.a = 0.8;
202 marker.color.r = 0.0;
203 marker.color.g = 1.0;
204 marker.color.b = 0.0;
207 marker.type = visualization_msgs::Marker::CUBE;
208 markers.markers.push_back(marker);
211 marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
214 marker.color.a = 1.0;
215 marker.pose.position.z += 0.3;
216 markers.markers.push_back(marker);
218 objectsAdded.insert(std::make_pair(objId, distanceFromNode));
223 if(distanceFromNode < objectsAdded.at(objId))
225 for(
unsigned int j=0; j<markers.markers.size(); ++j)
227 if(markers.markers[j].id == objId || markers.markers[j].id == -objId)
229 markers.markers[j].pose.position.x = objPose.x();
230 markers.markers[j].pose.position.y = objPose.y();
231 markers.markers[j].pose.position.z = objPose.z() + (markers.markers[j].id<0?0.3:0);
232 Eigen::Quaterniond
q = objPose.getQuaterniond();
233 markers.markers[j].pose.orientation.x = q.x();
234 markers.markers[j].pose.orientation.y = q.y();
235 markers.markers[j].pose.orientation.z = q.z();
236 markers.markers[j].pose.orientation.w = q.w();
239 objectsAdded.at(objId) = distanceFromNode;
246 if(!markers.markers.empty())
265 int main(
int argc,
char * argv[])
267 ros::init(argc, argv,
"save_objects_example");
cv::Mat RTABMAP_EXP uncompressData(const cv::Mat &bytes)
std::string uFormat(const char *fmt,...)
std::string objFramePrefix_
ros::Publisher pubMarkers_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Subscriber subsMapData_
std::map< double, int > nodeStamps_
#define UASSERT(condition)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void publish(const boost::shared_ptr< M > &message) const
void mapDataFromROS(const rtabmap_ros::MapData &msg, std::map< int, rtabmap::Transform > &poses, std::multimap< int, rtabmap::Link > &links, std::map< int, rtabmap::Signature > &signatures, rtabmap::Transform &mapToOdom)
int main(int argc, char *argv[])
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
SensorData & sensorData()
const cv::Mat & userDataCompressed() const
std::map< int, cv::Mat > nodeToObjects_
void userDataToROS(const cv::Mat &data, rtabmap_ros::UserData &dataMsg, bool compress)
tf::TransformListener tfListener_
ros::Subscriber subObjects_
void objectsDetectedCallback(const find_object_2d::ObjectsStampedConstPtr &msg)
void mapDataCallback(const rtabmap_ros::MapDataConstPtr &msg)