| 150 | |
| 151 | /// |
| 152 | void VIBE::ResetModel(const cv::Mat& img, const cv::Rect& roiRect) |
| 153 | { |
| 154 | const int top = std::max(0, roiRect.y); |
| 155 | const int bottom = std::min(img.rows, roiRect.y + roiRect.height); |
| 156 | const int left = std::max(0, roiRect.x); |
| 157 | const int right = std::min(img.cols, roiRect.x + roiRect.width); |
| 158 | for (int i = top; i < bottom; i++) |
| 159 | { |
| 160 | const uchar* img_ptr = img.ptr(i) + m_channels * left; |
| 161 | uchar* mask_ptr = m_mask.ptr(i) + left; |
| 162 | |
| 163 | for (int j = left; j < right; j++) |
| 164 | { |
| 165 | if (*mask_ptr) |
| 166 | { |
| 167 | int matching_counter = 0; |
| 168 | model_t::value_type* model_ptr = &m_model[m_channels * m_samples * m_size.width * i + m_channels * m_samples * j]; |
| 169 | for (size_t s = 0; s < m_samples; ++s) |
| 170 | { |
| 171 | size_t channels_counter = 0; |
| 172 | for (size_t c = 0; c < m_channels; ++c) |
| 173 | { |
| 174 | if (std::abs((int)model_ptr[c] - img_ptr[c]) >= m_distanceThreshold) |
| 175 | { |
| 176 | model_ptr[c] = img_ptr[c]; |
| 177 | ++channels_counter; |
| 178 | } |
| 179 | } |
| 180 | if (channels_counter == m_channels) |
| 181 | { |
| 182 | if (++matching_counter > m_matchingThreshold) |
| 183 | break; |
| 184 | } |
| 185 | model_ptr += m_channels; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | img_ptr += m_channels; |
| 190 | ++mask_ptr; |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | } |