FAST角點檢測
FAST角點由E. Rosten教授提出,相比其他檢測手段,這種方法的速度正如其名,相當的 快。值得關注的是他所研究的理論都是屬於實用類的,都很快。Rosten教授實現了FAST角點 檢測,並將其提供給了OpenCv,相當的有愛呀;不過OpenCv中的函數和Rosten教授的實現似 乎有點點不太一樣。遺憾的是,OpenCv中目前還沒有FAST角點檢測的文檔。下面是我從 Rosten的代碼中找到的函式宣告,可以看到粗略的參數說明。
/*
The references are:
* Machine learning for high-speed corner detection,
E. Rosten and T. Drummond, ECCV 2006
* Faster and better: A machine learning approach to corner detection
E. Rosten, R. Porter and T. Drummond, PAMI, 2009
*/
void cvCornerFast( const CvArr* image, int threshold, int N,
int nonmax_suppression, int* ret_number_of_corners,
CvPoint** ret_corners);
image: OpenCV image in which to detect corners. Must be 8 bit unsigned.
threshold: Threshold for detection (higher is fewer corners). 0-- 255
N: Arc length of detector, 9, 10, 11 or 12. 9 is usually best.
nonmax_suppression: Whether to perform nonmaximal suppression.
ret_number_of_corners: The number of detected corners is returned here.
ret_corners: The corners are returned here.
EmguCv中的 Image<TColor,TDepth>.GetFASTKeypoints方法也實現了FAST角點檢 測,不過參數少了一些,只有 threshold和nonmaxSupression,其中N我估計取的預設值9, 但是返回的角點數目我不知道是怎麼設定的。
使用FAST角點檢測的範例程式碼如下:
FAST關鍵點
private string FASTKeyPointFeatureDetect()
{
//擷取參數
int threshold = int.Parse (txtFASTThreshold.Text);
bool nonmaxSuppression = cbFASTNonmaxSuppression.Checked;
bool showDetail = cbFASTShowDetail.Checked;
//計算
Stopwatch sw = new Stopwatch();
sw.Start();
MKeyPoint[] keyPoints = imageSourceGrayscale.GetFASTKeypoints(threshold, nonmaxSuppression);
sw.Stop();
//顯示
Image<Bgr, Byte> imageResult = imageSourceGrayscale.Convert<Bgr, Byte>();
StringBuilder sbResult = new StringBuilder();
int idx = 0;
foreach (MKeyPoint keypoint in keyPoints)
{
imageResult.Draw(new CircleF(keypoint.Point, (int)(keypoint.Size / 2)), new Bgr(255d, 0d, 0d), (int)(keypoint.Size / 4));
if (showDetail)
sbResult.AppendFormat("第{0}點(座標 :{1},尺寸:{2},方向:{3}°,響應:{4},octave:{5}),",
idx, keypoint.Point, keypoint.Size, keypoint.Angle, keypoint.Response, keypoint.Octave);
idx++;
}
pbResult.Image = imageResult.Bitmap;
//釋放資源
imageResult.Dispose();
//返回
return string.Format("·FAST關鍵點,用時{0:F05}毫秒 ,參數(閥值:{1},nonmaxSupression:{2}),檢測到{3}個關鍵點\r\n{4}",
sw.Elapsed.TotalMilliseconds, threshold, nonmaxSuppression, keyPoints.Length, showDetail ? (sbResult.ToString() + "\r\n") : "");
}