Octave脚本循环只运行一次

时间:2013-09-13 14:04:51

标签: image matlab image-processing octave

我有一个脚本可以读取图像,覆盖它们上的散点图,然后将所有生成的图像组合成一个电影。虽然我在翻译脚本以便在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

同样,如果你注意到任何可以阻止这种情况迭代每一帧的东西,我们非常感激。谢谢!

0 个答案:

没有答案
相关问题