Skip to content

Commit e009fcf

Browse files
committed
Refactoring and fixes
1 parent cb7b5e2 commit e009fcf

15 files changed

Lines changed: 171 additions & 118 deletions

src/Detector/BaseDetector.h

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

128169
protected:
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

214255
private:

src/Detector/FaceDetector.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class FaceDetector final : public BaseDetector
1111
FaceDetector(const cv::UMat& gray);
1212
~FaceDetector(void) = default;
1313

14-
bool Init(const config_t& config);
14+
bool Init(const config_t& config) override;
1515

16-
void Detect(const cv::UMat& gray);
16+
void Detect(const cv::UMat& gray) override;
1717

18-
bool CanGrayProcessing() const
18+
bool CanGrayProcessing() const override
1919
{
2020
return true;
2121
}

src/Detector/MotionDetector.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
///
88
MotionDetector::MotionDetector(
99
BackgroundSubtract::BGFG_ALGS algType,
10-
cv::UMat& gray
11-
)
10+
cv::UMat& gray)
1211
:
1312
BaseDetector(gray),
1413
m_algType(algType)
@@ -71,6 +70,8 @@ void MotionDetector::DetectContour()
7170
void MotionDetector::Detect(const cv::UMat& gray)
7271
{
7372
m_backgroundSubst->Subtract(gray, m_fg);
73+
if (!m_ignoreMask.empty())
74+
cv::bitwise_and(m_fg, m_ignoreMask, m_fg);
7475

7576
DetectContour();
7677
}
@@ -117,4 +118,10 @@ void MotionDetector::CalcMotionMap(cv::Mat& frame)
117118
++moPtr;
118119
}
119120
}
121+
122+
#if 0
123+
std::cout << "m_ignoreMask = " << m_ignoreMask.size() << std::endl;
124+
if (!m_ignoreMask.empty())
125+
cv::imshow("ignoreMask", m_ignoreMask);
126+
#endif
120127
}

src/Detector/MotionDetector.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ class MotionDetector final : public BaseDetector
1212
MotionDetector(BackgroundSubtract::BGFG_ALGS algType, cv::UMat& gray);
1313
~MotionDetector(void) = default;
1414

15-
bool Init(const config_t& config);
15+
bool Init(const config_t& config) override;
1616

17-
void Detect(const cv::UMat& gray);
17+
void Detect(const cv::UMat& gray) override;
1818

19-
bool CanGrayProcessing() const
20-
{
21-
return true;
22-
}
19+
bool CanGrayProcessing() const override
20+
{
21+
return true;
22+
}
2323

24-
void CalcMotionMap(cv::Mat& frame);
24+
void CalcMotionMap(cv::Mat& frame) override;
2525

26-
void ResetModel(const cv::UMat& img, const cv::Rect& roiRect);
26+
void ResetModel(const cv::UMat& img, const cv::Rect& roiRect) override;
2727

2828
private:
2929
void DetectContour();

src/Detector/OCVDNNDetector.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class OCVDNNDetector final : public BaseDetector
1616
OCVDNNDetector(const cv::UMat& colorFrame);
1717
~OCVDNNDetector(void) = default;
1818

19-
bool Init(const config_t& config);
19+
bool Init(const config_t& config) override;
2020

21-
void Detect(const cv::UMat& colorFrame);
21+
void Detect(const cv::UMat& colorFrame) override;
2222

23-
bool CanGrayProcessing() const
23+
bool CanGrayProcessing() const override
2424
{
2525
return false;
2626
}

src/Detector/PedestrianDetector.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ class PedestrianDetector final : public BaseDetector
1818
PedestrianDetector(const cv::UMat& gray);
1919
~PedestrianDetector(void) = default;
2020

21-
bool Init(const config_t& config);
21+
bool Init(const config_t& config) override;
2222

23-
void Detect(const cv::UMat& gray);
23+
void Detect(const cv::UMat& gray) override;
2424

25-
bool CanGrayProcessing() const
26-
{
27-
return true;
28-
}
25+
bool CanGrayProcessing() const override
26+
{
27+
return true;
28+
}
2929

3030
private:
3131
DetectorTypes m_detectorType = HOG;

src/Detector/YoloDarknetDetector.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ class YoloDarknetDetector final : public BaseDetector
1616
{
1717
public:
1818
YoloDarknetDetector(const cv::UMat& colorFrame);
19-
~YoloDarknetDetector(void) = default;
19+
~YoloDarknetDetector(void) = default;
2020

21-
bool Init(const config_t& config);
21+
bool Init(const config_t& config) override;
2222

23-
void Detect(const cv::UMat& colorFrame);
24-
void Detect(const std::vector<cv::UMat>& frames, std::vector<regions_t>& regions);
23+
void Detect(const cv::UMat& colorFrame) override;
24+
void Detect(const std::vector<cv::UMat>& frames, std::vector<regions_t>& regions) override;
2525

26-
bool CanGrayProcessing() const
27-
{
28-
return false;
29-
}
26+
bool CanGrayProcessing() const override
27+
{
28+
return false;
29+
}
3030

3131
private:
3232
std::unique_ptr<Detector> m_detector;

src/Detector/YoloTensorRTDetector.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ class YoloTensorRTDetector final : public BaseDetector
1212
YoloTensorRTDetector(const cv::UMat& colorFrame);
1313
~YoloTensorRTDetector(void) = default;
1414

15-
bool Init(const config_t& config);
15+
bool Init(const config_t& config) override;
1616

17-
void Detect(const cv::UMat& colorFrame);
18-
void Detect(const std::vector<cv::UMat>& frames, std::vector<regions_t>& regions);
17+
void Detect(const cv::UMat& colorFrame) override;
18+
void Detect(const std::vector<cv::UMat>& frames, std::vector<regions_t>& regions) override;
1919

20-
bool CanGrayProcessing() const
20+
bool CanGrayProcessing() const override
2121
{
2222
return false;
2323
}

src/Detector/tensorrt_yolo/class_yolo_detector.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,8 @@
2020
class YoloDectector
2121
{
2222
public:
23-
YoloDectector()
24-
{
25-
26-
}
27-
~YoloDectector()
28-
{
29-
30-
}
23+
YoloDectector() = default;
24+
~YoloDectector() = default;
3125

3226
void init(const tensor_rt::Config &config)
3327
{

src/Tracker/Ctracker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CTracker final : public BaseTracker
4646

4747
///
4848
/// \brief CTracker::CTracker
49-
/// Tracker. Manage tracks. Create, remove, update.
49+
/// Manage tracks: create, remove, update.
5050
/// \param settings
5151
///
5252
CTracker::CTracker(const TrackerSettings& settings)

0 commit comments

Comments
 (0)