@@ -50,14 +50,50 @@ class BaseDetector
5050 }
5151 }
5252
53+ // /
54+ // / \brief ResetModel
55+ // / \param img
56+ // / \param roiRect
57+ // /
58+ virtual void ResetModel (const cv::UMat& /* img*/ , const cv::Rect& /* roiRect*/ )
59+ {
60+ }
61+
62+ // /
63+ // / \brief ResetIgnoreMask
64+ // /
65+ virtual void ResetIgnoreMask ()
66+ {
67+ if (!m_ignoreMask.empty ())
68+ m_ignoreMask = 255 ;
69+ }
70+
5371 // /
54- // / \brief ResetModel
72+ // / \brief UpdateIgnoreMask
5573 // / \param img
5674 // / \param roiRect
5775 // /
58- virtual void ResetModel (const cv::UMat& /* img*/ , const cv::Rect& /* roiRect*/ )
76+ virtual void UpdateIgnoreMask (const cv::UMat& img, cv::Rect roiRect)
5977 {
60- }
78+ if (m_ignoreMask.empty ())
79+ m_ignoreMask = cv::Mat (img.size (), CV_8UC1 , cv::Scalar (255 ));
80+
81+ auto Clamp = [](int & v, int & size, int hi)
82+ {
83+ if (v < 0 )
84+ {
85+ size += v;
86+ v = 0 ;
87+ }
88+ else if (v + size > hi - 1 )
89+ {
90+ size = hi - 1 - v;
91+ }
92+ };
93+ Clamp (roiRect.x , roiRect.width , m_ignoreMask.cols );
94+ Clamp (roiRect.y , roiRect.height , m_ignoreMask.rows );
95+ m_ignoreMask (roiRect) = 0 ;
96+ }
6197
6298 // /
6399 // / \brief CanGrayProcessing
@@ -100,7 +136,8 @@ class BaseDetector
100136 cv::ellipse (foreground, region.m_rrect , cv::Scalar (255 , 255 , 255 ), cv::FILLED );
101137#endif
102138 }
103-
139+ if (!m_ignoreMask.empty ())
140+ cv::bitwise_and (foreground, m_ignoreMask, foreground);
104141 cv::normalize (foreground, m_normFor, 255 , 0 , cv::NORM_MINMAX , m_motionMap.type ());
105142
106143 double alpha = 0.95 ;
@@ -123,18 +160,24 @@ class BaseDetector
123160 ++moPtr;
124161 }
125162 }
163+ #if 0
164+ if (!m_ignoreMask.empty())
165+ cv::imshow("ignoreMask", m_ignoreMask);
166+ #endif
126167 }
127168
128169protected:
129170 regions_t m_regions;
130171
131172 cv::Size m_minObjectSize;
132173
133- // Motion map for visualization current detections
174+ cv::Mat m_ignoreMask;
175+
176+ // Motion map for visualization current detections
134177 cv::Mat m_motionMap;
135- cv::Mat m_normFor;
178+ cv::Mat m_normFor;
136179
137- std::set<objtype_t > m_classesWhiteList;
180+ std::set<objtype_t > m_classesWhiteList;
138181
139182 std::vector<cv::Rect> GetCrops (float maxCropRatio, cv::Size netSize, cv::Size imgSize) const
140183 {
@@ -205,10 +248,8 @@ class BaseDetector
205248 // /
206249 objtype_t T2T (size_t typeInd) const
207250 {
208- if (typeInd < m_typesMap.size ())
209- return m_typesMap[typeInd];
210- else
211- return bad_type;
251+ objtype_t res = (typeInd < m_typesMap.size ()) ? m_typesMap[typeInd] : bad_type;
252+ return res;
212253 }
213254
214255private:
0 commit comments