Python采用霍夫椭圆变换检测图片中的椭圆物体

 时间:2026-02-13 22:42:32

1、打开IDLE软件,并且载入先关的函数库。

import matplotlib.pyplot as plt

from skimage import data,draw,color,transform,feature

Python采用霍夫椭圆变换检测图片中的椭圆物体

2、读取图片,并对图片进行相应的剪切,且需要进行灰度化处理。这读取的是skimage库内的文件。

image_rgb = data.coffee()[0:220, 160:420]

image_gray = color.rgb2gray(image_rgb)

Python采用霍夫椭圆变换检测图片中的椭圆物体

3、在灰度图的基础上,进行边缘检测,代码如下。

edges = feature.canny(image_gray, sigma=2.0, low_threshold=0.55, high_threshold=0.8)

Python采用霍夫椭圆变换检测图片中的椭圆物体

4、对边缘图像进行霍夫椭圆变换处理,代码如下,执行比较费时间。

result =transform.hough_ellipse(edges, accuracy=20, threshold=250,min_size=100, max_size=120)

result.sort(order='accumulator')

Python采用霍夫椭圆变换检测图片中的椭圆物体

5、获取我们的处理得到的椭圆。

best = list(result[-1])

yc, xc, a, b = [int(round(x)) for x in best[1:5]] 

orientation = best[5]

Python采用霍夫椭圆变换检测图片中的椭圆物体

6、查看效果,采用以下代码,在原图上画出我们检测得到的椭圆。

cy, cx =draw.ellipse_perimeter(yc, xc, a, b, orientation) 

image_rgb[cy, cx] = (0, 0, 255)

plt.imshow(image_rgb)

plt.show()

Python采用霍夫椭圆变换检测图片中的椭圆物体

7、我们检测的结果如下。

Python采用霍夫椭圆变换检测图片中的椭圆物体

  • 联想摄像头打开黑屏
  • C#控制台程序该如何实现输入输出
  • MyEclipse如何修改项目的java版本
  • Matlab2016b安装教程
  • 如何登录 Plesk
  • 热门搜索
    嗓子发炎肿痛怎么办 潍坊旅游景点 cf怎么卡箱子 环不取可以吗 水沸腾的特点 怎么让自己变得有气质 男人的精子可以吃吗 绝对值符号怎么打 怎么把桌面图标变大 北京物资学院怎么样