-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindPersonContour.cpp
More file actions
37 lines (25 loc) · 984 Bytes
/
FindPersonContour.cpp
File metadata and controls
37 lines (25 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "FindPersonContour.h"
#include "center.h"
using namespace cv;
using namespace std;
void findPersonContour(const Mat& inputFrame, vector<Rect>& outputCountors, vector<Center>& outputCenters)
{
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(inputFrame, contours, hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE);
vector<Point> contours_poly(4);
outputCountors.clear();
outputCenters.clear();
int m_maxObjectArea{50000};
int m_minObjectArea{10000};
for (auto contour : contours) {
approxPolyDP(Mat{contour}, contours_poly, 3, true);
Rect tmp{boundingRect(Mat{contours_poly})};
if (tmp.area() < m_maxObjectArea && tmp.area() > m_minObjectArea) {
outputCenters.push_back(
Center{(tmp.br() + tmp.tl()) *
0.5}); // save countour center
outputCountors.push_back(std::move(tmp)); // save countour
}
}
}