clear all; clc; close all; testName = 'CB2'; % Test = Start End X Y W H vidParams = [390 900 225 100 300 300]; fileName = 'testcb_2.mpg'; startTime = vidParams(1) ; % Start capturing at this frame endTime = vidParams(2) ; % End capturing at this frame fps = 3 ; % Frame sampling rate found by x/30 cropArea = [vidParams(3) vidParams(4) vidParams(5) vidParams(6)] ; % [x, y, width, height] of rectangle to crop vidCheck = 0 ; % Should frames be saved to a video for verification? 1 for yes, 0 for no showEdges = 0 ; % Show pic, color edge, and edge comparison images for each frame vid = mmreader(fileName); nframes = (startTime:fps:endTime); limits = [3.6 13.5]; % Area limits for cardboard for plotting test_cb2_time_coarse = (1:61)'; test_cb2_mass_coarse = [9.80000000000000;9.77000000000001;9.74000000000001;9.70000000000001;9.66000000000001;9.62000000000001;9.56000000000001;9.50000000000001;9.43000000000001;9.35000000000001;9.26000000000001;9.16000000000001;9.05000000000001;8.94000000000001;8.82000000000001;8.70000000000001;8.58000000000001;8.46000000000001;8.34000000000001;8.22000000000001;8.10000000000001;7.98000000000001;7.86000000000001;7.75000000000001;7.64000000000001;7.53000000000001;7.41000000000001;7.28000000000001;7.16000000000001;7.05000000000001;6.94000000000001;6.83000000000001;6.73000000000001;6.64000000000001;6.55000000000001;6.47000000000001;6.40000000000001;6.34000000000001;6.28000000000001;6.22000000000001;6.16000000000001;6.09000000000001;6.02000000000001;5.96000000000001;5.91000000000001;5.85000000000001;5.80000000000001;5.76000000000001;5.71000000000001;5.67000000000001;5.63000000000001;5.59000000000001;5.56000000000001;5.52000000000001;5.48000000000001;5.44000000000001;5.40000000000001;5.37000000000001;5.34000000000001;5.30000000000001;5.26000000000001]-5.26; mass_cb2_time = (0:1/(30/fps):18)'; mass_cb2_data = interp1(test_cb2_time_coarse, test_cb2_mass_coarse, mass_cb2_time, 'spline'); % from the video script test_cb2_time_coarse = (0:18)'; test_cb2_heights_coarse = [0; 2.48; 4.14; 2.76; 5.65; 5.24; 3.45; 6.345; 5.24; 10.07; 6.90; 9.93; 10.76; 9.52; 16.55; 20.14; 13.24; 17.93; 17.38]; test_cb2_time = (0:1/(30/fps):18)'; test_cb2_heights = interp1(test_cb2_time_coarse, test_cb2_heights_coarse, test_cb2_time, 'spline'); % Using a B-number of 1.69 from test cb2 predicted_time_coarse = (0:18)'; predicted_flameheights_coarse = [2;2.03389108370960;2.52009766647539;3.05836286841823;3.64868668953811;4.29106912983505;4.98551018930903;5.73200986796006;6.53056816578814;7.38118508279327;8.28386061897545;9.23859477433467;10.2453875488709;11.3042389425843;12.4151489554746;13.5781175875421;14.7931448387865;16.0602307092080;17.3793751988066]; predicted_time = (0:1/(30/fps):18)'; predicted_flameheights = interp1(predicted_time_coarse, predicted_flameheights_coarse, predicted_time, 'spline'); n = 1; edges = []; xcoeff = polyfit(test_cb2_time, test_cb2_heights, 2); yfit = polyval(xcoeff, test_cb2_time); j = 1; for i = nframes singleFrame = read(vid, i); % Grab a single frame from the movie I = imcrop(singleFrame, cropArea); % Crop the image to just the cone fig = figure; image(I); hold on set(gca,'handlevisibility','off', 'visible','off') axes('position',[0.13,0.11,0.775,0.815]) set(gca,'visible','off') text(13, 8, 'Predicted', 'FontSize', 18, 'Color', 'g', 'FontWeight', 'Bold') set(gca, 'xlim',[0.0 20]); set(gca, 'ylim',[0.0 20]); set(gca,'Color','None'); tit = title('Predicted Flame Heights - Test CB2'); set(gca,'FontSize',18,'FontWeight','bold'); set(tit,'FontSize',22,'FontWeight','bold'); % Plots a line on the cardboard showing the predicted flame height plotFlameHeight = limits(1) + ((limits(2)-limits(1))/20)*predicted_flameheights(j); line([5 13],[plotFlameHeight plotFlameHeight],[1 1],'Marker','.','LineStyle','-', 'LineWidth', 4.0, 'Color', 'g') filename = (['Frames/mov_', num2str(n) '.jpg']); print('-djpeg','-r100',filename) close if vidCheck == 1 vidOut(n).cdata = singleFrame; vidOut(n).colormap = []; end if showEdges == 1 close all; figure; subplot(1,3,1), imshow(I), title('Flame Original'); subplot(1,3,2), imshow(edges), title('Flame Edges RGB'); subplot(1,3,3), imshow(I4), title('Combined RG edges'); pause(1); end n = n + 1; j = j + 1; end % actualHeight = pixelHeight / 7.25; % Convert pixels to cm % figure; plot(actualHeight,'bo'); set(gca,'XTick',0:30/fps:endTime); set(gca,'XTickLabel',0:1:60);