Is there a way to overlay a graph onto a video, plotting each successive point with each frame?
33 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Teshan Rezel
am 11 Okt. 2021
Beantwortet: Walter Roberson
am 12 Okt. 2021
Reposted since the previous post didn't get resolved!
Hi folks,
I have a script that creates a video from image files, as below:
for i = 1 : numFolders
RawImages = [vidFolders(i).folder '\' vidFolders(i).name];
videoName = [RawImages '\' vidFolders(i).name '.avi'];
addpath(RawImages);
imageFolder = [RawImages '\Images\'];
files = dir([imageFolder '*.tif']);
numImages = length(files);
if ~isfile(videoName)
writerObj = VideoWriter(videoName);
writerObj.FrameRate = 10;
open(writerObj);
for j = 1:numImages
imagePath = [imageFolder files(j).name];
image = imread(imagePath);
image = image(:,:,1:3);
frame = im2frame(image);
writeVideo(writerObj, frame);
end
close(writerObj);
end
end
Each frame of the video is a temperature increment of 1 degree. For each video created, there is a plot that describes the video, as such:
where each point along the line is a degree increment, as with each frame in the video.
My question is: can I overlay the graph onto the video, such that the plot evolves with each frame? In other words, can I append the graph to the video and have the line extend along the X axis with each frame of the video?
I have tried videofig from the File Exchange and I can't get it to work as per:
type redraw;
vid = VideoReader('rhinos.avi');
videofig(vid.NumFrames, @(frm) redraw(frm, vid));
redraw(1, vid);
function redraw(frame, vidObj)
f = vidObj.read(frame);
f2 = edge(rgb2gray(f), 'canny');
f3 = bsxfun(@plus, f, uint8(255*f2));
image(f3); axis image off
end
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 12 Okt. 2021
Using the videofig() calls you show worked fine for me. Just make sure you get https://www.mathworks.com/matlabcentral/fileexchange/29544-figure-to-play-and-analyze-videos-with-custom-plots-on-top and not https://www.mathworks.com/matlabcentral/fileexchange/84028-preview-and-play-video-files
The shortcut to start the playing is to press return while focused on the figure. But if you need to automate, then after you run videofig, then
timers = timerfind();
start(timers(end)); %should start the playing
0 Kommentare
Weitere Antworten (1)
yanqi liu
am 12 Okt. 2021
for i = 1 : numFolders
RawImages = [vidFolders(i).folder '\' vidFolders(i).name];
videoName = [RawImages '\' vidFolders(i).name '.avi'];
addpath(RawImages);
imageFolder = [RawImages '\Images\'];
files = dir([imageFolder '*.tif']);
numImages = length(files);
if ~isfile(videoName)
writerObj = VideoWriter(videoName);
writerObj.FrameRate = 10;
open(writerObj);
for j = 1:numImages
imagePath = [imageFolder files(j).name];
image = imread(imagePath);
image = image(:,:,1:3);
% add line
image = insertShape(image,'line',[1 1 size(image,2) size(image,1)],'LineWidth',2);
frame = im2frame(image);
writeVideo(writerObj, frame);
end
close(writerObj);
end
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Acquisition Toolbox Supported Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!