forked from taygunk/multiple-tracking-master
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeanBGS.hpp
82 lines (60 loc) · 1.95 KB
/
MeanBGS.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/****************************************************************************
*
* MeanBGS.hpp
*
* Purpose: Implementation of a simple temporal mean background
* subtraction algorithm.
*
* Author: Donovan Parks, September 2007
*
Example:
Algorithms::BackgroundSubtraction::MeanParams params;
params.SetFrameSize(width, height);
params.LowThreshold() = 3*30*30;
params.HighThreshold() = 2*params.LowThreshold(); // Note: high threshold is used by post-processing
params.Alpha() = 1e-6f;
params.LearningFrames() = 30;
Algorithms::BackgroundSubtraction::MeanBGS bgs;
bgs.Initalize(params);
******************************************************************************/
#include "Bgs.hpp"
namespace Algorithms
{
namespace BackgroundSubtraction
{
// --- Parameters used by the Mean BGS algorithm ---
class MeanParams : public BgsParams
{
public:
unsigned int &LowThreshold() { return m_low_threshold; }
unsigned int &HighThreshold() { return m_high_threshold; }
float &Alpha() { return m_alpha; }
int &LearningFrames() { return m_learning_frames; }
private:
// A pixel is considered to be from the background if the squared distance between
// it and the background model is less than the threshold.
unsigned int m_low_threshold;
unsigned int m_high_threshold;
float m_alpha;
int m_learning_frames;
};
// --- Mean BGS algorithm ---
class MeanBGS : public Bgs
{
public:
virtual ~MeanBGS() {}
void Initalize(const BgsParams& param);
void InitModel(const RgbImage& data);
void Subtract(int frame_num, const RgbImage& data,
BwImage& low_threshold_mask, BwImage& high_threshold_mask);
void Update(int frame_num, const RgbImage& data, const BwImage& update_mask);
RgbImage* Background() { return &m_background; }
private:
void SubtractPixel(int r, int c, const RgbPixel& pixel,
unsigned char& lowThreshold, unsigned char& highThreshold);
MeanParams m_params;
RgbImageFloat m_mean;
RgbImage m_background;
};
};
};