Is it possible to extract the fall velocity of a ball using an opticalflow function in matlab's computer vision toolbox?

Viewed 21

In matlab's computer vision toolbox, I want to measure the velocity of a ball as it falls through water using the opticalflow function.

Currently, using the code I made, optical flow is applied to the entire video screen, so only the speed of the ball cannot be measured.

I want to assign an object to a ball and only apply opticalflow to the ball to get the fall velocity.

How can I apply opticalflow by assigning an object to only the ball?

v = VideoReader('sphere.avi');

v.CurrentTime

videoPlayer = vision.VideoPlayer('Position',[100,0,800,900]);


opticFlow = opticalFlowFarneback;

h = figure;

movegui(h);

hViewPanel = uipanel(h,'Position',[0 0 1 1],'Title','Plot of Optical Flow Vectors');
hPlot = axes(hViewPanel);


while hasFrame(v)

   frameRGB = readFrame(v);
   frameGrey = im2gray(frameRGB);
   flow = estimateFlow(opticFlow,frameGrey);

   imshow(frameRGB);
   title(sprintf('Current Time = %.3f sec', v.CurrentTime));
   hold on
   plot(flow,'decimationfactor',[5 5],'scaleFactor',2,'Parent',hPlot);
   hold off
   pause(10^-3)
   
end

release(videoPlayer);

enter image description here

0 Answers
Related