I want to track every pixel as feature point for temporal window of 15 frames using Farneback Dense optical flow. Using flow=cv2.calcOpticalFlowFarneback(prvs,next,None,0.5,3,15,3,5,1.2,0) , it shows dx and dy of every pixel in previous frame. Here I want to track certain feature point pixel over 15 frames and find the speed of that feature point.
How can speed can be estimated by dense optical flow of a feature point with a sequence of spatial locations over time with trajectory legth L ?
You already have dx and dy. With this information you can always have the velocity of such pixel if you know the time t
.
vx = dx / t
vy = dy / t
dx and dy can be negative, therefore it will keep kind of the orientation... remember that the origin is the top left corner and points right and down.
This way you can have the speed of each pixel per frame per dimension. You can always do a follow up of the pixel and calculate its trajectory length and divide it over time, you can say is the average speed of the pixel in a way.
For that you calculate the length of each point in the trajectory:
length = sqrt(dx**2 + dy**2)
and add them following the pixel, by that i mean something like:
totalLength = length(prev1[y,x]) + length(prev2[y+prev1[y,x][1], prev2[x+prev1[y,x]][0]]) ....
and then divide totalLength with the time.
If you want the speed of the total displacement, by that I mean the speed from the initial point till the end point (could be 0 if the pixel go back and forth) then just track the pixel by adding the displacements and then calculate the speed.
disp = (x,y) + prev1[y,x] + prev2[y,x] ...
speed = disp / t
I hope this helps you, if not jsut leave a comment.