00001
00002 #ifndef SAS_IRT_HPP
00003 #define SAS_IRT_HPP
00004
00005 #include "kernel/keyValueFile.hpp"
00006 #include "image/Image.hpp"
00007 #include <cvaux.h>
00008 #include "sas/irdm.hpp"
00009 #include "sas/ird.hpp"
00010
00011 namespace jafar {
00012 namespace sas {
00013
00015 struct SRoi : public CvBlob{
00016 float angle;
00017
00018 SRoi (float x_=0, float y_=0, float width_=0, float height_=0, float angle_=0) {
00019 x=x_; y=y_; w=width_; h=height_; ID=0; angle=angle_;
00020 };
00021 };
00022
00023
00029 class CS_IRT {
00030 public:
00032 CS_IRT() : isInitialized(false), isObject2TrackSet(false), tracker() {};
00033
00035 ~CS_IRT() {};
00036
00040 void initialize(int nbins_=16);
00041
00046 void setObject2Track(const jafar::image::Image& src_,
00047 CvRect const & rect);
00048
00052 SRoi trackObject(const jafar::image::Image& img_);
00053
00054 private:
00055 bool isInitialized;
00056 bool isObject2TrackSet;
00057 CvCamShiftTracker tracker;
00058 };
00059
00060
00064 class CV_IRT_BlobDetector : public CvFGDetector, public jafar::sas::IRD {
00065 public:
00066 CV_IRT_BlobDetector (IRDM * dm): CvFGDetector(), jafar::sas::IRD (dm), m_dm(dm) {};
00067 virtual ~CV_IRT_BlobDetector () {};
00068
00073 virtual IplImage* GetMask() {
00074 return m_mask;
00075 };
00081 virtual void Process(IplImage* pImg=0) {
00082 computeSaliency();
00083 if ( !m_mask || m_dm->m_imgs["src"].width() != m_dm->m_imgs["src"].width() || m_mask.height() != m_dm->m_imgs["src"].height() )
00084 m_mask = jafar::image::Image(m_dm->m_imgs["src"].width(),m_dm->m_imgs["src"].height(),IPL_DEPTH_8U,JfrImage_CS_GRAY);
00085 jafar::image::Image tmp = m_dm->m_imgs["saliency"].clone();
00086 cvNormalize(tmp,tmp,0.,255.,CV_MINMAX);
00087 tmp.resize(m_mask.width(),m_mask.height());
00088 cvConvertScale(tmp,m_mask);
00089 };
00094 virtual void Release() {};
00095
00096 private:
00097 IRDM * m_dm;
00098 jafar::image::Image m_mask;
00099 };
00100
00101
00107 class CV_IRT {
00108 public:
00109
00110 CV_IRT (IRDM * dm) : m_dm(dm), m_cvparams(), m_tracker(0), pMask(0) {
00111 m_cvparams.pBT = 0;
00112 m_cvparams.pBD = 0;
00113 m_cvparams.pBTGen = 0;
00114 m_cvparams.pBTA = 0;
00115 m_cvparams.pFG = 0;
00116 m_cvparams.pBTPP = 0;
00117 };
00118
00119 virtual ~CV_IRT () {
00120 release();
00121 };
00122
00123 void init();
00124
00125 void release();
00126
00127 void process(jafar::image::Image & display);
00128
00129 private:
00130 IRDM * m_dm;
00131 CvBlobTrackerAutoParam1 m_cvparams;
00132 CvBlobTrackerAuto * m_tracker;
00133 IplImage* pMask;
00134 };
00135
00136
00140 class BK_IRT {
00141 public:
00142
00146 class Params : public jafar::kernel::KeyValueFileLoad {
00147 public:
00148 float m_thd_confidence;
00149 float m_ModelNoise;
00150 float m_DataNoisePos;
00151 float m_DataNoiseSize;
00152
00153 Params(float tdc=0.5, float mn=1e-5f, float dnp=1e-1f, float dns= 1e-1f) :
00154 m_thd_confidence(tdc), m_ModelNoise(mn),m_DataNoisePos(dnp),m_DataNoiseSize(dns) {};
00155 protected:
00159 void loadKeyValueFile(jafar::kernel::KeyValueFile const& keyValueFile);
00160 };
00161
00162
00163 BK_IRT (IRDM * dm, Params params=Params()) : m_dm(dm), m_params(params) {};
00164
00165 static inline BK_IRT * createBKIRT(IRDM * dm, std::string const & filename) {
00166 BK_IRT::Params params;
00167 params.load(filename);
00168 return new BK_IRT(dm,params);
00169 };
00170 virtual ~BK_IRT ();
00171
00172 void process();
00173
00174 void draw(jafar::image::Image & display);
00175
00176 private:
00177
00178 struct tracker {
00179 CvKalman* m_Kalman;
00180 sTrack * m_track;
00181 sir * m_predict;
00182
00183 ~tracker() {
00184 cvReleaseKalman(&m_Kalman);
00185 delete m_predict;
00186 m_track->m_tracked = false;
00187 };
00188
00189 float getConfidence(sir * s, int w_);
00190
00191 void update(sir * s);
00192 };
00193
00194
00195 IRDM * m_dm;
00196 Params m_params;
00197 std::list<tracker *> m_trackers;
00198 std::list<sir *> m_candidates;
00199
00200
00201 tracker * startTracker(sir * s, sir * c);
00202 tracker * endTracker(tracker * tr);
00203 float getConfidence(sir * s, sir * c, int w_);
00204
00205 };
00206
00207 }
00208 }
00209
00210 #endif // SAS_IRT_HPP