00001 #include <vslam_system/place_recognizer.h>
00002
00003 namespace vslam {
00004
00005 PlaceRecognizer::PlaceRecognizer(const std::string& tree_file,
00006 const std::string& weights_file)
00007 : tree_(tree_file)
00008 {
00009 database_.loadWeights(weights_file);
00010 }
00011
00012 void PlaceRecognizer::insert(const frame_common::Frame& frame, uint32_t id)
00013 {
00014 vt::Document words(frame.dtors.rows);
00015 for (int i = 0; i < frame.dtors.rows; ++i) {
00016 words[i] = tree_.quantize(frame.dtors.row(i));
00017 }
00018
00019 vt::DocId doc_id = database_.insert(words);
00020 assert(doc_id == user_ids_.size());
00021 user_ids_.push_back(id);
00022 }
00023
00024 void PlaceRecognizer::findAndInsert(const frame_common::Frame& frame, uint32_t id,
00025 const FrameVector& all_frames, size_t N,
00026 std::vector<const frame_common::Frame*>& matches)
00027 {
00028 vt::Document words(frame.dtors.rows);
00029 for (int i = 0; i < frame.dtors.rows; ++i) {
00030 words[i] = tree_.quantize(frame.dtors.row(i));
00031 }
00032
00033 vt::Matches doc_matches;
00034 vt::DocId doc_id = database_.findAndInsert(words, N, doc_matches);
00035 assert(doc_id == user_ids_.size());
00036 user_ids_.push_back(id);
00037
00038 matches.resize(doc_matches.size());
00039 for (size_t i = 0; i < matches.size(); ++i) {
00040 matches[i] = &all_frames[ user_ids_[doc_matches[i].id] ];
00041 }
00042 }
00043
00044 }