00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef OPENCV_BLOBTRACK_H
00021 #define OPENCV_BLOBTRACK_H
00022
00023 #include <ardev/ardevconfig.h>
00024
00025 #ifdef HAVE_OPENCV
00026
00027 #include <ardev/ardev.h>
00028 #include <ardev/debug.h>
00029 #include <map>
00030
00031 #include <opencv/cv.h>
00032
00033 struct intlt_bt
00034 {
00035 public: bool operator () (const int & lhs, const int &rhs)
00036 {
00037 return lhs < rhs;
00038 };
00039 };
00040
00041 typedef struct BlobPair
00042 {
00043 int Hue1_Min;
00044 int Hue1_Max;
00045 int Hue2_Min;
00046 int Hue2_Max;
00047 double Height;
00048
00049 ARPosition pos;
00050 } BlobPair_t;
00051
00055 class OpenCVBlobTrackPreProcess : public FrameProcessObject
00056 {
00057 public:
00059 OpenCVBlobTrackPreProcess(CameraObject & Camera, double BlobMinSize = 200, double BlobMaxSize = 10000, bool debug = false);
00060
00062 ~OpenCVBlobTrackPreProcess();
00063
00065 void ProcessFrame(const ARImage & frame);
00066
00072 int AddBlobs(BlobPair_t & blob);
00074 void RemoveBlobs(int id);
00075
00077 bool GetMarkerPos(int id, ARPosition &result);
00078
00079 private:
00080 unsigned int lastFrameWidth;
00081 unsigned int lastFrameHeight;
00082 ARCamera camera;
00083 double MinSize;
00084 double MaxSize;
00085 bool Debug;
00086 int PatNumber;
00087
00088 std::map<int,BlobPair,intlt_bt> Markers;
00089
00090
00091 ARPoint GetBlobCenter(int HueMin, int HueMax, IplImage * im, CvSize size);
00092
00094 ARPosition GetPosition(ARPoint P1, ARPoint P2, double Height);
00095
00097 void DropLowSat(IplImage * h_img, IplImage * s_img, int sat_thresh, int NewHue, CvSize size);
00098 };
00099
00102 class OpenCVBlobTrackPosition : public PositionObject
00103 {
00104 public:
00105 OpenCVBlobTrackPosition(OpenCVBlobTrackPreProcess & pre, const BlobPair_t & blob) : Pre(pre), Blob(blob)
00106 {
00107 Elapsed = 0;
00108 MarkerID = 0;
00109 memset(&lastGoodPosition,0,sizeof(lastGoodPosition));
00110 };
00111
00112 ~OpenCVBlobTrackPosition()
00113 {
00114 };
00115
00117 int Initialise(bool Active = true)
00118 {
00119 dbg_print(ARDBG_VERBOSE,"Adding new blob pair to opencv tracker: %d %d %d %d\n",Blob.Hue1_Min, Blob.Hue1_Max,Blob.Hue2_Min,Blob.Hue2_Max);
00120 MarkerID = Pre.AddBlobs(Blob);
00121 dbg_print(ARDBG_VERBOSE,"Blob was assigned Marker ID: %d\n",MarkerID);
00122 return 0;
00123 };
00124
00126 void Terminate()
00127 {
00128 Pre.RemoveBlobs(MarkerID);
00129 };
00130
00132 virtual ARPosition GetPosition();
00133
00135 virtual bool Present();
00136
00137 protected:
00138 OpenCVBlobTrackPreProcess & Pre;
00139 unsigned int MarkerID;
00140 ARPosition lastGoodPosition;
00141 StopWatch Timer;
00142 double Elapsed;
00143 BlobPair_t Blob;
00144 };
00145
00146 #endif
00147 #endif