Java+opencv3.2.0实现hough圆检测功能

2025-05-29 0 38

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);

}

源图像:

Java+opencv3.2.0实现hough圆检测功能

输出图像:

Java+opencv3.2.0实现hough圆检测功能

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。

原文链接:http://blog.csdn.net/m1109048058/article/details/77577677

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 Java+opencv3.2.0实现hough圆检测功能 https://www.kuaiidc.com/112900.html

相关文章

发表评论
暂无评论