forked from zk00006/OpenTLD
-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathMedianFlowTracker.cpp
More file actions
92 lines (74 loc) · 2.29 KB
/
Copy pathMedianFlowTracker.cpp
File metadata and controls
92 lines (74 loc) · 2.29 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* Copyright 2011 AIT Austrian Institute of Technology
*
* This file is part of OpenTLD.
*
* OpenTLD is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenTLD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenTLD. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* MedianFlowTracker.cpp
*
* Created on: Nov 17, 2011
* Author: Georg Nebehay
*/
#include "MedianFlowTracker.h"
#include <cmath>
#include "FBTrack.h"
using namespace cv;
namespace tld
{
MedianFlowTracker::MedianFlowTracker()
{
trackerBB = NULL;
}
MedianFlowTracker::~MedianFlowTracker()
{
cleanPreviousData();
}
void MedianFlowTracker::cleanPreviousData()
{
delete trackerBB;
trackerBB = NULL;
}
void MedianFlowTracker::track(const Mat &prevMat, const Mat &currMat, Rect *prevBB)
{
if(prevBB != NULL)
{
if(prevBB->width <= 0 || prevBB->height <= 0)
{
return;
}
float bb_tracker[] = {(float)prevBB->x, (float)prevBB->y, (float)(prevBB->width + prevBB->x - 1), (float)(prevBB->height + prevBB->y - 1)};
float scale;
IplImage prevImg = prevMat;
IplImage currImg = currMat;
int success = fbtrack(&prevImg, &currImg, bb_tracker, bb_tracker, &scale);
//Extract subimage
float x, y, w, h;
x = floor(bb_tracker[0] + 0.5);
y = floor(bb_tracker[1] + 0.5);
w = floor(bb_tracker[2] - bb_tracker[0] + 1 + 0.5);
h = floor(bb_tracker[3] - bb_tracker[1] + 1 + 0.5);
//TODO: Introduce a check for a minimum size
if(!success || x < 0 || y < 0 || w <= 0 || h <= 0 || x + w > currMat.cols || y + h > currMat.rows || x != x || y != y || w != w || h != h) //x!=x is check for nan
{
//Leave it empty
}
else
{
trackerBB = new Rect(x, y, w, h);
}
}
}
} /* namespace tld */