00001
00008 #if 0
00009 #include "rtslam/dataManagerActiveSearch.hpp"
00010 #include "rtslam/observationAbstract.hpp"
00011 #include "rtslam/rawImage.hpp"
00012 #include "rtslam/sensorPinhole.hpp"
00013 #include "rtslam/descriptorImagePoint.hpp"
00014
00015 #include "rtslam/imageTools.hpp"
00016
00017 namespace jafar {
00018 namespace rtslam {
00019
00020 template<class RawSpec,class SensorSpec, class Detector, class Matcher >
00021 void DataManagerActiveSearch<RawSpec,SensorSpec, Detector, Matcher >::
00022 processKnownObs( boost::shared_ptr<RawSpec> rawData )
00023 {
00024 int numObs = 0;
00025 asGrid->renew();
00026 obsListSorted.clear();
00027
00028
00029 for (ObservationList::iterator obsIter = observationList().begin(); obsIter
00030 != observationList().end(); obsIter++) {
00031 observation_ptr_t obsPtr = *obsIter;
00032
00033 obsPtr->clearEvents();
00034 obsPtr->measurement.matchScore = 0;
00035
00036
00037
00038 obsPtr->project();
00039
00040
00041 obsPtr->predictVisibility();
00042
00043 if (obsPtr->isVisible()) {
00044
00045
00046
00047 asGrid->addObs(obsPtr->expectation.x());
00048
00049
00050
00051 obsPtr->predictInfoGain();
00052
00053
00054
00055 obsListSorted[obsPtr->expectation.infoGain] = obsPtr;
00056
00057 }
00058 }
00059
00060
00061
00062 for (ObservationListSorted::reverse_iterator obsIter = obsListSorted.rbegin(); obsIter
00063 != obsListSorted.rend(); obsIter++) {
00064 observation_ptr_t obsPtr = obsIter->second;
00065
00066
00067
00068 obsPtr->project();
00069
00070 obsPtr->events.predicted = true;
00071
00072
00073 obsPtr->predictVisibility();
00074
00075 if (obsPtr->isVisible()) {
00076
00077 obsPtr->events.visible = true;
00078
00079 if (numObs < algorithmParams_.n_updates) {
00080
00081 obsPtr->events.measured = true;
00082
00083
00084 obsPtr->counters.nSearch++;
00085
00086
00087
00088
00089 image::ConvexRoi roi(obsPtr->expectation.x(), obsPtr->expectation.P() + matcherParams_.measVar*identity_mat(2), matcherParams_.regionSigma);
00090 obsPtr->predictAppearance();
00091
00092
00093
00094 obsPtr->measurement.std(detectorParams_.measStd);
00095 boost::shared_ptr<RawSpec> rawSpecPtr = SPTR_CAST<RawSpec>(sensorPtr()->getRaw());
00096
00097 match(rawSpecPtr, obsPtr->predictedAppearance, roi, obsPtr->measurement,
00098 obsPtr->observedAppearance);
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 if (obsPtr->getMatchScore() > matcherParams_.threshold) {
00122 obsPtr->counters.nMatch++;
00123 obsPtr->events.matched = true;
00124 obsPtr->computeInnovation();
00125
00126
00127
00128
00129 if (obsPtr->compatibilityTest(matcherParams_.mahalanobisTh)) {
00130 numObs++;
00131 obsPtr->counters.nInlier++;
00132
00133 obsPtr->update();
00134
00135 obsPtr->events.updated = true;
00136 }
00137
00138 }
00139
00140
00141
00142
00143 }
00144
00145 }
00146
00147
00148
00149
00150 }
00151
00152 obsListSorted.clear();
00153 }
00154
00155
00156 template<>
00157 bool DataManagerActiveSearch<RawImage, SensorPinhole, QuickHarrisDetector, correl::FastTranslationMatcherZncc>::
00158 match(const boost::shared_ptr<RawImage> & rawPtr, const appearance_ptr_t & targetApp, image::ConvexRoi &roi, Measurement & measure, const appearance_ptr_t & app)
00159 {
00160 app_img_pnt_ptr_t targetAppImg = SPTR_CAST<AppearanceImagePoint>(targetApp);
00161 app_img_pnt_ptr_t appImg = SPTR_CAST<AppearanceImagePoint>(app);
00162
00163 measure.matchScore = matcher->match(targetAppImg->patch, *(rawPtr->img),
00164 roi, measure.x()(0), measure.x()(1));
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 return true;
00176
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 template<>
00213 void DataManagerActiveSearch<RawImage, SensorPinhole, QuickHarrisDetector, correl::FastTranslationMatcherZncc>::
00214 detectNewObs( boost::shared_ptr<RawImage> rawData )
00215 {
00216 if (mapManagerPtr()->mapSpaceForInit()) {
00217
00218 ROI roi;
00219 if (asGrid->getRoi(roi)) {
00220 feat_img_pnt_ptr_t featPtr(new FeatureImagePoint(detectorParams_.patchSize,
00221 detectorParams_.patchSize,
00222 CV_8U));
00223 featPtr->measurement.std(detectorParams_.measStd);
00224 if (detector->detectIn(*(rawData->img.get()), featPtr, &roi)) {
00225 vec pix = featPtr->measurement.x();
00226 app_img_pnt_ptr_t appPtr = SPTR_CAST<AppearanceImagePoint>(featPtr->appearancePtr);
00227
00228
00229 cv::Size size = appPtr->patch.size();
00230
00231 int shift_x = (size.width-1)/2;
00232 int shift_y = (size.height-1)/2;
00233 int x_src = pix(0)-shift_x;
00234 int y_src = pix(1)-shift_y;
00235 rawData->img->copy(appPtr->patch, x_src, y_src, 0, 0, size.width, size.height);
00236
00237
00238
00239
00240
00241
00242
00243 observation_ptr_t obsPtr =
00244 mapManagerPtr()->createNewLandmark(shared_from_this());
00245
00246
00247 obsPtr->counters.nSearch = 1;
00248 obsPtr->counters.nMatch = 1;
00249 obsPtr->counters.nInlier = 1;
00250 obsPtr->events.visible = true;
00251 obsPtr->events.predicted = false;
00252 obsPtr->events.measured = true;
00253 obsPtr->events.matched = false;
00254 obsPtr->events.updated = false;
00255 obsPtr->measurement = featPtr->measurement;
00256
00257
00258
00259
00260
00261
00262
00263
00264 app_img_pnt_ptr_t app_src = SPTR_CAST<AppearanceImagePoint>(featPtr->appearancePtr);
00265 app_img_pnt_ptr_t app_dst = SPTR_CAST<AppearanceImagePoint>(obsPtr->observedAppearance);
00266 app_src->patch.copy(app_dst->patch, (app_src->patch.width()-app_dst->patch.width())/2,
00267 (app_src->patch.height()-app_dst->patch.height())/2, 0, 0,
00268 app_dst->patch.width(), app_dst->patch.height());
00269
00270
00271 obsPtr->backProject();
00272
00273
00274 vec7 globalSensorPose = sensorPtr()->globalPose();
00275 desc_img_pnt_ptr_t
00276 descPtr(new DescriptorImagePointFirstView(featPtr, globalSensorPose,
00277 obsPtr));
00278 obsPtr->landmarkPtr()->setDescriptor(descPtr);
00279
00280 }
00281 }
00282 }
00283 }
00284
00285 template<class RawSpec,class SensorSpec, class Detector, class Matcher>
00286 void DataManagerActiveSearch<RawSpec,SensorSpec,Detector,Matcher>::
00287 process( boost::shared_ptr<RawAbstract> data )
00288 {
00289 boost::shared_ptr<RawImage> dataSpec = SPTR_CAST<RawImage>(data);
00290
00291 processKnownObs(dataSpec);
00292
00293 detectNewObs(dataSpec);
00294 }
00295
00296 }
00297 };
00298
00299 #endif