00001
00002
00003 #ifndef SLAM_IMAGE_SEGMENT_MANAGER_HPP
00004 #define SLAM_IMAGE_SEGMENT_MANAGER_HPP
00005
00006 #include <iostream>
00007 #include <vector>
00008 #include <map>
00009
00010 #include "jmath/jblas.hpp"
00011
00012 #include "slam/bearingOnlySlam.hpp"
00013
00014 #include "lines/lineSegmentSet.hpp"
00015 #include "lines/lineSegment.hpp"
00016 #include "lines/matchingSet.hpp"
00017 #include "slam/observation.hpp"
00018
00019 namespace jafar {
00020 namespace slamlines {
00021
00024 class ImageSegment {
00025
00026 public:
00027
00028 static const unsigned int NO_ID = 0;
00029
00031 unsigned int id;
00032
00034 jblas::vec2 ext1;
00035 jblas::vec2 ext2;
00036
00038 jblas::sym_mat ext1Cov;
00039 jblas::sym_mat ext2Cov;
00040
00041
00042 ImageSegment(jblas::vec2 ext1_, jblas::vec2 ext2_) :
00043 id(NO_ID) ,
00044 ext1(ext1_),
00045 ext2(ext2_)
00046 {}
00047
00048 ImageSegment(jblas::vec2 ext1_, jblas::vec2 ext2_, jblas::sym_mat ext1Cov_, jblas::sym_mat ext2Cov_,unsigned int id_) :
00049 id(id_) ,
00050 ext1(ext1_),
00051 ext2(ext2_),
00052 ext1Cov(ext1Cov_),
00053 ext2Cov(ext2Cov_)
00054 {}
00055 };
00056
00057 std::ostream& operator <<(std::ostream& s, ImageSegment const& seg);
00058
00060 typedef std::pair<std::size_t, std::size_t> Match;
00061
00063 typedef std::vector<Match> VecMatches;
00064
00066 typedef std::vector<ImageSegment> VecImageSegments;
00067
00068 void readImageSegments(std::string const& filename, VecImageSegments& vecImageSegments);
00069
00070 void readImageSegmentsId(std::string const& filename, VecImageSegments& vecImageSegments);
00071
00072 void readImageSegmentsMatches(std::string const& filename, VecMatches& matches);
00073
00074 void lineSegmentSetToImageSegmentVec(jafar::lines::LineSegmentSet& lineSegmentSet, VecImageSegments& vecImageSegments);
00075
00076 void matchingSetToImageSegmentsMatches(jafar::lines::MatchingSet& matchingSet, VecMatches& matches);
00077
00078 unsigned int propagateId(VecMatches const& vecMatches,
00079 VecImageSegments const& vecImageSegmentsRef, VecImageSegments& vecImageSegmentsMatch);
00080
00081
00082
00085 class ImageSegmentManager {
00086
00087 protected:
00088
00089 unsigned int p_idFactory;
00090 unsigned int getNewFeatureId() {return ++p_idFactory;}
00091
00092
00093 slam::BearingOnlySlam& p_slam;
00094
00096 double p_minSegmentSize;
00097
00098 jblas::vec2 p_zone1;
00099 jblas::vec2 p_zone2;
00100
00101 bool isInZone(jblas::vec2 const& pix) const {
00102 return pix(0) > p_zone1(0) && pix(1) > p_zone1(1) && pix(0) < p_zone2(0) && pix(1) < p_zone2(1);
00103 }
00104
00105 void featureSelection(VecImageSegments& vecImageSegments);
00106
00107 void slamProcessObservations(unsigned int currentFrameIndex, VecImageSegments& vecImageSegments) const;
00108
00109 public:
00111 slam::Observation::ObservationType type;
00112
00113
00114 ImageSegmentManager(slam::BearingOnlySlam& slam, slam::Observation::ObservationType type_=slam::Observation::SEGMENT_IMAGE) : p_idFactory(0), p_slam(slam), type(type_) {}
00115
00116 void setup(double minSegmentSize, double u1, double v1, double u2, double v2) {
00117 p_minSegmentSize = minSegmentSize;
00118 p_zone1(0) = u1;
00119 p_zone1(1) = v1;
00120 p_zone2(0) = u2;
00121 p_zone2(1) = v2;
00122 }
00123
00124 void initFrame(unsigned int frameIndex_, VecImageSegments& vecImageSegments);
00125 void processFrame(unsigned int frameIndex, VecImageSegments& vecImageSegments);
00126
00127 unsigned int compareId(VecMatches const& matches,
00128 VecImageSegments const& vecImageSegmentsRef, VecImageSegments& vecImageSegmentsMatch, jafar::lines::LineSegmentSet& lineSegmentSet);
00129
00130 unsigned int compareIdInv(VecMatches const& matches,
00131 VecImageSegments const& vecImageSegmentsRef, VecImageSegments& vecImageSegmentsMatch, jafar::lines::LineSegmentSet& lineSegmentSet);
00132 unsigned int compareIdInvAll(VecMatches const& matches, VecImageSegments const& vecImageSegmentsRef, VecImageSegments& vecImageSegmentsMatch, jafar::lines::LineSegmentSet& lineSegmentSet);
00133 };
00134
00135
00136
00137
00139 class ImageHomogenCoordSegmentManager {
00140
00141 protected:
00142
00143 unsigned int p_idFactory;
00144 unsigned int getNewFeatureId() {return ++p_idFactory;}
00145
00146 slam::SlamEkf& slam;
00147
00149 double p_minSegmentSize;
00150
00151 jblas::vec2 p_zone1;
00152 jblas::vec2 p_zone2;
00153
00155 bool isInZone(jblas::vec2 const& pix) const {
00156 return pix(0) > p_zone1(0) && pix(1) > p_zone1(1) && pix(0) < p_zone2(0) && pix(1) < p_zone2(1);
00157 }
00158
00160 void featureSelection(VecImageSegments& vecImageSegments);
00161
00163 void slamProcessObservations(unsigned int currentFrameIndex, VecImageSegments& vecImageSegments) const;
00164
00165 public:
00166
00168 slam::Observation::ObservationType type;
00169
00171 ImageHomogenCoordSegmentManager(slam::SlamEkf& slam_, slam::Observation::ObservationType type_=slam::Observation::SEGMENT_IMAGE) : p_idFactory(0), slam(slam_), type(type_) {}
00172
00180 void setup(double minSegmentSize, double u1, double v1, double u2, double v2) {
00181 p_minSegmentSize = minSegmentSize;
00182 p_zone1(0) = u1;
00183 p_zone1(1) = v1;
00184 p_zone2(0) = u2;
00185 p_zone2(1) = v2;
00186 }
00187
00189 void initFrame(unsigned int frameIndex_, VecImageSegments& vecImageSegments);
00190
00192 void processFrame(unsigned int frameIndex, VecImageSegments& vecImageSegments);
00193
00194
00195
00198 unsigned int compareId(VecMatches const& matches,
00199 VecImageSegments const& vecImageSegmentsRef, VecImageSegments& vecImageSegmentsMatch, jafar::lines::LineSegmentSet& lineSegmentSet);
00200
00203 unsigned int compareIdInv(VecMatches const& matches,
00204 VecImageSegments const& vecImageSegmentsRef, VecImageSegments& vecImageSegmentsMatch, jafar::lines::LineSegmentSet& lineSegmentSet);
00205
00208 unsigned int compareIdInvAll(VecMatches const& matches, VecImageSegments const& vecImageSegmentsRef, VecImageSegments& vecImageSegmentsMatch, jafar::lines::LineSegmentSet& lineSegmentSet);
00209 };
00210
00211
00212 }
00213 }
00214
00215 #endif // SLAM_IMAGE_SEGMENT_MANAGER_HPP