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函數會自動計算半徑)
示例代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
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); } |
源圖像:
輸出圖像:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://blog.csdn.net/m1109048058/article/details/77577677