Java+opencv3.2.0實現(xiàn)hough圓檢測功能
hough圓檢測和hough線檢測的原理近似,對于圓來說,在參數(shù)坐標系中表示為C:(x,y,r)。
函數(shù):
Imgproc.HoughCircles(Mat image, Mat circles, int method, double dp, double minDist, double param1, double param2, int minRadius, int maxRadius)
參數(shù)說明:
image:源圖像
circles:檢測到的圓的輸出矢量(x,y,r)
method:使用的檢測方法,目前只有一種Imgproc.HOUGH_GRADIENT
dp:檢測圓心的累加器圖像與源圖像之間的比值倒數(shù)
minDist:檢測到的圓的圓心之間的最小距離
param1:method設置的檢測方法對應參數(shù),針對HOUGH_GRADIENT,表示邊緣檢測算子的高閾值(低閾值是高閾值的一半),默認值100
param2:method設置的檢測方法對應參數(shù),針對HOUGH_GRADIENT,表示累加器的閾值。值越小,檢測到的無關的圓
minRadius:圓半徑的最小半徑,默認為0
maxRadius:圓半徑的最大半徑,默認為0(若minRadius和maxRadius都默認為0,則HoughCircles函數(shù)會自動計算半徑)
示例代碼:
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);
}
源圖像:

輸出圖像:

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
java中LinkedBlockingQueue與ArrayBlockingQueue的異同
這篇文章主要介紹了java中LinkedBlockingQueue與ArrayBlockingQueue的異同,需要的朋友可以參考下2016-08-08

