Creating a timelapsed composite video with plots and webcam images
From Lehigh RTMD Wiki
Saving the plot images from MATLAB
Below is sample code for creating a set of plot images based on an x and y history. This assumes that MATLAB array 'xval' contains the x values and array 'yval' contains the y values. Also, they both must have the same number of rows. The images will be created in the working directory.
i = 1;
sizeof = size(xval);
xmin = -0.04;
xmax = 0.04;
ymin = -1.0;
ymax = 1.0;
while (i <= sizeof(1))
plot(xval(1:i),yval(1:i),'r',xval(i:i),yval(i:i),'--b>','MarkerSize',5,'MarkerFaceColor','b');
xlabel('Rotation (rads)');
ylabel('Normalized Moment, M/Mpn');
title('Normalized Moment vs Rotation');
axis([xmin xmax ymin ymax]);
grid on;
filename = ['images/graph' sprintf('%06',i)];
print('-djpeg',filename);
i = i + 1;
end
C code for creating composite images
Below is example C code for batch processing the composition with Imagemagick. A required file, "bg.jpg", should be the background sized to the necessary dimensions for MJPEG (ie, 1024x768);
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
int i;
int numfiles;
int numplots;
char buf[1000];
char* imagemagickpath = "C:\\Progra~1\\IMAGEM~1.6-Q\\convert";
FILE *f;
// Pass in the number of files to use in the composition
numfiles = atoi(argv[1]);
// For loop goes through each set of images and creates the composite image
for (i = 1; i <= numfiles; i++) {
printf("[Composite] : Image %i/%i\n",i,numfiles);
// Resize the plot
sprintf(buf,"%s plots\\image%06d.jpg -resize 500 -quality 100 tempvid1.jpg",imagemagickpath,i);
system (buf);
// Resize the webcam image
sprintf(buf,"%s webcam\\image%06d.jpg -resize 500 -quality 100 tempvid2.jpg",imagemagickpath,i);
system (buf);
// Add the plot to the west portion of the background
sprintf(buf,"%s -quality 100 -compose Over -gravity west tempvid1.jpg bg.jpg new.jpg",imagemagickpath);
system (buf);
// Add the image to the east portion of the background
sprintf(buf,"%s -quality 100 -compose Over -gravity east tempvid2.jpg new.jpg output\\image%06d.jpg",imagemagickpath,i);
system (buf);
}
// Cleanup
system ("del tempvid1.png tempvid2.png new.png");
return 0;
}
Then see Creating timelapsed webcam video on how to create the video file.

