forked from Smorodov/Multitarget-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetector.cpp
More file actions
56 lines (51 loc) · 1.39 KB
/
Detector.cpp
File metadata and controls
56 lines (51 loc) · 1.39 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "Detector.h"
CDetector::CDetector(cv::Mat& gray)
{
fg = gray.clone();
bs = new BackgroundSubtract;
bs->init(gray);
}
//----------------------------------------------------------------------
// Detector
//----------------------------------------------------------------------
void CDetector::DetectContour(cv::Mat& img, std::vector<cv::Rect>& Rects, std::vector<Point_t>& centers)
{
Rects.clear();
centers.clear();
std::vector<std::vector<cv::Point> > contours;
std::vector<cv::Vec4i> hierarchy;
cv::Mat edges = img.clone();
cv::Canny(img, edges, 50, 190, 3);
cv::findContours(edges, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cv::Point());
if (contours.size() > 0)
{
for (size_t i = 0; i < contours.size(); i++)
{
cv::Rect r = cv::boundingRect(contours[i]);
Rects.push_back(r);
centers.push_back((r.br() + r.tl())*0.5);
}
}
}
const std::vector<Point_t>& CDetector::Detect(cv::Mat& gray)
{
bs->subtract(gray, fg);
// rects - bounding rectangles
// centers - centers of bounding rectangles
/*
cv::Mat fg2;
fg.convertTo(fg2,CV_32FC1);
cv::GaussianBlur(fg2,fg2,Size(5,5),1.0);
cv::Laplacian(fg2,fg2,CV_32FC1);
normalize(fg2,fg2,0,255,cv::NORM_MINMAX);
fg2.convertTo(fg2,CV_8UC1);
cv::applyColorMap(fg2,fg2,COLORMAP_JET);
imshow("Foreground",fg2);
*/
DetectContour(fg, rects, centers);
return centers;
}
CDetector::~CDetector(void)
{
delete bs;
}