I am trying to see the velocity of an object by using Matlab so I came up with this code
reader = vision.VideoFileReader ('C:\folder1\objectsandflow.avi');
viewer = vision.DeployableVideoPlayer;
optical = vision.OpticalFlow;
optical.OutputValue = 'Horizontal and vertical components in complex form';
videoPlayer = vision.VideoPlayer('Name','Motion Vector');
while isDone (reader)
I = step(reader);
of = step (optical, rgb2gray(I));
y = of .* conj(of);
step(viewThresh,y>mean(y(:)));
step(videoPlayer)
end
release(videoPlayer);
release(reader);
The problem is I cannot see either the values of the flow (I mean I am looking for the velocity of some objects and I can use Matlab for it, can I?), nor the video
At the same time I do not know whether this will work to calculate all the velocities of my objects in the case that this code can't, how can I calculate multiple velocities in Matlab?
Your problem is in these two lines:
step(viewThresh,y>mean(y(:)));
step(videoPlayer)
Try replacing them with these:
viewThresh = y;
viewThresh(y < mean(y(:))) = 0;
step(videoPlayer, viewThresh);
You do not need the step
method for thresholding y
, because you are not using any objects. And when you call step
on the videoPlayer
object, you have to pass in the video frame you wish to display.