33 inline ostream& operator<<(ostream& os,
const ViBeBase& vibe) {
53 numberOfSamples(DEFAULT_NUMBER_OF_SAMPLES),
54 matchingThreshold(DEFAULT_MATCHING_THRESHOLD),
55 matchingNumber(DEFAULT_MATCHING_NUMBER),
56 updateFactor(DEFAULT_UPDATE_FACTOR),
57 stride(width * channels),
58 pixels(height * width),
59 numValues(height * width * channels),
62 lastHistoryImageSwapped(),
79 const uint32_t COLUMNS = width * channels;
82 historyImage =
new uint8_t[NUMBER_OF_HISTORY_IMAGES * COLUMNS * height];
84 for (uint32_t i = 0; i < NUMBER_OF_HISTORY_IMAGES; ++i) {
85 for (int32_t index = COLUMNS * height - 1; index >= 0; --index)
86 historyImage[i * COLUMNS * height + index] = buffer[index];
91 new uint8_t[COLUMNS * height * (numberOfSamples - NUMBER_OF_HISTORY_IMAGES)];
93 for (int32_t index = COLUMNS * height - 1; index >= 0; --index) {
94 uint8_t value = buffer[index];
96 for (uint32_t x = 0; x < numberOfSamples - NUMBER_OF_HISTORY_IMAGES; ++x) {
97 historyBuffer[index * (numberOfSamples - NUMBER_OF_HISTORY_IMAGES) + x] =
100 static_cast<int32_t>(value) + rand() % 20 - 10,
101 static_cast<int32_t
>(BACKGROUND)
103 static_cast<int32_t
>(FOREGROUND)
109 int32_t size = (width > height) ? 2 * width + 1 : 2 * height + 1;
111 jump =
new uint32_t[size];
112 neighbor =
new int32_t[size];
113 position =
new uint32_t[size];
115 for (int32_t i = 0; i < size; ++i) {
117 jump[i] = (rand() % (2 * updateFactor)) + 1;
119 neighbor[i] = ((rand() % 3) - 1) + ((rand() % 3) - 1) * width;
121 position[i] = rand() % numberOfSamples;
127 ViBeBase::~ViBeBase() {
128 delete[] historyImage;
129 delete[] historyBuffer;
137 uint32_t ViBeBase::getNumberOfSamples()
const {
138 return numberOfSamples;
143 uint32_t ViBeBase::getMatchingThreshold()
const {
144 return matchingThreshold;
149 void ViBeBase::setMatchingThreshold(int32_t matchingThreshold) {
150 if (matchingThreshold <= 0)
153 this->matchingThreshold = matchingThreshold;
158 uint32_t ViBeBase::getMatchingNumber()
const {
159 return matchingNumber;
164 void ViBeBase::setMatchingNumber(int32_t matchingNumber) {
165 if (matchingNumber <= 0)
168 this->matchingNumber = matchingNumber;
173 uint32_t ViBeBase::getUpdateFactor()
const {
179 void ViBeBase::setUpdateFactor(int32_t updateFactor) {
180 if (updateFactor <= 0)
183 this->updateFactor = updateFactor;
186 int32_t size = 2 * max(width, height) + 1;
188 for (int32_t i = 0; i < size; ++i) {
190 jump[i] = (updateFactor == 1) ? 1 : (rand() % (2 * updateFactor)) + 1;
196 void ViBeBase::print(ostream& os)
const {
197 os <<
" - Number of samples per pixel : " << numberOfSamples << endl;
198 os <<
" - Number of matches needed : " << matchingNumber << endl;
199 os <<
" - Matching threshold : " << matchingThreshold << endl;
200 os <<
" - Model update subsampling factor: " << updateFactor ;
Interface to the ViBe class.