Skip to content

Commit 49919d4

Browse files
committed
Updated non maximum suppression function
1 parent 49887e8 commit 49919d4

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ In project uses libraries:
2727
- GTL: https://github.com/rdmpage/graph-template-library
2828
- MWBM: https://github.com/rdmpage/maximum-weighted-bipartite-matching
2929
- Pedestrians detector: https://github.com/sturkmen72/C4-Real-time-pedestrian-detection
30+
- Non Maximum Suppression: https://github.com/Nuzhny007/Non-Maximum-Suppression

main.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ void mv_MouseCallback(int event, int x, int y, int /*flags*/, void* param)
2727

2828
// ----------------------------------------------------------------------
2929
void nms(
30-
const std::vector<cv::Rect>& srcRects,
31-
std::vector<cv::Rect>& resRects,
32-
float thresh
33-
)
30+
const std::vector<cv::Rect>& srcRects,
31+
std::vector<cv::Rect>& resRects,
32+
float thresh,
33+
int neighbors = 0
34+
)
3435
{
3536
resRects.clear();
3637

@@ -54,7 +55,7 @@ void nms(
5455
auto lastElem = --std::end(idxs);
5556
const cv::Rect& rect1 = srcRects[lastElem->second];
5657

57-
resRects.push_back(rect1);
58+
int neigborsCount = 0;
5859

5960
idxs.erase(lastElem);
6061

@@ -71,12 +72,17 @@ void nms(
7172
if (overlap > thresh)
7273
{
7374
pos = idxs.erase(pos);
75+
++neigborsCount;
7476
}
7577
else
7678
{
7779
++pos;
7880
}
7981
}
82+
if (neigborsCount >= neighbors)
83+
{
84+
resRects.push_back(rect1);
85+
}
8086
}
8187
}
8288

@@ -583,7 +589,7 @@ void PedestrianDetector(int argc, char** argv)
583589
scanner.FastScan(original, foundRects, 2);
584590
#endif
585591

586-
nms(foundRects, filteredRects, 0.3f);
592+
nms(foundRects, filteredRects, 0.3f, 1);
587593

588594
for (auto rect : filteredRects)
589595
{

0 commit comments

Comments
 (0)