00001
00014 #ifndef RAWPROCESSORS_HPP_
00015 #define RAWPROCESSORS_HPP_
00016
00017
00018 #include "correl/explorer.hpp"
00019 #include "rtslam/quickHarrisDetector.hpp"
00020
00021
00022 #include "rtslam/rawImage.hpp"
00023 #include "rtslam/sensorPinhole.hpp"
00024 #include "rtslam/descriptorImagePoint.hpp"
00025
00026
00027
00028 namespace jafar {
00029 namespace rtslam {
00030
00031 class ImagePointZnccMatcher
00032 {
00033 private:
00034 correl::FastTranslationMatcherZncc matcher;
00035
00036 public:
00037 struct matcher_params_t {
00038 int patchSize;
00039 int maxSearchSize;
00040 double lowInnov;
00041 double threshold;
00042 double hi_threshold;
00043 double hi_limit;
00044 double mahalanobisTh;
00045 double relevanceTh;
00046 double measStd;
00047 double measVar;
00048 } params;
00049
00050 public:
00051 ImagePointZnccMatcher(double minScore, double partialPosition, int patchSize, int maxSearchSize, double lowInnov, double threshold, double hi_threshold, double hi_limit, double mahalanobisTh, double relevanceTh, double measStd):
00052 matcher(minScore, partialPosition)
00053 {
00054 JFR_ASSERT(patchSize%2, "patchSize must be an odd number!");
00055 JFR_ASSERT(minScore>=0.0 && minScore<=1, "minScore must be between 0 and 1!");
00056 params.patchSize = patchSize;
00057 params.maxSearchSize = maxSearchSize;
00058 params.lowInnov = lowInnov;
00059 params.threshold = threshold;
00060 params.hi_threshold = hi_threshold;
00061 params.hi_limit = hi_limit;
00062 params.mahalanobisTh = mahalanobisTh;
00063 params.relevanceTh = relevanceTh;
00064 params.measStd = measStd;
00065 params.measVar = measStd * measStd;
00066 }
00067
00068 void match(const boost::shared_ptr<RawImage> & rawPtr, const appearance_ptr_t & targetApp, const image::ConvexRoi & roi, Measurement & measure, appearance_ptr_t & app)
00069 {
00070 app_img_pnt_ptr_t targetAppSpec = SPTR_CAST<AppearanceImagePoint>(targetApp);
00071 app_img_pnt_ptr_t appSpec = SPTR_CAST<AppearanceImagePoint>(app);
00072
00073 measure.std(params.measStd);
00074 measure.matchScore = matcher.match(targetAppSpec->patch, *(rawPtr->img),
00075 roi, measure.x()(0), measure.x()(1), measure.std_est(0), measure.std_est(1));
00076 if (measure.std_est(0) > 50 || measure.std_est(1) > 50) measure.matchScore = 0.;
00077 measure.x() += targetAppSpec->offset.x();
00078 measure.P() += targetAppSpec->offset.P();
00079 rawPtr->img->extractPatch(appSpec->patch, (int)measure.x()(0), (int)measure.x()(1), appSpec->patch.width(), appSpec->patch.height());
00080 appSpec->offset.x()(0) = measure.x()(0) - ((int)(measure.x()(0)) + 0.5);
00081 appSpec->offset.x()(1) = measure.x()(1) - ((int)(measure.x()(1)) + 0.5);
00082 appSpec->offset.P() = measure.P();
00083 }
00084 };
00085
00086
00087
00088
00089 class ImagePointHarrisDetector
00090 {
00091 private:
00092 QuickHarrisDetector detector;
00093 boost::shared_ptr<DescriptorFactoryAbstract> descFactory;
00094
00095 public:
00096 struct detector_params_t {
00097 int patchSize;
00098 double measStd;
00099 double measVar;
00100 } params;
00101
00102 public:
00103 ImagePointHarrisDetector(int convSize, double thres, double edge, int patchSize, double measStd,
00104 boost::shared_ptr<DescriptorFactoryAbstract> const &descFactory):
00105 detector(convSize, thres, edge), descFactory(descFactory)
00106 {
00107 JFR_ASSERT(convSize%2, "convSize must be an odd number!");
00108 JFR_ASSERT(patchSize%2, "patchSize must be an odd number!");
00109 params.patchSize = patchSize;
00110 params.measStd = measStd;
00111 params.measVar = measStd * measStd;
00112 }
00113
00114 bool detect(const boost::shared_ptr<RawImage> & rawData, const image::ConvexRoi &roi, boost::shared_ptr<FeatureImagePoint> & featPtr)
00115 {
00116 featPtr.reset(new FeatureImagePoint(params.patchSize, params.patchSize, CV_8U));
00117 featPtr->measurement.std(params.measStd);
00118 if (detector.detectIn(*(rawData->img.get()), featPtr, &roi))
00119 {
00120
00121 vec pix = featPtr->measurement.x();
00122 boost::shared_ptr<AppearanceImagePoint> appPtr = SPTR_CAST<AppearanceImagePoint>(featPtr->appearancePtr);
00123 rawData->img->extractPatch(appPtr->patch, (int)pix(0), (int)pix(1), params.patchSize, params.patchSize);
00124 appPtr->offset.x()(0) = pix(0) - ((int)pix(0) + 0.5);
00125 appPtr->offset.x()(1) = pix(1) - ((int)pix(1) + 0.5);
00126 appPtr->offset.P() = jblas::zero_mat(2);
00127
00128 return true;
00129 } else return false;
00130 }
00131
00132 void fillDataObs(const boost::shared_ptr<FeatureImagePoint> & featPtr, boost::shared_ptr<ObservationAbstract> & obsPtr)
00133 {
00134
00135 app_img_pnt_ptr_t app_src = SPTR_CAST<AppearanceImagePoint>(featPtr->appearancePtr);
00136 app_img_pnt_ptr_t app_dst = SPTR_CAST<AppearanceImagePoint>(obsPtr->observedAppearance);
00137 app_src->patch.copyTo(app_dst->patch);
00138
00139
00140
00141 app_dst->offset = app_src->offset;
00142
00143
00144 descriptor_ptr_t descPtr(descFactory->createDescriptor());
00145 obsPtr->landmarkPtr()->setDescriptor(descPtr);
00146 }
00147
00148 };
00149
00150 }}
00151
00152 #endif