成对点之间的运动矢量

时间:2016-03-12 10:19:12

标签: matlab

我有一系列来自视频的nFrames图像,我已经计算了所有这些SIFT关键点和描述符,并将它们存储在两个cell数组中。我现在需要做的是计算图像1上的第一个关键点和图像2上的相应关键点之间的向量(相应的关键点将是具有相同或最相似描述符的关键点),并且对所有其他关键点都这样做关键点,以便绘制一个图表,显示关键点如何在场景上移动,这反映了场景中物体的移动。

关键点存储为4-by-n数组(第一行是x组件,第二行是y组件 - 另外两行是scale组件和angle,我不需要 - ,每列对应一个不同的关键点),所以我想从第一张图像到第二张图像中减去相应的点,但是不会这样做。我最终还是在这两个中间还有另一个点?如何将差异存储为矢量,以便稍后在同一图表上绘制所有这些差异?

目前我只有这个:

% Clear all and add all folders to the current path
clear; close all; clc;
addpath(genpath('.'));

% Set path, nFrames and threshold values
path = 'img/record_tennis';
d = dir([ path,'\*.png' ]);
nFrames = length( d( not([ d.isdir ]) ) );
th = 0.01;
step = 20;
keypts = cell(1,nFrames);
desc = cell(1,nFrames);

% Main loop
for i = 1:step:nFrames
    disp([ 'Processing frame number ',num2str(i),' of ',num2str(nFrames),'...' ]);
    % Read the current image
    imgRGB = imread([ path,'/',d(i).name ]);
    img = sum( double(imgRGB),3 ) / 3 / 255;

    % Perform SIFT on the current image and plot the keypoints
    [ keypts{1,i},desc{1,i} ] = sift( img,'Threshold',th );
    imshow( img ), hold on
    plot( keypts{1,i}(1,:),keypts{1,i}(2,:),'.' );
    pause(1); clc;
end

% Remove empty cells
keypts = keypts( ~cellfun( @isempty,keypts ) );
desc   = desc( ~cellfun( @isempty,desc ) );

有了这个,我计算了每个帧的SIFT个关键点和描述符(我添加了一个step值,因为移动非常小,这样它在连续图像之间更加明显)。然后我由于步长因素而移除了空单元格,现在我必须计算相应关键点之间的向量,但我仍然坚持这一点。

1 个答案:

答案 0 :(得分:0)

通常,如果你想要从一组点到另一组点的矢量,你可以简单地减去这两个点(如你所提到的)。这将为您提供[dx, dy]的向量。为了显示那个矢量场,你可以使用quiver从初始点开始绘制每个矢量。箭袋的输入是:

quiver(initial_x, initial_y, dx, dy, scale)

因此,如果我们查看您的变量,我们可以从您的keypts变量构建每个变量。

initial_x = keypts{1}(1,:);
initial_y = keypts{1}(2,:);
dx = keypts{current_frame}(1,:) - initial_x;
dy = keypts{current_frame}(2,:) - initial_y;

现在,您应该可以在图像上绘制此图像以显示运动场。

hax = axes();
imshow(img, 'Parent', hax);
hold(hax, 'on')
q = quiver(initial_x, initial_y, dx, dy, 1);

现在,这要求keypts中的点实际上具有不同帧之间的对应关系(即keypts{1}(:,1)是与相同的物理点{ {1}})。根据您正在呼叫的功能,这可能是也可能不是。

相关问题