我有一个脚本可以读取图像,在它们上面叠加散点图,然后将所有生成的图像组合成一部电影。我在翻译脚本以在 Octave 中工作时遇到了一些困难。我已经解决了所有的问题,除了我的循环只运行一次。即创建的视频只有一帧长。我怀疑这可能与gcf有关?尽管我已经看了很长时间,以至于我认为这可能只是我缺少的一些简单的东西。任何想法将不胜感激。
循环是:
for i = 1:subsamp:numel(dd)
if (mod(i,100)==0)
fprintf('frame %d/%d\n', i, numel(dd));
end
% read current image and trim its width and height to a multiple of 4
img = imread([img_dir,'/',dd(i).name]);
trim_x = mod(size(img,2),4);
trim_y = mod(size(img,1),4);
img = img(1:end-trim_y,1:end-trim_x);
% display current image
set(0,'CurrentFigure',hnd);
imshow(img);
% if there is truth for this frame, show it
which_block = map(i);
if (which_block > 0)
% grab data chunk for this frame
block = truth(starts(which_block):ends(which_block),:);
pts = block(:,7:8);
ids = block(:,2);
% overlay tracks and ids
hold on;
scatter(pts(:,1),pts(:,2),5);
hold off;
end
% add this frame to movie file
getframe(img);
mov = addframe(mov,frame);
end
最后的“getframe()”函数是我在网上其他地方找到的。它看起来像这样:
function frame = getframe (h)
print ("tmp.fig", "-djpg");
frame = im2double (imread ("tmp.fig"));
## Truncate to even size to accomodate addframe()
if (mod (size (frame, 1), 2) > 0); frame = frame(2:end, :, :); endif
if (mod (size (frame, 2), 2) > 0); frame = frame(:, 2:end, :); endif
endfunction
同样,如果您注意到任何可能阻止它遍历每一帧的东西,我们将不胜感激。谢谢!!