PedestrainCounting
TargetsFreeList.h
1 
7 #ifndef TARGETS_FREELIST_HEADER
8 #define TARGETS_FREELIST_HEADER
9 
10 #include "SingleTarget.h"
11 
13  SingleTarget *target;
14  TargetsFreeListNode *nextFree;
15  bool isFree;
16  cv::Scalar color;
17 
18  TargetsFreeListNode(const Options &opts);
20 };
21 
23 public:
24  TargetsFreeList(const Options &opts);
25  ~TargetsFreeList();
26 
30  void ResetOneTarget(int index);
31 
32  int InitializeTarget(const Rect &target, const Point2D &initVelocity);
33 
37  void Propagate(const Size &imgSize);
38 
42  void Observe(const IntegralImage *intImage, const Pool<Rect> &detections);
43 
44  inline void Resample() {
45  for (auto &node : listNodes) {
46  if (!node.isFree)
47  //node.target->ResampleWithConfidence();
48  node.target->ResampleWithBest();
49  }
50  }
51 
52  inline bool GetTarget(int index, Rect &t) const {
53  if (listNodes[index].isFree) {
54  return false;
55  }
56  else {
57  t = listNodes[index].target->GetTarget();
58  }
59  }
60 
61  inline int GetCapacity() const {
62  return capacity;
63  }
64 
72  void CalculateMatchScore(const IntegralImage *intImage,
73  const Pool<Rect> &dets, std::vector<MatchMatrix::MatchScore> &matchMat) const;
74 
78  bool CheckNearbyTarget(const Rect &det, int distThre) const;
79 
80  // The array of nodes.
81  std::vector<TargetsFreeListNode> listNodes;
82  const int capacity;
83 
84  // Weight for detection term in particle observation.
85  const float detectionWeight;
86 
87  const std::vector<int> &GetMatchDets() { return matchDets; }
88 
92  void Train(const IntegralImage *intImage, const MultiSampler *multiSampler);
93  void Train(int idx, const IntegralImage *intImage, const SingleSampler *singleSampler);
94 
95  inline void DrawTargets(cv::Mat &img, int index = -1) const {
96  if (index < capacity && index >= 0 && !listNodes[index].isFree) {
97  listNodes[index].target->DrawTarget(img, listNodes[index].color);
98  }
99  else {
100  for (const auto &node : listNodes) {
101  if (!node.isFree)
102  node.target->DrawTarget(img, node.color);
103  }
104  }
105  }
106 
107  inline void DrawParticles(cv::Mat &img, int index = -1) const {
108 
109  // Here all the particles are black.
110  cv::Scalar black(0.0f, 0.0f, 0.0f);
111 
112  if (index < capacity && index >= 0 && !listNodes[index].isFree) {
113  listNodes[index].target->DrawParticles(img, black);
114  }
115  else {
116  for (const auto &node : listNodes) {
117  if (!node.isFree)
118  node.target->DrawParticles(img, black);
119  }
120  }
121  }
122 
123  inline void DrawParticlesWithConfidence(cv::Mat &img, int index = -1) const {
124  if (index < capacity && index >= 0 && !listNodes[index].isFree) {
125  listNodes[index].target->DrawParticlesWithConfidence(img, listNodes[index].color);
126  }
127  else {
128  for (const auto &node : listNodes) {
129  if (!node.isFree)
130  node.target->DrawParticlesWithConfidence(img, node.color);
131  }
132  }
133  }
134 
135  inline void DrawMatches(cv::Mat &img, Pool<Rect> dets) {
136  for (int i = 0; i < capacity; i++) {
137  if (!listNodes[i].isFree && matchDets[i] != -1) {
138  // We have a matched detection.
139  // Draw the detection.
140  cv::rectangle(img, (cv::Rect)dets[matchDets[i]], listNodes[i].color, 2);
141  }
142  }
143  }
144 
145  // The (detection, target) pair.
146  // Set by MatchMatrix.
147  std::vector<int> matchDets;
148 
149 private:
150 
151  TargetsFreeListNode *freeNodes;
152 };
153 
154 
155 #endif
Definition: TargetsFreeList.h:12
Definition: TargetsFreeList.h:22
void ResetOneTarget(int index)
Definition: TaregetsFreeList.cpp:30
void CalculateMatchScore(const IntegralImage *intImage, const Pool< Rect > &dets, std::vector< MatchMatrix::MatchScore > &matchMat) const
Definition: TaregetsFreeList.cpp:63
Definition: SingleTarget.h:36
Definition: Geometry.h:34
Definition: MultiSampler.h:18
void Observe(const IntegralImage *intImage, const Pool< Rect > &detections)
Definition: TaregetsFreeList.cpp:81
Definition: Geometry.h:14
void Train(const IntegralImage *intImage, const MultiSampler *multiSampler)
Definition: TaregetsFreeList.cpp:109
bool CheckNearbyTarget(const Rect &det, int distThre) const
Definition: TaregetsFreeList.cpp:123
void Propagate(const Size &imgSize)
Definition: TaregetsFreeList.cpp:73
Definition: IntegralImage.h:11
Definition: SingleSampler.h:13
Definition: Geometry.h:69
Definition: Options.h:14