Java+opencv3.2.0實現hough圓檢測功能,opencv3.2.0hough

來源:互聯網
上載者:User

Java+opencv3.2.0實現hough圓檢測功能,opencv3.2.0hough

hough圓檢測和hough線檢測的原理近似,對於圓來說,在參數座標系中表示為C:(x,y,r)。

函數:

Imgproc.HoughCircles(Mat image, Mat circles, int method, double dp, double minDist, double param1, double param2, int minRadius, int maxRadius)

參數說明:

image:源映像
circles:檢測到的圓的輸出向量(x,y,r)
method:使用的檢測方法,目前只有一種Imgproc.HOUGH_GRADIENT
dp:檢測圓心的累加器映像與源映像之間的比值倒數
minDist:檢測到的圓的圓心之間的最小距離
param1:method設定的檢測方法對應參數,針對HOUGH_GRADIENT,表示邊緣檢測運算元的高閾值(低閾值是高閾值的一半),預設值100
param2:method設定的檢測方法對應參數,針對HOUGH_GRADIENT,表示累加器的閾值。值越小,檢測到的無關的圓
minRadius:圓半徑的最小半徑,預設為0
maxRadius:圓半徑的最大半徑,預設為0(若minRadius和maxRadius都預設為0,則HoughCircles函數會自動計算半徑)

範例程式碼:

public static void main(String[] args)  {    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);    Mat src = Imgcodecs.imread("F:\\websbook_com_1589226.jpg");    Mat dst = src.clone();    Imgproc.cvtColor(src, dst, Imgproc.COLOR_BGR2GRAY);    Mat circles = new Mat();    Imgproc.HoughCircles(dst, circles, Imgproc.HOUGH_GRADIENT, 1, 100, 440, 50, 0, 345);    // Imgproc.HoughCircles(dst, circles, Imgproc.HOUGH_GRADIENT, 1, 100,    // 440, 50, 0, 0);    for (int i = 0; i < circles.cols(); i++)    {      double[] vCircle = circles.get(0, i);      Point center = new Point(vCircle[0], vCircle[1]);      int radius = (int) Math.round(vCircle[2]);      // circle center      Imgproc.circle(src, center, 3, new Scalar(0, 255, 0), -1, 8, 0);      // circle outline      Imgproc.circle(src, center, radius, new Scalar(0, 0, 255), 3, 8, 0);    }    Imgcodecs.imwrite("F:\\dst2.jpg", src);  }

源映像:


輸出映像:

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.