2012-12-01 34 views
3

我正在阅读vl_ubcmatch的函数源代码,提供了here,我在试着理解,它是如何计算分数的,以及它在技术上如何工作。vl_ubcmatch如何在技术上工作?

但是,这个C代码有这些宏,怪异的##变量,以及什么,我没有经验。所以这里的主要问题是我在C中的无能。如果可能的话,有人可以告诉我,vl_ubcmatch究竟是如何工作的?它如何比较两个描述符?

+0

我不认为这是一个短“如何用C语言编写C++模板“的解释。你必须阅读一本书。 –

+0

卡尔,想加入聊天? http://chat.stackoverflow.com/rooms/20457/chat-with-karl – 2012-12-01 19:48:31

回答

12

这在Distinctive Image Features from Scale-Invariant Keypoints的7.1节和7.2节中有解释。

文档的功能是在这里:http://www.vlfeat.org/mdoc/VL_UBCMATCH.html

从特征D1的匹配在图像1到特征D2在图像2被用于仅当d1和d2之间的距离小于距离显著较小以d1和任何图像2中的其他功能。比赛需要比任何其他潜在比赛好得多。 “重要”由您传递给VL_UBCMATCH功能的阈值定义。

7.2节是指近似最近邻搜索的结构,但VL_UBCMATCH不使用此:

for(k1 = 0 ; k1 < K1 ; ++k1, L1_pt += ND) {      \ 
                    \ 
    PROMOTE_##MXC best = maxval ;          \ 
    PROMOTE_##MXC second_best = maxval ;        \ 
    int bestk = -1 ;             \ 
                    \ 
    /* For each point P2[k2] in the second image... */    \ 
    for(k2 = 0 ; k2 < K2 ; ++k2, L2_pt += ND) {      \ 
                    \ 
    int bin ;              \ 
    PROMOTE_##MXC acc = 0 ;           \ 
    for(bin = 0 ; bin < ND ; ++bin) {        \ 
     PROMOTE_##MXC delta =           \ 
     ((PROMOTE_##MXC) L1_pt[bin]) -        \ 
     ((PROMOTE_##MXC) L2_pt[bin]) ;        \ 
     acc += delta*delta ;           \ 
    }                \ 
                    \ 
    /* Filter the best and second best matching point. */   \ 
    if(acc < best) {            \ 
     second_best = best ;           \ 
     best = acc ;             \ 
     bestk = k2 ;             \ 
    } else if(acc < second_best) {         \ 
     second_best = acc ;           \ 
    }                \ 
    }                 \ 
                    \ 
    L2_pt -= ND*K2 ;             \ 
                    \ 
    /* Lowe's method: accept the match only if unique. */    \ 
    if(thresh * (float) best < (float) second_best &&     \ 
    bestk != -1) {             \ 
    pairs_iterator->k1 = k1 ;          \ 
    pairs_iterator->k2 = bestk ;         \ 
    pairs_iterator->score = best ;         \ 
    pairs_iterator++ ;            \ 
    }                 \ 
} 

这里是伪代码:

matches = [] 
For each descriptor k1 in image 1: 
    closest_match_distance = Infinity 
    second_closest_match_distance = Infinity 
    best_match = None 
    For each descriptor k2 in image 2: 
     distance_squared = d(k1, k2) 
     if (distance_squared < closest_match_distance): 
      second_closest_match_distance = closest_match_distance 
      closest_match_distance = distance_squared 
      best_match = k2 
    If (threshold * closest_match_distance < 
     second_closest_match_distance AND best_match != None): 
     matches.Insert((k1, best_match, closest_match_distance)) 
return matches