Adding Figures onto a Video

13 次查看(过去 30 天)
Lucianne Morin
Lucianne Morin 2020-7-9
Hello! I am currently working on a heat map, which I am generating from code that was writen by the last person working on this project. I'm not super familiar with it, but basically what they were doing was generating a movie using the immovie command and playing it with movie. I am trying to overlay figures on top of my video, so I changed it to use the writeVideo command, which is saving my array as an .avi, then I am trying to load that .avi and use the video overlay process explained here https://blogs.mathworks.com/pick/2010/12/10/video-player-for-your-frame-based-processing/ to display the figures. It's just generating a blank figure with axes, not even the original video I am trying to load.
Does anyone know how to solve this, or if there is an easier method for me to use? I've attached my code, function files, jpgs, and raw data below.

回答(1 个)

Prabhan Purwar
Prabhan Purwar 2020-7-20
Hi,
Kindly go through the following example illustrated at link.
%% EXAMPLE 1
% Place this in a file called "redraw.m":
function redraw(frame)
imshow(['AT3_1m4_' num2str(frame, '%02.0f') '.tif']) %To draw frame
end
%Then from a script or the command line, call:
videofig(10, @redraw); %To setup figure to play
redraw(1)
As videofig is used to set up the viewer and not to display, you need to put redraw(1,v2); (Function code is below) to display images. (Reason for getting blank figure with axis).
function redraw(frame, vidObj)
% Read frame
f = vidObj.read(frame);
image(f);
axis image off
end
% Under BNIHeat.m
v2=VideoReader('heat_map.avi');
videofig(v2.NumFrames, @(frm) redraw(frm,v2));
redraw(1,v2);
If you wish to put images with it, try to merge images using imfuse.
Hope it helps!!

Community Treasure Hunt

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

Start Hunting!

Translated by