I would like to compute velocity of key feature points and set thresholding for motion detection in a video.
I have a python code with me as follows:
def compute_vel_kf(self, fps):
if ((len(self.features) == 0) or (self.features == None)):
return;
test_image = self.current_frame.copy();
time_diff_in_sec = 1/fps;
self.v = [];
for i, p1 in enumerate(self.features):
p2 = self.features_prev[i];
# speed = dist/time
vx, vy = [(p1[0][0] - p2[0][0]), (p1[0][1] - p2[0][1])];
v = sqrt(vx * vx + vy * vy)*fps;
ang = math.atan2(vy, vx);
self.v.append(array([v, ang]));
i += 1;
return self.v;
I have to port it to cpp code. In cpp code i have used points[1] and points[2] that holds current frame & previous frame detected points respectively. I need to calculate velocity of the detected key feature points.