33#include <boost/filesystem.hpp>
42#include <Math/Math3d.h>
62 featureCalculator.addFeature<
CHArea>();
63 featureCalculator.addFeature<
CHVolume>();
65 featureCalculator.addFeature<
BBVolume>();
66 featureCalculator.addFeature<
BBArea>();
81 classesSegmentPrx = memoryPrx->getObjectClassesSegment();
82 databasePrx = memoryPrx->getCommonStorage();
86 connected = databasePrx->isConnected();
90ObjectShapeClassification::refetchObjects()
93 boost::recursive_mutex::scoped_lock lock(mutexEntities);
94 EntityIdList ids = classesSegmentPrx->getAllEntityIds();
97 for (EntityIdList::const_iterator it = ids.begin(); it != ids.end(); ++it)
99 const EntityBasePtr entity = classesSegmentPrx->getEntityById(*it);
100 const ObjectClassPtr objClass = ObjectClassPtr::dynamicCast(entity);
105 dbObjects.push_back(objClass);
111ObjectShapeClassification::checkFeatures()
113 for (
auto optr : dbObjects)
129 std::string ivFile =
"";
134 fileManager->ensureFileInCache(obj->getAttribute(
ATTR_IV_FILE), ivFile,
false);
139 ARMARX_WARNING <<
"No IV file found for object" << obj->getName();
147 template <
typename Pair>
151 return a.second < b.second;
156ObjectShapeClassification::compareToDB(
Points& points)
158 std::vector<std::pair<std::string, Points>> objectsPoints;
161 for (
auto& obj : dbObjects)
163 auto points = getPointsFromIV(obj);
165 if (points.size() != 0)
167 objectsPoints.push_back(
TaggedPoints(obj->getName(), points));
173 auto newObjectFeatures = featureCalculator.getFeatures(points);
192 for (
const auto& feat : newObjectFeatures)
199 std::map<std::string, std::map<std::string, double>> objectDiffs;
200 std::map<std::string, double> maxDiffs;
205 for (
const auto& obj : objectsPoints)
208 auto features = featureCalculator.getFeatures(obj.second);
209 std::map<std::string, double> diffs;
212 for (
const auto& p : newObjectFeatures)
214 auto& feature = p.second;
215 double diff = feature->compare(*features[feature->name()]);
216 diffs[feature->name()] = diff;
219 double oldValue = maxDiffs[feature->name()];
220 maxDiffs[feature->name()] = (diff > oldValue) ? diff : oldValue;
223 objectDiffs[obj.first] = diffs;
226 std::map<std::string, double> objectDiffsTotal;
229 for (
const auto& obj : objectDiffs)
233 double totalDiff = std::accumulate(obj.second.begin(),
236 [&](
double prev,
const std::pair<std::string, double> p)
238 double diff = (p.second / maxDiffs[p.first]);
239 ARMARX_VERBOSE_S <<
"-- " << p.first <<
": " << diff;
240 return prev + (p.second / maxDiffs[p.first]);
242 objectDiffsTotal[obj.first] = totalDiff;
243 ARMARX_VERBOSE <<
"--+ Total score(" << obj.first <<
"): " << totalDiff <<
"\n";
248 *std::min_element(objectDiffsTotal.begin(), objectDiffsTotal.end(), by_second());
250 ARMARX_INFO <<
"Best match found: " << bestMatch.first <<
" with score of " << bestMatch.second;
256ObjectShapeClassification::matchToFoundPointCloud(
const Points& newPoints,
257 const Points& foundPointCloud)
276 for (
size_t i = 0; i < segmentedObjectPoints.size(); i++)
278 points.push_back(armarx::Vector3Ptr::dynamicCast(segmentedObjectPoints.at(i))->toEigen());
285 ARMARX_INFO <<
"Connected to DB, starting classification";
292 matchToFoundPointCloud(points, foundPointCloud.second);
296 return foundPointCloud.first;
300 ARMARX_WARNING <<
"No connection to DB. Unable to start classification";
303 return "ERROR: No similar object found";
const std::string ATTR_IV_FILE
const std::string ATTR_FEATURES
static std::vector< Eigen::Vector3f > fromFile(const std::string &fileName)
Property< PropertyType > getProperty(const std::string &name)
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
void SetScenePointcloud(const std::vector< Eigen::Vector3f > &aScenePoints)
void SetObjectPointcloud(const std::vector< Eigen::Vector3f > &aObjectPoints)
float SearchObject(Mat3d &mRotation, Vec3d &vTranslation, const float fBestDistanceUntilNow=FLT_MAX)
std::string FindSimilarKnownObject(const ::visionx::types::PointList &segmentedObjectPoints, const ::Ice::Current &)
void onInitComponent()
Pure virtual hook for the subclass.
void onConnectComponent()
Pure virtual hook for the subclass.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
VectorXD< 3, double > Vec3d
const LogSender::manipulator flush
IceInternal::Handle< ObjectClass > ObjectClassPtr
std::vector< Point > Points
std::pair< std::string, Points > TaggedPoints
bool operator()(const Pair &a, const Pair &b)