PedestrainCounting
MultiSampler.h
1 
7 #ifndef MULTI_SAMPLER_HEADER
8 #define MULTI_SAMPLER_HEADER
9 
10 #include "GlobalHeader.h"
11 #include "Options.h"
12 #include "Geometry.h"
13 #include "Pool.h"
14 
15 // Const number of samples per targets.
16 #define MULTI_SAMPLER_SAMPLES 5
17 
18 class MultiSampler {
19 public:
20  MultiSampler(const Options &opts);
21  ~MultiSampler();
22 
28  void Sample(const std::vector<int> &matchDets, const Pool<Rect> &detections, const Size &imgSize);
29 
38  public:
39  typedef const_iterator self_type;
40  typedef const Rect value_type;
41  typedef const Rect& reference;
42  typedef std::vector<Rect>::const_pointer pointer;
43  typedef int difference_type;
44  typedef std::input_iterator_tag iterator_category;
45  const_iterator(pointer p,
46  int t,
47  int l,
48  bool *m) : ptr(p), target(t), mask(m), length(l) {}
49  self_type operator++() {
50 
51  self_type old = *this;
52 
53  // First add one.
54  i++;
55  ptr++;
56 
57  // Check if this is a valid one.
58  while (i < length && !mask[i]) {
59  i++;
60  ptr++;
61  }
62  return old;
63  }
64  reference operator*() { return *ptr; }
65  pointer operator->() { return ptr; }
66  bool operator==(const self_type& rhs) { return ptr == rhs.ptr; }
67  bool operator!=(const self_type& rhs) { return ptr != rhs.ptr; }
68  int GetTarget() { return (target == (i / MULTI_SAMPLER_SAMPLES)) ? 1 : -1; }
69  private:
70  pointer ptr;
71  bool *mask;
72  int target;
73  int i;
74  int length;
75  };
76 
77  const_iterator begin(int target) const {
78  const_iterator iter = const_iterator(&samples[0], target, samples.size(), mask);
79 
80  // If the first target is unused, we have to move iter.
81  if (!mask[0]) {
82  iter++;
83  }
84 
85  return iter;
86  }
87  const_iterator end() const { return const_iterator(&samples[0] + samples.size(), -1, samples.size(), mask); }
88 
89 protected:
90 
91  int capacity;
92 
99  std::vector<Rect> samples;
100  bool *mask;
101 
102  static std::default_random_engine generator;
103  std::normal_distribution<float> gaussianWidth;
104  std::normal_distribution<float> gaussianHeight;
105 
106 };
107 
108 #endif
Definition: Geometry.h:34
Definition: MultiSampler.h:18
Definition: Geometry.h:14
Definition: MultiSampler.h:37
std::vector< Rect > samples
Definition: MultiSampler.h:99
void Sample(const std::vector< int > &matchDets, const Pool< Rect > &detections, const Size &imgSize)
Definition: MultiSampler.cpp:18
Definition: Options.h:14