Matlab VLFEAT-多重匹配

mar*_*esk 18 matlab opencv computer-vision vlfeat

我在Matlab中执行与VLFEAT的SIFT匹配.

单个匹配很容易显示:我按照教程进行操作.

更新1 :(从我的需求中提取问题)

接下来我会考虑场景的4种不同视图:我希望将第一台摄像机(左下角)中找到的功能与其他摄像机匹配.

图像已经不失真.

在此输入图像描述

我可以匹配第三个图像:我设法用偏移校正坐标以获得正确的显示.我设置了高阈值(较少的点)以获得更易理解的图像.我的代码发布在下面,然后会有问题

指出(它不会影响问题或答案,只有我的代码中的变量名称)

由于我的4台摄像机实际上是在空间中移动的立体摄像机,因此4台摄像机(和相关输出)是:


左下:左边的摄像头命名为a.这张图片中的特征是fa描述符da......
右下角:左边的摄像头命名为a.此图像中的特征是fb描述符 db......
左上角:左前一个相机在前一个瞬间命名为a.此图像中的功能是fa_old描述符 da_old......
右上角:右前一个相机名为b的相机.这张图片中的特征是fb_old描述符 db_old......

移动较小,所以我预计SIFT可以检索相同的点.

此代码查找点并执行"蓝色匹配"和"红色匹配"

%classic instruction for searching feature
    [fa,da] = vl_sift((Ia_f),'NormThresh', thresh_N, 'EdgeThresh', thresh_E) ;
% with the same line I obtain
%fa are features in the current left image (da are descriptors)
%fb are features in the current right image (db... )
%fa_old are features in the previous left image
%fb_old are features in the previous right image

%code from tutorials (find the feature)
[matches, scores] = vl_ubcmatch(da,db,thresh_SIFT) ;
[drop, perm] = sort(scores, 'descend') ;
matches = matches(:, perm);

%my code

figure(1) ; %clf ;
axis equal;
%prepare the image
imshow(cat(1,(cat(2, Ia_v_old, Ib_v_old)),cat(2,Ia_v,Ib_v)));

%matching between the left frames (current and previous)
[matches_prev, scores_prev] = vl_ubcmatch(da,da_old,thresh_SIFT) ; 
[drop_prev, perm_prev] = sort(scores_prev, 'descend') ;
matches_prev = matches_prev(:, perm_prev) ;

%find index of descriptors in common, write them in order
I = intersect(matches(1,:), matches_prev(1,:),'stable');
MI_1 = arrayfun(@(x)find(matches(1,:)==x,1),I);
MI_2 = arrayfun(@(x)find(matches_prev(1,:)==x,1),I);
matches_M = matches(:,MI_1(:));
matches_prev_M = matches_prev(:,MI_2(:));

%features coordinates in the current images (bottom)
xa = fa(1,matches_M(1,:)) + offset_column ;
xb = fb(1,matches_M(2,:)) + size(Ia,2); %+offset_column-offset_column ;
ya = fa(2,matches_M(1,:)) + offset_row + size(Ia,1);
yb = fb(2,matches_M(2,:)) + offset_row + size(Ia,1);            

%matching "in space" (blue lines)
space_corr = line([xa ; xb], [ya ; yb]) ;
set(space_corr,'linewidth', 1, 'color', 'b') ;
%plotting features
fa(1,:) = fa(1,:) + offset_column ;
fa(2,:) = fa(2,:) + offset_row + size(Ia,1);
vl_plotframe(fa(:,matches_M(1,:))) ;
fb(1,:) = fb(1,:) + size(Ia,2) ;
fb(2,:) = fb(2,:) + offset_row + size(Ia,1);
vl_plotframe(fb(:,matches_M(2,:))) ;

%matching "in time" %corrx and coor y are corrected offsets
xa2 = fa_old(1,matches_prev_M(2,:)) + corrx;  %coordinate per display
ya2 = fa_old(2,matches_prev_M(2,:)) - size(Ia,1) + corry;

fa_old(1,:) = fa_old(1,:) + corrx;
fa_old(2,:) = fa_old(2,:) - size(Ia,1) + corry;
fb_old(1,:) = fb_old(1,:) + corrx ;
fb_old(2,:) = fb_old(2,:) - size(Ia,1) + corry;

%plot red lines
time_corr = line([xa ; xa2], [ya ; ya2]) ;
set(time_corr,'linewidth', 1, 'color', 'r') ;
%plot feature in top left image
vl_plotframe(fa_old(:,matches_prev_M(2,:))) ;
%plot feature in top right image
vl_plotframe(fb_old(:,matches_ex_M(2,:))) ;
Run Code Online (Sandbox Code Playgroud)

一切都有效.我想重复几行代码并按正确的顺序找到正确的matches_ex_M索引数组,最后在最后一个(右上角)图像中连接该特征(与其他任何一个图像一起)

% one of many tries (all wrong)
[matches_ex, scores_ex] = vl_ubcmatch(da_old,db_old,thresh_SIFT) ;
[drop_ex, perm_ex] = sort(scores_ex, 'descend') ;
matches_ex = matches_ex(:, perm_ex);
Ib = intersect(matches_prev_M(2,:), matches_ex(1,:),'stable');
MIb_2 = arrayfun(@(x)find(matches_ex(1,:)==x,1),Ib);
matches_ex_M = matches_ex(:,MIb_2(:));
Run Code Online (Sandbox Code Playgroud)

问题是新的交叉点将导致新的重新排序,并且所有匹配都将是错误的.但是我已经承认在尝试所有可能的匹配索引数组的组合之后我没有更多的想法.问题是我不能同时执行3个数组之间的交集,也不能改变它们的顺序.精选在所有4个图像中都很好地显示,我可以在不同的脚本中执行从任何图像到另一个图像的单个匹配.在右上角的图像中,有相同的功能,但顺序不同.

我得到了什么(显然是错的) 在此输入图像描述

合成我的探测器:

我想我应该改变右上方框架中点的顺序,以便有一个很好的"黄色"匹配,但我不知道如何在不改变左上方的顺序的情况下制作它(这会破坏"红色")匹配"和/或"蓝色匹配")

任何的想法?任何不同的策略?谢谢大家.

更新2:在考虑从MATLAB + VLFEAT切换到Python(2.7)+ OpenCV(2.4.13)之后(我更喜欢在Matlab和VLFEAT中有一个解决方案)我找到了这个答案.有人可以用C++做到这一点.但我无法在Python中转换它,也无法在Matlab中转换它.也可以接受pythonic解决方案(由于这个原因添加了适当的标签).