Quick way to update image objects in a Matlab shape

I need to display updated images as quickly as possible in a Matlab figure. Each image is processed and then displayed. However, the display speed of color images is rather slow. For example, when I run the following code

videoObj = VideoReader('sample.avi'); nFrames = videoObj.NumberOfFrames; h = videoObj.Height; w = videoObj.Width; mov(1:nFrames) = struct('cdata', zeros(h, w, 3, 'uint8'), 'colormap', []); for k = 1 : nFrames mov(k).cdata = read(interObj, k); end tic for i=1:nFrames frame = mov(i).cdata; image(frame); drawnow; end secPerFrame = toc/nFrames 

secPerFrame = 0.012 seconds is required to update each frame. Where each frame is an RGB image of 640x480 pixels. Therefore, if I want to process a video stream at a speed of 30 frames per second, this leaves "only" 0.033 - 0.012 = 0.021 seconds for the actual image processing after subtracting the service data associated with the image display.

Is there a faster way to update image objects in Matlab?

+4
source share
1 answer

If all images are the same size, you can use the image command once, and then update the CData property for the axes.

 videoObj = VideoReader('sample.avi'); nFrames = videoObj.NumberOfFrames; mov(1:nFrames) = ... struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'), 'colormap', []); for k = 1 : nFrames mov(k).cdata = read(interObj, k); end tic image(mov(1).cdata); imageHandle = get(gca,'Children'); for i=1:number frame = mov(i).cdata; set(imageHandle ,'CData',frame); drawnow; end secPerFrame = toc/number 

This will still be slow since Matlab metrics are not optimized for showing videos. If the application allows pre-processing, save it as a movie file to disk and call an external program to display it.

+3
source

Source: https://habr.com/ru/post/1415614/


All Articles