Warp images using motion maps generated by optical FlowLKDoG (Matlab 2015A)

This question is based on modified Matlab code from online documentation for optical flow system objects in 2015a version as shown in opticalFlowLK class

clc; clearvars; close all;
inputVid = VideoReader('viptraffic.avi');
opticFlow = opticalFlowLKDoG('NumFrames',3);
inputVid.currentTime = 2;
k = 1;
while inputVid.currentTime<=2 + 1/inputVid.FrameRate
 frameRGB{k} = readFrame(inputVid);
 frameGray{k} = rgb2gray(frameRGB{k});    
 flow{k} = estimateFlow(opticFlow,frameGray{k});
 k = k+1;
end

      

Let's look at stream {2} .Vx and stream {2}. We get U and V motion maps that describe motion from frameGray {1} to frameGray {2}.

I want to use stream {2} .Vx and stream {2}. Directly onto the data in frameGray {1} to convert frameGray {1}, which visually resembles frameGray {2}.

I tried this code:

[x, y] = meshgrid(1:size(frameGray{1},2), 1:size(frameGray{1},1));
frameGray1Warped = interp2(double(frameGray{1}) , x-flow{2}.Vx , y-flow{2}.Vy);

      

But it doesn't seem to do anything at all other than ruining the image quality (but objects do not display any real movement in relation to their locations in frameGray {2}.

I added 3 images showing 2 original frames, followed by frame 1 distorted using a motion field similar to frame 2:

frame 1

frame 2

frame 1 warped to 2

It is easy to see that frame 1, deformed to 2, is essentially frame 1 of degraded quality, but the machines did not move at all. That is - the location of the cars is the same: look at the car closest to the camera relative to the road dividing line next to it; it is practically the same as in frame 1, and frame 1, distorted to 2, but in frame 2 is completely different.

+3


source to share





All Articles