我正在处理以下代码。
n=0;
folder = fileparts(which('viptraffic.avi'));
movieFullFileName = fullfile(folder, 'viptraffic.avi');
vidReader = VideoReader(movieFullFileName);
opticFlow = opticalFlowLK('NoiseThreshold',0.0039);
while hasFrame(vidReader)
frameRGB = readFrame(vidReader);
frameGray = rgb2gray(frameRGB);
flow = estimateFlow(opticFlow,frameGray);
H=imag(flow)
V=real(flow)
frameWithFlow = getframe(gca);
imshow(frameRGB);
imshow(frameWithFlow.cdata)
hold on
plot(flow,'DecimationFactor',[5 5], 'ScaleFactor',10)
hold off
n=n+1;
end
是否有办法获得每张图像中获得的每个光流场的光流估计速度和幅度?
答案 0 :(得分:3)
estimateFlow
会返回opticalFlow个对象,该对象具有幅度,相位和速度属性。因此,在您的情况下,flow
是opticalFlow
对象,而不是复杂数组,您无法将其传递给real
和imag
。而是使用对象的属性:
flow.Vx % x component of velocity
flow.Vy % y component of velocity
flow.Orientation % Phase
flow.Magnitude % Magnitude