FAST(Features from Accelerated Segment Test) 由 Rosten 教授提出,以極高速度著稱。OpenCV 的 cvCornerFast 參數包含:影像(8-bit)、閾值(0-255,越大角點越少)、弧長 N(9/10/11/12,通常 9 最佳)、非極大值抑制旗標。EmguCV 的 GetFASTKeypoints 僅保留 threshold 與 nonmaxSuppression 兩參數,N 預設為 9。
MKeyPoint[] keyPoints = imageSourceGrayscale.GetFASTKeypoints(threshold, nonmaxSuppression);
foreach (MKeyPoint kp in keyPoints)
imageResult.Draw(new CircleF(kp.Point, kp.Size/2), new Bgr(255,0,0), kp.Size/4);
由 Vincent Lepetit 提出,EmguCV 以 LDetector 類別實作。參數包含基礎特徵大小、群聚距離、金字塔層數、視圖數、半徑、閾值、詳細輸出旗標、最大關鍵點數、座標縮放。
LDetector detector = new LDetector();
detector.BaseFeatureSize = ...; detector.NOctaves = ...; // 等參數設定
MKeyPoint[] keyPoints = detector.DetectKeyPoints(imageSourceGrayscale, maxCount, scaleCoords);
SIFT(Scale-Invariant Feature Transform)廣泛用於物體追蹤、影像拼接,但 OpenCV 未內建。David Lowe 提供 C/Matlab 參考實作,而 VLFeat(Andrea Vedaldi & Brian Fulkerson)提供更易整合的 C 版本。使用流程:
vl_sift_new 初始化濾波器(可重複用於同尺寸影像)vl_sift_process_first_octave + vl_sift_process_next_octave 遍歷八度vl_sift_detect 取得關鍵點vl_sift_calc_keypoint_orientations 取得方向vl_sift_calc_keypoint_descriptor 產生 128 維描述子vl_sift_delete 釋放資源IntPtr ptrSiftFilt = VlFeatInvoke.vl_sift_new(w, h, noctaves, nlevels, o_min);
Image<Gray, Single> img = imageSourceGrayscale.ConvertScale<Single>(1, 0);
if (VlFeatInvoke.vl_sift_process_first_octave(ptrSiftFilt, img.MIplImage.imageData) != VL_ERR_EOF) {
while (true) {
VlFeatInvoke.vl_sift_detect(ptrSiftFilt);
VlSiftFilt siftFilt = (VlSiftFilt)Marshal.PtrToStructure(ptrSiftFilt, typeof(VlSiftFilt));
VlSiftKeypoint* pKeys = (VlSiftKeypoint*)siftFilt.keys.ToPointer();
for (int i=0; i<siftFilt.nkeys; i++) {
VlSiftKeypoint kp = *pKeys++;
// 繪製、計算方向、計算描述子...
}
if (VlFeatInvoke.vl_sift_process_next_octave(ptrSiftFilt) == VL_ERR_EOF) break;
}
}
VlFeatInvoke.vl_sift_delete(ptrSiftFilt);
為簡化 .NET 開發,作者將 VLFeat SIFT 部分封裝為 SiftDetector,使用步驟:
Process(Image<Gray,Single>, SiftDetectorResultType) 取得 List<SiftFeature>Dispose() 或等待 GC 釋放SiftDetector detector = new SiftDetector(imageSource.Size, noctaves, nlevels, o_min);
List<SiftFeature> features = detector.Process(imageSourceSingle, SiftDetectorResultType.Extended);
// 繪製與顯示...
detector.Dispose();
文末附上完整的 VlSiftKeypoint、VlSiftFilt 結構配置(StructLayout.Sequential)與 VlFeatInvoke 類別,涵蓋所有需匯入的 vl_sift_* 函式簽章(DllImport("vl.dll")),包含錯誤碼常數(VL_ERR_OK、VL_ERR_EOF 等)。