imshow and plot not displaying when using opticalFlow

Hi, Following the optical flow examples, the code below is behaving in an odd way. If I only use imshow on the image it will refresh in real-time (i.e comment out the plot command), however if I try to plot the optical flow vectors, I will only get the very last frame displayed once the loop has completed. Could anyone shed any light on this?
vidDevice = imaq.VideoDevice('winvideo', 1);
optical = opticalFlowHS;
nFrames = 0;
while (nFrames<100)
nFrames = nFrames + 1;
rgbData = step(vidDevice);
grey = rgb2gray(rgbData);
optFlow = estimateFlow(optical,grey);
imshow(rgbData);
hold on
plot(optFlow, 'DecimationFactor',[5 5],'ScaleFactor',25);
hold off
end
release(vidDevice);
Many thanks

 채택된 답변

Jan
Jan 2016년 3월 19일

0 개 추천

Try to insert a drawnow command to allow Matlab to update the display.
It will be faster to create the axes and image objects once before the loop and update the 'CData' property inside the loop only.

댓글 수: 1

Thanks Jan as well for the extra tips, I have a little bit more performance now!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Issa Al-Hmoud
Issa Al-Hmoud 2019년 8월 20일

0 개 추천

try the pause command after the hold off
pause(0.1)

카테고리

도움말 센터File Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

질문:

2016년 3월 19일

답변:

2019년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by