00001
00002
00003 #ifndef _OBJECT_IDENTIFIER_HPP
00004 #define _OBJECT_IDENTIFIER_HPP
00005
00006 #include "kernel/jafarException.hpp"
00007 #include "image/Image.hpp"
00008 #include "gfm/MatchingResult.hpp"
00009 #include "gfm/DetectionResult.hpp"
00010 #include "oracle/objectRecognizer.hpp"
00011 #include "oracle/objectLoader.hpp"
00012 #include <boost/tuple/tuple.hpp>
00013 #include <set>
00014 #include <string>
00015
00016 namespace jafar {
00017
00018 namespace oracle {
00019
00020 const double ORACLE_IDENTIFICATION_THRESHOLD = 0.8;
00025 typedef boost::tuple<std::string, oracle::ObjectLoader*, oracle::ObjectRecognizer*> Model;
00026 struct ltstr {
00027 bool operator()(const Model& m1,
00028 const Model& m2) const {
00029 return strcmp(m1.get<0>().c_str(), m2.get<0>().c_str()) < 0;
00030 }
00031 };
00033 typedef std::set<Model, ltstr> ModelsDatabase;
00035 typedef ModelsDatabase::iterator ModelIterator;
00037 typedef std::map<std::string, double> RecognitionResults;
00039 typedef RecognitionResults::iterator ResultIterator;
00041 void addModel(ModelsDatabase& _database,
00042 const std::string& _modelName,
00043 oracle::ObjectLoader* _loader,
00044 oracle::ObjectRecognizer* _recognizer);
00046 void addModel(ModelsDatabase& _database,
00047 const std::string& _modelName,
00048 oracle::ObjectLoader* _loader);
00049 ModelIterator getModel(ModelsDatabase& _database,
00050 const std::string& _modelName);
00051
00060 class ObjectIdentifier {
00061
00062
00063
00064
00065 typedef enum IdentificationResult{
00066 FAILED_IDENTIFICATION,
00067 CONFIRMED_IDENTIFICATION,
00068 AMBIGOUS_IDENTIFICATION
00069 };
00070
00071 private:
00073 gfm::DetectionResult m_detectedFeatures;
00075 gfm::MatchingResult m_matchedFeatures;
00077 ModelsDatabase m_database;
00079 RecognitionResults results;
00081 oracle::ObjectRecognizer* m_recognizer;
00083 image::Image request;
00085 IdentificationResult m_result;
00087 std::vector<std::string> plausibles;
00088 gfm::DetectionResult remaining;
00089
00090 public:
00092 ObjectIdentifier() {};
00096 ObjectIdentifier(const ModelsDatabase& database);
00098 ~ObjectIdentifier();
00100 void addModel(const std::string& _modelName,
00101 oracle::ObjectLoader* _loader);
00103 void addModel(const std::string& _modelName,
00104 oracle::ObjectLoader* _loader,
00105 oracle::ObjectRecognizer* _recognizer);
00107 oracle::ModelIterator getModel(const std::string& _modelName);
00109 void setQueryImage(const image::Image& _query);
00111 void setModelsDatabase(const ModelsDatabase& database);
00113 std::vector<std::string> identifiedObjects() const {
00114 return plausibles;
00115 }
00117 void process();
00118 private:
00120 void initialTry();
00122 void tryAgain(const gfm::DetectionResult& dr);
00124 void evaluateResult();
00126 gfm::DetectionResult remainingFeatures(const gfm::DetectionResult& dr,
00127 const gfm::MatchingResult& mr);
00129 bool isMatchedFeature(gfm::InterestFeature* f,
00130 const gfm::MatchingResult& mr);
00132 ResultIterator bestRecognitionResult();
00134 ModelIterator bestModel();
00135 };
00136
00137 }
00138
00139 }
00140
00141 #endif