I have two images (frame1 and frame2) and I am able to calculate u,v using opencv:
flow = cv2.calcOpticalFlowFarneback(prvs,next, 0.5, 1, 3, 15, 3, 5, 1, 0)
I want to translate frame1 using this u,v to quantify the quality of the difference using various optical flow methods. I intend to extrapolate using these u,v.
Is there a simple way to achieve this?
One way to compute a simple translation is to average the flow:
This gives the vector
(avg_u, avg_v)
needed to translate.Regarding your comments, it seems you want to move every pixel
(x,y)
to the location specified by its flow vector(u(x,y), v(x,y))
.First, generate a Cartesian grid:
Then, the desired mapping is simply the addition of this grid with the flow:
Finally, perform a
cv2.remap
: