醉了,写综述看几十页的原论文也就算了,论文里居然没把问题表达清楚,还好源码开源了,不然都不知道到时候怎么 si 的。

原文是:

As static trajectories do not contain motion information, we prune them in a post-processing stage. Trajectories with sudden large displacements, most likely to be erroneous, are also removed. Such trajectories are detected, if the displacement vector between two consecutive frames is larger than 70% of the overall displacement of the trajectory.

代码开源在:Dense Trajectories Video Description

其中的轨迹筛选源码在#include "Descriptors.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
// check whether a trajectory is valid or not
bool IsValid(std::vector<Point2f>& track, float& mean_x, float& mean_y, float& var_x, float& var_y, float& length)
{
int size = track.size();
float norm = 1./size;
for(int i = 0; i < size; i++) {
mean_x += track[i].x;
mean_y += track[i].y;
}
mean_x *= norm;
mean_y *= norm;

for(int i = 0; i < size; i++) {
float temp_x = track[i].x - mean_x;
float temp_y = track[i].y - mean_y;
var_x += temp_x*temp_x;
var_y += temp_y*temp_y;
}
var_x *= norm;
var_y *= norm;
var_x = sqrt(var_x);
var_y = sqrt(var_y);

// remove static trajectory
if(var_x < min_var && var_y < min_var)
return false;
// remove random trajectory
if( var_x > max_var || var_y > max_var )
return false;

float cur_max = 0;
for(int i = 0; i < size-1; i++) {
track[i] = track[i+1] - track[i];
float temp = sqrt(track[i].x*track[i].x + track[i].y*track[i].y);

length += temp;
if(temp > cur_max)
cur_max = temp;
}

if(cur_max > max_dis && cur_max > length*0.7)
return false;

track.pop_back();
norm = 1./length;
// normalize the trajectory
for(int i = 0; i < size-1; i++)
track[i] *= norm;

return true;
}

然后加一点自己的注释。

首先有一些变量,在#include "DenseTrack.h"中定义的:

1
2
3
4
// parameters for rejecting trajectory
const float min_var = sqrt(3);
const float max_var = 50;
const float max_dis = 20;

这三个代表最小位移的阈值最大位移的阈值条件筛选阈值。第三个可能有点懵逼,看代码:

1
2
3
4
5
6
// remove static trajectory
if(var_x < min_var && var_y < min_var)
return false;
// remove random trajectory
if( var_x > max_var || var_y > max_var )
return false;

这个就是前两句了:

As static trajectories do not contain motion information, we prune them in a post-processing stage. Trajectories with sudden large displacements, most likely to be erroneous, are also removed.

不怎么动的,和运动幅度过大的,都会被剔除。

然后就是第三个:

1
2
if(cur_max > max_dis && cur_max > length*0.7)
return false;

Such trajectories are detected, if the displacement vector between two consecutive frames is larger than 70% of the overall displacement of the trajectory.

这句话我以为是在说把符合这个条件的选出来(作为轨迹),没想到这也是剔除项,这没有源码谁能发现的了啊!

也就是说,如果相邻两帧之间的最大位移向量大于总位移轨迹的70%,那么这样的轨迹也会被检测到(并剔除)。

不过这个有一个先决条件cur_max > max_dis,猜测可能的原因是保证一些细节吧?大概有些单次位移虽然很大,但是我想不出来为什么这样了= =!

以上,如果有人碰巧看到了,有什么错误欢迎指正,感恩。