-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBioTrackerTrackingAlgorithm.cpp
More file actions
59 lines (45 loc) · 2.01 KB
/
Copy pathBioTrackerTrackingAlgorithm.cpp
File metadata and controls
59 lines (45 loc) · 2.01 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
57
58
59
#include "BioTrackerTrackingAlgorithm.h"
#include "Utility/TrackedComponents/TrackedComponentFactory.h"
#include <future>
#include <chrono>
BioTrackerTrackingAlgorithm::BioTrackerTrackingAlgorithm(IModel *parameter, IModel *trajectory)
{
_TrackingParameter = (TrackerParameter*)parameter;
_TrackedTrajectoryMajor = (TrackedTrajectory*)trajectory;
_imageX = 100;
_imageY = 100;
}
void BioTrackerTrackingAlgorithm::doTracking(std::shared_ptr<cv::Mat> p_image, uint framenumber)
{
auto start = std::chrono::high_resolution_clock::now();
//dont do nothing if we ain't got an image
if (p_image->empty()) {
return;
}
if (_imageX != p_image->size().width || _imageY != p_image->size().height) {
_imageX = p_image->size().width;
_imageY = p_image->size().height;
Q_EMIT emitDimensionUpdate(_imageX, _imageY);
}
using namespace cv;
cv::Mat imgHSV;
std::shared_ptr<cv::Mat> _imgTracked = std::make_shared<cv::Mat>();
cvtColor(*p_image, imgHSV,
COLOR_BGR2HSV); //Convert the captured frame from BGR to HSV
inRange(imgHSV, Scalar(_TrackingParameter->_lowH, _TrackingParameter->_lowS, _TrackingParameter->_lowV),
Scalar(_TrackingParameter->_highH, _TrackingParameter->_highS, _TrackingParameter->_highV),
*_imgTracked); //Threshold the image
//morphological opening (remove small objects from the foreground)
erode(*_imgTracked, *_imgTracked, getStructuringElement(MORPH_ELLIPSE, Size(5,
5)));
dilate(*_imgTracked, *_imgTracked, getStructuringElement(MORPH_ELLIPSE, Size(5,
5)));
//morphological closing (fill small holes in the foreground)
cv::dilate(*_imgTracked, *_imgTracked,
cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5)));
cv::erode(*_imgTracked, *_imgTracked, cv::getStructuringElement(cv::MORPH_ELLIPSE,
cv::Size(5, 5)));
Q_EMIT emitCvMatA(_imgTracked, QString("Tracked"));
Q_EMIT emitChangeDisplayImage("Tracked");
Q_EMIT emitTrackingDone(framenumber);
}