2011-04-01 23 views
1

背景在Emgu.CV中這些閾值是什麼意思,是否有更好的方法來檢測一個圓?

這裏是我的(從Emgu.CV.Examples溶液ShapeDetection項目與EmguCV下載傳來大多代碼)獲得的圖像和繪畫中就發現圓Emgu.CV代碼:

//Load the image from file 
Image<Bgr, Byte> img = new Image<Bgr, byte>(myImageFile); 

//Get and sharpen gray image (don't remember where I found this code; prob here on SO) 
Image<Gray, Byte> graySoft = img.Convert<Gray, Byte>().PyrDown().PyrUp(); 
Image<Gray, Byte> gray = graySoft.SmoothGaussian(3); 
gray = gray.AddWeighted(graySoft, 1.5, -0.5, 0); 

Image<Gray, Byte> bin = gray.ThresholdBinary(new Gray(149), new Gray(255)); 

Gray cannyThreshold = new Gray(149); 
Gray cannyThresholdLinking = new Gray(149); 
Gray circleAccumulatorThreshold = new Gray(1000); 

Image<Gray, Byte> cannyEdges = bin.Canny(cannyThreshold, cannyThresholdLinking); 

//Circles 
CircleF[] circles = cannyEdges.HoughCircles(
    cannyThreshold, 
    circleAccumulatorThreshold, 
    4.0, //Resolution of the accumulator used to detect centers of the circles 
    15.0, //min distance 
    5, //min radius 
    0 //max radius 
    )[0]; //Get the circles from the first channel 

//draw circles (on original image) 
foreach (CircleF circle in circles) 
    img.Draw(circle, new Bgr(Color.Brown), 2); 

以下是圖像:

Image of circles

的問題

  1. 好的,所以我知道ThresholdBinary的閾值是多少。由於我從灰度圖像獲取二值圖像,因此圖像中灰度的強度。這是因爲圖片中灰度圓的強度爲150到185。我認爲這與HoughCircles的第一個參數相同。

    我不知道的是circleAccumulatorThreshold,累加器的分辨率和最小距離(第二,第三和第四個參數爲HoughCircles)是或應該到那裏的值。我顯然沒有正確的值,因爲圖中的圓圈不正確。

  2. 我的第二個問題是,有沒有更好的方法來找到圓?我需要能夠在許多類型的光線中檢測到這個圓圈(即圓圈的顏色強度可能很低,如80或更低),並在圖片中獲得它的尺寸。匹配一個圈子的最佳方式是什麼?我應該讓這個圓圈變成另一種顏色,並在原始圖像中尋找那種顏色?任何其他想法?

感謝

回答

3
  • 累加器是多少分,必須要考慮「收集」一 圈。數字越高意味着檢測到的圈數越少
  • 決議是如何 關閉點必須是建議的圈子。基本上是 像素的「大小」。
  • MinDistance是多麼接近圓是允許 彼此。在你的例子中,你有3個圈子,都非常接近 。增加最小距離可以防止重疊圓圈,而只是繪製一個圓圈。

至於你的答案兩個數字,圖像模糊,轉換爲灰度圖像,然後門檻消除照明差異是通常的解決

1

雖然這個問題是「很多」的時候,我想提出一個回答問題2對於那些誰可能會遇到類似的問題的好處。

你可以做的是:

  1. 閾值的圖像以去除背景,
  2. 檢測物體的圖像中,
  3. 計算圓(http://en.wikipedia.org/wiki/Shape_factor_(image_analysis_and_microscopy))的圓,它應該是1如果它是一個圓圈。使用方法FindContours(在emgucv中)提供了需要爲區域和圓的周長計算的所有信息。然後,您可以使用這些信息來獲取檢測到的圈子的維度。
+0

你有什麼建議刪除的背景是什麼? @Oliver – 2017-11-17 05:48:58