You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.2 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __BLOB_DETECTOR_HEADER__
  2. #define __BLOB_DETECTOR_HEADER__
  3. #include "../../../components/base/basicVideoAnalyzer.h"
  4. #include "../../../components/base/basicCameraPTZ.h"
  5. //#include "../blob/blob.h"
  6. #include "../blob/BlobResult.h"
  7. #include "../filter/filterImage.h"
  8. // display (native resolution of projector)
  9. static const int WIDTH = 800; //1280
  10. static const int HEIGHT = 600; //800
  11. static const int BPP = 32;
  12. // tracker parameters
  13. static const float TMINAREA = 16.f; // minimum area of blob to track 16
  14. static const float TMAXRADIUS = 40.f; // a blob is identified with a blob in the previous frame if it exists within this radius
  15. enum { BLOB_NULL, BLOB_NEW, BLOB_STEADY, BLOB_MOVE }; // event types
  16. #define V_SEGMENT_SIZE 5
  17. #define H_SEGMENT_SIZE 5
  18. typedef struct S_point2D {
  19. float x, y;
  20. }point2D;
  21. typedef std::vector<point2D> vector2DPoints;
  22. class cBlob {
  23. private:
  24. protected:
  25. public:
  26. unsigned int id;
  27. int weight;
  28. point2D location, origin; // current location and origin for defining a drag vector
  29. Rect box; // to define our axis-aligned bounding box
  30. float area;
  31. int event; // event type: one of BLOB_NULL, BLOB_DOWN, BLOB_MOVE, BLOB_UP
  32. bool tracked; // a flag to indicate this blob has been processed
  33. Scalar color;
  34. float dir;
  35. vector2DPoints ConvexHull;
  36. };
  37. class blobDetector: public basicVideoAnalyzer{
  38. private:
  39. U8 m_aSegments[V_SEGMENT_SIZE][H_SEGMENT_SIZE];
  40. filterImage *m_oFilter;
  41. int m_nPrepMethod;
  42. bool m_bReduceSize;
  43. bool m_bUsePolygones;
  44. bool m_bShowPolygones;
  45. bool m_bShowRectangles;
  46. bool m_bShowCentres;
  47. float m_nMinArea;
  48. float m_nMaxRadius;
  49. float m_fSegmentStepX;
  50. float m_fSegmentStepY;
  51. CBlobResult *m_vBlobs;
  52. IplImage *m_pIplThr;
  53. IplImage *m_pIplOrig;
  54. IplImage *m_pIplWork;
  55. Mat m_oMat;
  56. Mat tThresh;
  57. int m_nCursorX;
  58. int m_nCursorY;
  59. int m_nCursorZ;
  60. int m_nStepX;
  61. int m_nStepY;
  62. int m_nStepZ;
  63. bool m_bCursorIsSet;
  64. // instances of helper classes for obtaining blob location and bounding box
  65. CBlobGetXCenter XCenter;
  66. CBlobGetYCenter YCenter;
  67. CBlobGetMinX MinX;
  68. CBlobGetMinY MinY;
  69. CBlobGetMaxX MaxX;
  70. CBlobGetMaxY MaxY;
  71. // storage of the current blobs and the blobs from the previous frame
  72. vector<cBlob> blobs;
  73. vector<cBlob> blobs_previous;
  74. CBlob current_blob;
  75. bool lookupMaxActiveSegment(U8 &x, U8 &y);
  76. #ifndef NO_PTZ_CAMERAS
  77. basicCameraPTZ *m_pPTZ;
  78. #endif
  79. int m_nCamControllCurrent;
  80. protected:
  81. virtual bool m_fImageAnalyzer(Mat &Picture);
  82. public:
  83. blobDetector();
  84. blobDetector( float min_area, float max_radius );
  85. ~blobDetector();
  86. virtual void markup(Mat &Picture);
  87. vector<cBlob> &getBlobs( void );
  88. #ifndef NO_PTZ_CAMERAS
  89. bool attachPTZ(basicCameraPTZ *cam);
  90. #endif
  91. void showPolygones(bool val){ if (m_bUsePolygones) m_bShowPolygones = val; };
  92. void showRectangles(bool val){ m_bShowRectangles = val; };
  93. void showCentres(bool val){
  94. m_bShowCentres = val;
  95. };
  96. void setUsePolygones(bool val){ m_bUsePolygones = val; };
  97. };
  98. #endif