2012-12-01 38 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