【问题标题】:Saving a series of manually selected points保存一系列手动选择的点
【发布时间】:2025-12-27 20:55:16
【问题描述】:

只是一个简单的问题。我生成了一段代码,借此我在每一帧中选择感兴趣的点。但是,最后一个选定点的坐标是唯一保存的坐标。有谁知道如何设置代码,以便将每个帧的所有点保存在例如第 1 列中 x 位置和第 2 列中 y 位置的文本文件中?这是我目前开发的代码;

clear;
clc;

%% Video file information
obj = VideoReader('T9_720p_60p_60mm_f5.MOV');

%% Sampling rate 
fps = get(obj, 'FrameRate');
dt = 1/fps;

%% Image Information
file_info = get(obj);
image_width = file_info.Width;
image_height = file_info.Height;

%%Desired image size
x_range = 1:image_height;
y_range = 1:image_width;
szx = length(x_range);
szy = length(y_range);

%%Image processing - Point selection
for n = 33:115
    frame = read(obj,n);
    imshow(frame);
    hpoint = impoint(gca, []);
    Position = getPosition(hpoint);
end

【问题讨论】:

  • 您可以设置全局变量或使用句柄并将新坐标附加到旧坐标。

标签: matlab


【解决方案1】:

我刚刚意识到我只需要在循环结束之前添加以下内容

%%Save data

n = n-32;
data(n,:) = [Position];
end

问候

【讨论】:

  • 为了加速代码你应该在for循环之前预分配data=nan(115-32,2);