-
Notifications
You must be signed in to change notification settings - Fork 0
/
Initialize.h
179 lines (161 loc) · 4.65 KB
/
Initialize.h
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#ifndef INITIALIZE_H_
#define INITIALIZE_H_
#include "DenseTrackStab.h"
#include <getopt.h>
void InitTrackInfo(TrackInfo* trackInfo, int track_length, int init_gap)
{
trackInfo->length = track_length;
trackInfo->gap = init_gap;
}
DescMat* InitDescMat(int height, int width, int nBins)
{
DescMat* descMat = (DescMat*)malloc(sizeof(DescMat));
descMat->height = height;
descMat->width = width;
descMat->nBins = nBins;
long size = height*width*nBins;
descMat->desc = (float*)malloc(size*sizeof(float));
memset(descMat->desc, 0, size*sizeof(float));
return descMat;
}
void ReleDescMat(DescMat* descMat)
{
if(descMat != NULL) {
if(descMat->desc != NULL)
free(descMat->desc);
free(descMat);
}
}
void InitDescInfo(DescInfo* descInfo, int nBins, bool isHof, int size, int nxy_cell, int nt_cell)
{
descInfo->nBins = nBins;
descInfo->isHof = isHof;
descInfo->nxCells = nxy_cell;
descInfo->nyCells = nxy_cell;
descInfo->ntCells = nt_cell;
descInfo->dim = nBins*nxy_cell*nxy_cell;
descInfo->height = size;
descInfo->width = size;
}
void InitSeqInfo(SeqInfo* seqInfo, char* video)
{
VideoCapture capture;
capture.open(video);
if(!capture.isOpened())
fprintf(stderr, "Could not initialize capturing..\n");
// get the number of frames in the video
int frame_num = 0;
while(true) {
Mat frame;
capture >> frame;
if(frame.empty())
break;
if(frame_num == 0) {
seqInfo->width = frame.cols;
seqInfo->height = frame.rows;
}
frame_num++;
}
seqInfo->length = frame_num;
}
void usage()
{
fprintf(stderr, "Extract improved trajectories from a video\n\n");
fprintf(stderr, "Usage: DenseTrackStab video_file [options]\n");
fprintf(stderr, "Options:\n");
fprintf(stderr, " -h Display this message and exit\n");
fprintf(stderr, " -S [start frame] The start frame to compute feature (default: S=0 frame)\n");
fprintf(stderr, " -E [end frame] The end frame for feature computing (default: E=last frame)\n");
fprintf(stderr, " -L [trajectory length] The length of the trajectory (default: L=15 frames)\n");
fprintf(stderr, " -W [sampling stride] The stride for dense sampling feature points (default: W=5 pixels)\n");
fprintf(stderr, " -N [neighborhood size] The neighborhood size for computing the descriptor (default: N=32 pixels)\n");
fprintf(stderr, " -s [spatial cells] The number of cells in the nxy axis (default: nxy=2 cells)\n");
fprintf(stderr, " -t [temporal cells] The number of cells in the nt axis (default: nt=3 cells)\n");
fprintf(stderr, " -A [scale number] The number of maximal spatial scales (default: 8 scales)\n");
fprintf(stderr, " -I [initial gap] The gap for re-sampling feature points (default: 1 frame)\n");
fprintf(stderr, " -v [verbose] Print descriptor vectors \n");
fprintf(stderr, " -p [disable video] Do not launch video player \n");
fprintf(stderr, " -x [HOG] Compute histogram of oriented gradients (default: true)\n");
fprintf(stderr, " -y [HOF] Compute histogram of optical flow (default: true)\n");
fprintf(stderr, " -z [MBH] Compute motion boundary histograms (default: true)\n");
}
bool arg_parse(int argc, char** argv)
{
int c;
bool flag = false;
bool single_option = true;
char* executable = basename(argv[0]);
while((c = getopt (argc, argv, "hS:E:L:W:N:s:t:A:I:H:pvxyz")) != -1)
{
switch(c) {
case 'S':
start_frame = atoi(optarg);
flag = true;
break;
case 'E':
end_frame = atoi(optarg);
flag = true;
break;
case 'L':
track_length = atoi(optarg);
break;
case 'W':
min_distance = atoi(optarg);
break;
case 'N':
patch_size = atoi(optarg);
break;
case 's':
nxy_cell = atoi(optarg);
break;
case 't':
nt_cell = atoi(optarg);
break;
case 'A':
scale_num = atoi(optarg);
break;
case 'I':
init_gap = atoi(optarg);
break;
case 'h':
usage();
exit(0);
break;
case 'p':
show_track = false;
break;
case 'v':
verbose_flag = true;
break;
case 'x':
if(single_option) {
HOF_flag = false;
MBH_flag = false;
}
HOG_flag = true;
single_option = false;
break;
case 'y':
if(single_option) {
HOG_flag = false;
MBH_flag = false;
}
HOF_flag = true;
single_option = false;
break;
case 'z':
if(single_option) {
HOG_flag = false;
HOF_flag = false;
}
MBH_flag = true;
single_option = false;
break;
default:
fprintf(stderr, "error parsing arguments at -%c\n Try '%s -h' for help.", c, executable );
abort();
}
}
return flag;
}
#endif /*INITIALIZE_H_*/