00001 #ifndef BLOBTRACKER_H_DEFINED 00002 #define BLOBTRACKER_H_DEFINED 00003 00004 #include "Image/OpenCVUtil.H" 00005 00006 #include "Component/ModelComponent.H" 00007 #include "Component/ModelParam.H" 00008 #include "Image/Image.H" 00009 #include <vector> 00010 #include "Util/sformat.H" 00011 00012 #ifdef HAVE_OPENCVAUX 00013 #define MAX(a,b) ((a) < (b) ? (b) : (a)) 00014 #include <opencv/cvaux.h> 00015 #include <opencv/cvvidsurv.hpp> 00016 #endif 00017 #if (CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 2) || CV_MAJOR_VERSION>=3 00018 #include <opencv2/legacy/blobtrack.hpp> 00019 #include <opencv2/video/background_segm.hpp> 00020 #endif 00021 00022 class Blob { 00023 public: 00024 Point2D<int> center; 00025 Dims dims; 00026 int id; 00027 double confidence; 00028 std::string toString() { return sformat("[Blob Object: Center<%s>, Dims<%s>, Id %d, Conf %f]",convertToString(center).c_str(),convertToString(dims).c_str(),id,confidence); } 00029 }; 00030 00031 class BlobTracker : public ModelComponent 00032 { 00033 public: 00034 BlobTracker(OptionManager& mgr, 00035 const std::string& descrName = "BlobTracker", 00036 const std::string& tagName = "BlobTracker"); 00037 00038 ~BlobTracker(); 00039 00040 void update(Image<PixRGB<byte> > img); 00041 00042 std::vector<Blob> getBlobs() { return itsBlobs; } 00043 00044 00045 00046 private: 00047 CvBlobTrackerAuto* itsTracker; 00048 CvBlobTrackerAutoParam1 itsTrackerParams; 00049 std::vector<Blob> itsBlobs; 00050 }; 00051 00052 00053 00054 00055 00056 #endif 00057