Optic flow Farnebeck: sorting vectors on quiver plot by the direction they are pointing

3 ビュー (過去 30 日間)
Rianne Stowell
Rianne Stowell 2018 年 5 月 17 日
編集済み: Rianne Stowell 2018 年 5 月 17 日
Hi all,
I am utilizing optic flow modeling to estimate the movement of cellular processes towards a central location (ie the site of an injury). I find that the the optic flow Farnebeck function does a great job of tracking this, however I need some help processing the output to answer my experimental question. The vectors generated by the function have magnitudes and orientations which are based upon local coordinates. I want to be able to sort the vectors by whether or not they are pointed at my spot of interest, with the current format of the data I can't get this information, I can only get the local orientations of the vectors.
Below is the code I am running:
close all
%Select folder (filepath) and file (imFileName) to open% [imFileName, filePath] = uigetfile('*.avi', 'Select timelapse .avi file to run...'); %adds the folder to the path so you can get back in there easily% addpath(filePath); if isempty (imFileName) error ('No file selected...'); end %The following defines my opened file as the variable Goat% Goat = imFileName; %The following code creates an optic flow video using the Farneback %method which tracks movement over my whole video file% vidReader = VideoReader(Goat); %set up optical flow object to do the estimate% opticFlow = opticalFlowFarneback; %Read in video frames and estimate optical flow of each frame. Display %the video frames with flow vectors%
xvel_export=[];yvel_export=[];mag_export=[];orient_export=[];
%Initialize an empty matrix to load values into.
figure1 = figure;
while hasFrame(vidReader)
frameRGB = readFrame(vidReader);
frameGray = rgb2gray(frameRGB);
figure,imshow(frameRGB(:,:,:))
flow = estimateFlow(opticFlow,frameGray);
imshow(frameRGB)
hold on
x_vel = [flow.Vx];
y_vel = [flow.Vy];
xvel_export(end+1,:,:)=[;x_vel];
yvel_export(end+1,:,:)=[;y_vel];
%Creation of 2-3D matrices consisting of each iteration of data
%calculated during run (or for all frames)
magnitudes = flow.Magnitude;
orientations = flow.Orientation;
mag_export(end+1,:,:)=[;magnitudes];
orient_export(end+1,:,:)=[;orientations];
Boat = circshift(orient_export,[400 -300]);
plot(flow,'DecimationFactor',[10 10],'ScaleFactor',2);
hold on
saveas(gcf,sprintf('figure%d.jpg'))
end

回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by