How to analyse optical flow information
13 次查看(过去 30 天)
显示 更早的评论
Hi there,
I have acquired the output from the optical fow in a structure and would like to learn how to use the data to say there are defects - using magnitude and Orientation, as well as how to use Vector motion Vx and Vy in my analysis.As an example, consider determining the peak and obtaining the wavelength measurement per unit time.
Is it possible to extract the output vectors? I'd like to use static analysis to determine the quality in terms of flicker, blink, and blur. Any suggestions would be highly appreciated.
The information in my sample data structure is as follows:
Vx: [360×640 single]
Vy: [360×640 single]
Orientation: [360×640 single]
Magnitude: [360×640 single]
3 个评论
采纳的回答
Praveen Reddy
2023-8-23
编辑:Praveen Reddy
2023-8-23
Hi,
I understand that you want to compute spatial image gradients, temporal gradients and export the results. You can compute the spatial gradient using the flow obtained and temporal gradient as the difference between current frame and previous frame. Please find the modified code below where the results are exported as “.mat” files.
vidReader = VideoReader('visiontraffic.avi');
opticFlow = opticalFlowHS;
h = figure;
movegui(h);
hViewPanel = uipanel(h,'Position',[0 0 1 1],'Title','Plot of Optical Flow Vectors');
hPlot = axes(hViewPanel);
% Create arrays to store spatial and temporal gradients
spatial_gradients = [];
temporal_gradients = [];
fprintf('%15s| %15s| %15s| %15s|\n---------------+----------------+----------------+-----------------+\n', ...
'VidCurrentTime','Magnitude','Orientation','Algexecutiontime' );
% Initialize previous frame variables
prevFrameRGB = readFrame(vidReader);
prevFrameGray = im2gray(prevFrameRGB);
while hasFrame(vidReader)
frameRGB = readFrame(vidReader);
frameGray = im2gray(frameRGB);
t1 = tic;
flow = estimateFlow(opticFlow,frameGray);
t2 = toc(t1);
fprintf('%15.4f|%15.8f | %15.8f| %16.8f|\n',vidReader.CurrentTime,std2(sqrt(flow.Magnitude)),std2(angle(flow.Orientation)),t2 );
% Calculate spatial gradient (per pixel) using the magnitude of flow
spatial_gradient = sqrt(flow.Magnitude);
spatial_gradients = [spatial_gradients; spatial_gradient(:)];
% Calculate temporal gradient (per frame) using the difference between current and previous frame
temporal_gradient = abs(frameGray - prevFrameGray);
temporal_gradients = [temporal_gradients; temporal_gradient(:)];
imshow(frameRGB)
hold on
plot(flow,'DecimationFactor',[5 5],'ScaleFactor',60,'Parent',hPlot);
q = findobj(gca,'type','Quiver');
q.Color = 'r';
drawnow
hold off
pause(10^-3)
% Store current frame for the next iteration
prevFrameRGB = frameRGB;
prevFrameGray = frameGray;
end
% Export the spatial and temporal gradients as data files
save('spatial_gradients.mat', 'spatial_gradients');
save('temporal_gradients.mat', 'temporal_gradients');
I hope this helps.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Tracking and Motion Estimation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!