-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracker.cpp
64 lines (52 loc) · 1.42 KB
/
tracker.cpp
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
#include "pch.h"
#include "tracker.h"
tracker::tracker()
{
// The input image frame size (resolution).
img_shape[0] = 0;
img_shape[1] = 0;
init_center[0] = 0;
init_center[1] = 0;
}
tracker::tracker(int img_width, int img_height)
{
img_shape[0] = img_width;
img_shape[1] = img_height;
init_center[0] = img_width / 2;
init_center[1] = img_height / 2;
this->default_bbox_creator();
}
tracker::~tracker()
{
}
void tracker::bbox_creator(int crop_size)
{
// Update prev_crop_size using the newly calculated crop_size.
prev_crop_size = alpha *crop_size + (1-alpha)*prev_crop_size;
// Define the new bounding box around the current center point.
int cx = current_center[0] - (prev_crop_size / 2);
if (cx < 0) cx = 0;
int cy = current_center[1] - (prev_crop_size / 2);
if (cy < 0) cy = 0;
if (current_center[0] + (prev_crop_size / 2) > img_shape[0] - 1)
{
cx = img_shape[0] - prev_crop_size;
}
else if (current_center[1] + (prev_crop_size / 2) > img_shape[1] - 1)
{
cy = img_shape[1] - prev_crop_size;
}
bbox[0] = cx;
bbox[1] = cy;
bbox[2] = prev_crop_size;
bbox[3] = prev_crop_size;
}
void tracker::default_bbox_creator()
{
bbox[0] = init_center[0] - (img_shape[1] / 4);
bbox[1] = init_center[1] - (img_shape[1] / 4);
bbox[2] = default_crop_size;
bbox[3] = default_crop_size;
current_center[0] = init_center[0];
current_center[1] = init_center[1];
}