81 const memoryx::ObjectClassNameList& objectClassNames,
82 const Ice::Current&
c)
86 serviceTopic->requestService(
"MaskRCNNImageProcessor", 1000);
87 std::scoped_lock lock2(pointCloudMutex);
88 memoryx::ObjectLocalizationResultList resultList;
89 pcl::PointCloud<PointL>::Ptr cloudPtr(
new pcl::PointCloud<PointL>());
90 pcl::PointCloud<PointL>::Ptr resultCloud(
new pcl::PointCloud<PointL>());
95 ARMARX_WARNING <<
"Timeout or error while waiting for point cloud data"
106 std::map<std::string, int> nameIdMap;
107 std::map<int, std::string> idNameMap;
108 for (
auto entry : mapping)
117 cloudPtr->is_dense =
false;
118 std::vector<int>
index;
119 ARMARX_INFO <<
"Cloud size with NaN: " << cloudPtr->size();
120 pcl::removeNaNFromPointCloud(*cloudPtr, *cloudPtr,
index);
121 ARMARX_INFO <<
"Cloud size without NaN: " << cloudPtr->size();
124 std::map<uint32_t, pcl::PointIndices> labeledPointMap;
126 std::map<std::string, Eigen::Vector3f> positionMap;
129 pcl::search::KdTree<PointL>::Ptr tree(
new pcl::search::KdTree<PointL>);
130 tree->setInputCloud(cloudPtr);
132 pcl::EuclideanClusterExtraction<PointL> ec;
133 ec.setClusterTolerance(20);
134 ec.setMinClusterSize(100);
135 ec.setMaxClusterSize(25000);
136 ec.setInputCloud(cloudPtr);
137 ec.setSearchMethod(tree);
140 for (
auto& it : labeledPointMap)
142 auto label = it.first;
143 if (label == backgroundLabel)
149 if (!idNameMap.count(label))
154 auto labelName = idNameMap.at(label);
156 if (std::find(objectClassNames.begin(), objectClassNames.end(), labelName) ==
157 objectClassNames.end())
163 auto labelIndices = it.second.indices;
165 pcl::IndicesPtr i(
new std::vector<int>(it.second.indices));
167 std::vector<pcl::PointIndices> cluster_indices;
168 ec.extract(cluster_indices);
169 ARMARX_VERBOSE <<
"Found " << cluster_indices.size() <<
" clusters";
171 if (!cluster_indices.size())
178 size_t maxClusterSize = 0;
179 size_t indexBiggestCluster = 0;
180 for (
auto& cluster : cluster_indices)
183 if (cluster.indices.size() > maxClusterSize)
185 indexBiggestCluster = j;
186 maxClusterSize = cluster.indices.size();
190 labelIndices = cluster_indices.at(indexBiggestCluster).indices;
193 pcl::PointCloud<PointL>::Ptr segment(
new pcl::PointCloud<PointL>());
194 copyPointCloud(*cloudPtr, labelIndices, *segment);
195 *resultCloud += *segment;
198 Eigen::Vector4f centroid;
199 pcl::compute3DCentroid(*segment, centroid);
200 positionMap[labelName] = centroid.head<3>();
204 for (
auto pair : positionMap)
206 auto name = pair.first;
207 Eigen::Vector3f position = pair.second;
209 memoryx::ObjectLocalizationResult result;
210 result.position =
new FramedPosition(position, sourceNodeName, agentName);
212 Eigen::Matrix3f
id = Eigen::Matrix3f::Identity();
214 result.objectClassName = name;
215 result.recognitionCertainty = 0.6;
218 Eigen::Vector3f cov(500, 500, 500);
220 Eigen::Vector3f::Zero(), cov.asDiagonal());
221 resultList.push_back(result);