opencv python中的椭圆检测
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了opencv python中的椭圆检测,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2248字,纯文字阅读大概需要4分钟。
内容图文
![opencv python中的椭圆检测](/upload/InfoBanner/zyjiaocheng/696/ef5c0c0360554d9e84876171ba2ae5a9.jpg)
我的图片在这里:
我正在寻找更好的解决方案或算法来检测这张照片中的椭圆形部分(盘),并在Opencv中的另一张照片中对其进行遮罩.
你能给我一些建议或解决方案吗?
我的代码是:
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1.2, 1, param1=128, minRadius=200, maxRadius=600)
# draw detected circles on image
circles = circles.tolist()
for cir in circles:
for x, y, r in cir:
x, y, r = int(x), int(y), int(r)
cv2.circle(img, (x, y), r, (0, 255, 0), 4)
# show the output image
cv2.imshow("output", cv2.resize(img, (500, 500)))
解决方法:
Xie,Yonghong和Qiang Ji制作的skimage中有另一种替代方法,并出版为…
“A new efficient ellipse detection method.” Pattern Recognition, 2002.
Proceedings. 16th International Conference on. Vol. 2. IEEE, 2002.
他们的椭圆检测代码相对较慢,此示例大约需要70秒;相比网站声称“ 28秒”.
如果您有conda或pip:“名称”,请安装scikit-image并试一试…
可以找到here或下面的副本/粘贴其代码:
import matplotlib.pyplot as plt
from skimage import data, color, img_as_ubyte
from skimage.feature import canny
from skimage.transform import hough_ellipse
from skimage.draw import ellipse_perimeter
# Load picture, convert to grayscale and detect edges
image_rgb = data.coffee()[0:220, 160:420]
image_gray = color.rgb2gray(image_rgb)
edges = canny(image_gray, sigma=2.0,
low_threshold=0.55, high_threshold=0.8)
# Perform a Hough Transform
# The accuracy corresponds to the bin size of a major axis.
# The value is chosen in order to get a single high accumulator.
# The threshold eliminates low accumulators
result = hough_ellipse(edges, accuracy=20, threshold=250,
min_size=100, max_size=120)
result.sort(order='accumulator')
# Estimated parameters for the ellipse
best = list(result[-1])
yc, xc, a, b = [int(round(x)) for x in best[1:5]]
orientation = best[5]
# Draw the ellipse on the original image
cy, cx = ellipse_perimeter(yc, xc, a, b, orientation)
image_rgb[cy, cx] = (0, 0, 255)
# Draw the edge (white) and the resulting ellipse (red)
edges = color.gray2rgb(img_as_ubyte(edges))
edges[cy, cx] = (250, 0, 0)
fig2, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, figsize=(8, 4), sharex=True,
sharey=True,
subplot_kw={'adjustable':'box-forced'})
ax1.set_title('Original picture')
ax1.imshow(image_rgb)
ax2.set_title('Edge (white) and result (red)')
ax2.imshow(edges)
plt.show()
内容总结
以上是互联网集市为您收集整理的opencv python中的椭圆检测全部内容,希望文章能够帮你解决opencv python中的椭圆检测所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。