Is there a way to overlay a graph onto a video, plotting each successive point with each frame?

조회 수: 8 (최근 30일)
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?

채택된 답변

Walter Roberson
Walter Roberson 2021년 9월 27일
편집: Walter Roberson 2021년 9월 27일
  댓글 수: 3
Walter Roberson
Walter Roberson 2021년 10월 4일
What problems are you encountering with video_fig ? It is difficult to make recommendations that will avoid a problem that has not been defined.
Teshan Rezel
Teshan Rezel 2021년 10월 5일
Hi @Walter Roberson, apologies! I have typed in the example given in the documentation as so, but it doesn't run at all!
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

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

추가 답변 (1개)

yanqi liu
yanqi liu 2021년 9월 28일
clc; clear all; close all;
t = linspace(0, 2*pi);
xt = cos(t);
yt = sin(t);
figure; axis([-1 1 -1 1]);
writerObj = VideoWriter('out.avi');
writerObj.FrameRate = 24;
open(writerObj);
for i =1 : 5: length(t)
plot(xt(1:i), yt(1:i), 'r-');
axis([-1 1 -1 1]);
frame = getframe(gcf);
writeVideo(writerObj, frame);
pause(1e-1);
end
plot(xt, yt, 'r-');
axis([-1 1 -1 1]);
frame = getframe(gcf);
writeVideo(writerObj, frame);
pause(1e-1);
close(writerObj);

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by