33 #define SAME_REF_AND_RECOG_RESULT_CONFIDENCE_THRESH 0.01 37 Recognizer::Recognizer(
const std::string& dbfilename,
double bin_size,
double maxProjectionAngleDeviation,
bool enabledSelfVoteCheck,
int raterType) :
38 bin_size(bin_size), maxProjectionAngleDeviation(maxProjectionAngleDeviation), enabledSelfVoteCheck(enabledSelfVoteCheck), mRaterType(raterType)
48 const double filterThreshold,
const int resultsPerPattern,
const std::string targetPatternName) {
54 TreeHeightToPatternName::reverse_iterator treeHeightIt;
79 std::map<ObjectPtr, std::vector<VotedPosePtr> >::iterator cacheIt =
votingCache.find(
object);
81 std::vector<VotedPosePtr> votedPoses = (*cacheIt).second;
86 vmit =
patternToVotedPoses.insert(std::make_pair(patternName, std::vector<VotedPosePtr>())).first;
88 (*vmit).second.push_back(v);
94 std::set<std::string> types;
95 if (object->type ==
"")
102 types.insert(object->type);
106 for (
const std::string& objectType : types)
113 if (object->observedId ==
"" || object->observedId == vote->observedId)
127 std::map<ObjectPtr, std::vector<VotedPosePtr> >::iterator cacheIt =
votingCache.find(
object);
129 cacheIt =
votingCache.insert(std::make_pair(
object, std::vector<VotedPosePtr>())).first;
132 (*cacheIt).second.push_back(v);
170 vsres->matchingObjects, vsres->confidence,
171 vsres->summarizedVotes));
177 if(this->
ismResults[resIdx]->confidence >= res->confidence)
192 refObj->confidence = vsres->confidence;
194 double weightSum = 0;
195 for (
ObjectPtr& obj : vsres->matchingObjects->objects)
197 weightSum += obj->weight;
199 refObj->weight = weightSum;
204 if (setObj->confidence < refObj->confidence || setObj->weight
221 for (
size_t i = 0; i < this->
ismResults.size(); i++)
233 for (
size_t i = 0; i < this->
inputSet->objects.size(); i++) {
235 if (setObj->type == o->type && setObj->observedId == o->observedId
253 typedef std::pair<std::string, std::vector<VoteSpecifierPtr> > mapItemType;
254 std::set<std::string> patternNames;
257 patternNames.insert(vote->patternName);
272 std::map<std::string, std::set<std::string> > patternToSubpatterns;
274 std::vector<std::string> topLevelPatterns;
277 typedef std::pair<std::string, std::vector<VoteSpecifierPtr> > mapItemType;
281 std::map<std::string, std::set<std::string> >::iterator patternIt;
282 patternIt = patternToSubpatterns.find(vote->patternName);
285 if(patternIt != patternToSubpatterns.end()){
287 if(vote->objectType.find(
"_sub") == std::string::npos)
290 patternIt->second.insert(vote->objectType);
294 std::set<std::string> newSubpatterns;
296 if(vote->objectType.find(
"_sub") != std::string::npos)
297 newSubpatterns.insert(vote->objectType);
298 patternToSubpatterns.insert(std::pair<std::string, std::set<std::string> >(vote->patternName, newSubpatterns));
305 for(
auto& valuePair : patternToSubpatterns)
306 if (valuePair.first.find(
"_sub") == std::string::npos)
307 topLevelPatterns.push_back(valuePair.first);
310 std::list<std::pair<std::string, unsigned int> > breadthFirstPatternQueue;
313 for(std::string currentTopLevelPattern : topLevelPatterns)
314 breadthFirstPatternQueue.push_back(std::pair<std::string, unsigned int>(currentTopLevelPattern, 0));
317 while(breadthFirstPatternQueue.size()) {
320 std::pair<std::string, unsigned int> patternAtHeight = breadthFirstPatternQueue.front();
322 breadthFirstPatternQueue.pop_front();
324 TreeHeightToPatternName::iterator heightMappingIt;
330 heightMappingIt->second.insert(patternAtHeight.first);
334 std::set<std::string> newPattern;
335 newPattern.insert(patternAtHeight.first);
336 patternPerTreeHeight.insert(std::pair<
unsigned int,std::set<std::string> >(patternAtHeight.second, newPattern));
341 std::map<std::string, std::set<std::string> >::iterator currentSubPatterns;
342 currentSubPatterns = patternToSubpatterns.find(patternAtHeight.first);
344 for(std::string subPattern : currentSubPatterns->second){
347 breadthFirstPatternQueue.push_back(std::pair<std::string, unsigned int>(subPattern, patternAtHeight.second+1));
356 const double filterThreshold,
const int resultsPerPattern,
const std::string targetPatternName) {
357 std::map<std::string, std::vector<RecognitionResultPtr> > patternNameToResults;
360 std::vector<RecognitionResultPtr> topLevelResults;
362 if (res->patternName.find(
"_sub") == std::string::npos) {
363 if(targetPatternName.empty() || targetPatternName == res->patternName)
365 topLevelResults.push_back(res);
369 std::map<std::string, std::vector<RecognitionResultPtr> >::iterator it = patternNameToResults.find(res->patternName);
370 if (it == patternNameToResults.end())
372 it = patternNameToResults.insert(std::make_pair(res->patternName, std::vector<RecognitionResultPtr>())).first;
374 (*it).second.push_back(res);
378 std::map<std::string, std::vector<RecognitionResultPtr> > patternNameToTopLevelResults;
380 std::map<std::string, std::vector<RecognitionResultPtr> >::iterator it = patternNameToTopLevelResults.find(res->patternName);
381 if (it == patternNameToTopLevelResults.end()) {
382 std::vector<RecognitionResultPtr> p;
384 patternNameToTopLevelResults.insert(std::make_pair(res->patternName, p));
386 (*it).second.push_back(res);
389 std::vector<RecognitionResultPtr> ret;
392 for (
const std::pair<std::string, std::vector<RecognitionResultPtr> >& patternPair : patternNameToTopLevelResults) {
393 std::vector<RecognitionResultPtr> rlist = patternPair.second;
396 return o1->confidence > o2->confidence;
399 for (
size_t i = 0; i < rlist.size() && (resultsPerPattern < 0 || (int)i < resultsPerPattern); i++) {
400 if (rlist[i]->confidence >= filterThreshold) {
412 return o1->confidence > o2->confidence;
420 std::map<std::string, std::vector<RecognitionResultPtr> > patternNameToResults) {
421 std::vector<RecognitionResultPtr> ret;
422 for (
ObjectPtr& obj : result->recognizedSet->objects) {
423 std::map<std::string, std::vector<RecognitionResultPtr> >::iterator it = patternNameToResults.find(obj->type);
424 if (it == patternNameToResults.end()) {
428 PosePtr originalPose = originalResult->referencePose;
429 PosePtr currentPose = obj->pose;
433 ret.push_back(originalResult);
PatternNameToVotedPoses patternToVotedPoses
void arrangePatternsAccordingToTreeHeight()
PatternNameToPatternMap patternDefinitions
static std::vector< RecognitionResultPtr > assembleIsmTrees(const std::vector< RecognitionResultPtr > &ismResults, const double filterThreshold, const int resultsPerPattern, const std::string targetPatternName)
TableHelperPtr tableHelper
boost::shared_ptr< Point > PointPtr
static PointPtr applyQuatAndRadiusToPose(const PosePtr &pose, const QuaternionPtr &quat, double radius)
bool enabledSelfVoteCheck
static std::vector< RecognitionResultPtr > getSubPatternsForResult(RecognitionResultPtr result, std::map< std::string, std::vector< RecognitionResultPtr > > patternNameToResults)
PatternNameAndVotingSpaceTuple votingSpaceBuffer
void calculateVotedPosesForAllObjects()
boost::shared_ptr< VotingResult > VotingResultPtr
boost::shared_ptr< TableHelper > TableHelperPtr
std::string patternForVotingSpaceViz
ObjectTypeToVoteMap voteSpecifiersPerObject
std::set< std::string > objectTypes
boost::shared_ptr< VotedPose > VotedPosePtr
std::map< ObjectPtr, std::vector< VotedPosePtr > > votingCache
PosePtr calculatePoseFromVote(const PosePtr &pose, const VoteSpecifierPtr &vote) const
boost::shared_ptr< Pattern > PatternPtr
static bool poseEqual(const PosePtr &p1, const PosePtr &p2)
boost::shared_ptr< VoteSpecifier > VoteSpecifierPtr
std::vector< RecognitionResultPtr > ismResults
void getPatternDefinitions()
boost::shared_ptr< ObjectSet > ObjectSetPtr
int objectAlreadyInSet(const ObjectPtr &o)
boost::shared_ptr< RecognitionResult > RecognitionResultPtr
int resultAlreadyExisting(const RecognitionResultPtr &res)
#define SAME_REF_AND_RECOG_RESULT_CONFIDENCE_THRESH
boost::shared_ptr< Pose > PosePtr
void fillAndEvalVotingSpaceAtTreeHeight(unsigned int treeHeight)
double maxProjectionAngleDeviation
std::vector< VotingResultPtr > VotingResultPtrs
const std::vector< RecognitionResultPtr > recognizePattern(const ObjectSetPtr &objectSet, const double filterThreshold=0.0, const int resultsPerPattern=-1, const std::string targetPatternName="")
static PosePtr getReferencePose(const PosePtr &source, const PointPtr &refPoint, const QuaternionPtr &objectToRefPoseQuat)
boost::shared_ptr< VotingSpace > VotingSpacePtr
this namespace contains all generally usable classes.
TreeHeightToPatternName patternPerTreeHeight
boost::shared_ptr< Object > ObjectPtr
Recognizer(const std::string &dbfilename, double bin_size, double maxProjectionAngleDeviation, bool enabledSelfVoteCheck, int raterType=0)