python - 检测圆形形状opencv

标签 python opencv computer-vision artificial-intelligence

每个人我对 OpenCV 和计算机视觉都很陌生,我被这个问题困住了,这看起来很微不足道,但请原谅我的菜鸟 :)

我正在尝试从横截面图像中检测钢筋。

Original Color Image

我正在使用这段代码:

import cv2
import cv2.cv as cv
import numpy as np

img = cv2.imread('test/t2.jpg',0)
img = cv2.equalizeHist(img)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)

circles = cv2.HoughCircles(img,cv.CV_HOUGH_GRADIENT,1,10,param1=50,param2=30,minRadius=0,maxRadius=25)

circles = np.uint16(np.around(circles))
for i in circles[0,:]:
    # draw the outer circle
    cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)

cv2.imshow('detected circles',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()

这是我目前得到的结果,不太好: Result

我正在寻找有关如何处理这个问题以及如何了解更多关于 CV 的指导,因为我真的很感兴趣!

非常感谢!

最佳答案

HoughCircles 不足以检测像您这样的复杂图像中的圆圈。

SO 已经对此进行了一些讨论。您可以引用这些帖子以及高质量的可接受答案

标准方式:

Filled circle detection using CV2 in Python?

What are the possible fast ways to detect circle in an image?

噪声图像:

https://dsp.stackexchange.com/questions/5930/find-circle-in-noisy-data

另一种方法:

Gradient Pair Vectors

Learning Automata

关于python - 检测圆形形状opencv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35519102/

相关文章:

python - cv2.destroyAllWindows() 的功能是什么?

c++ - 具有 3 个类别的 OpenCV SVM 预测置信度

c# - 将 Texture2D 转换为 OpenCV Mat?

matlab - 如何对图像应用主成分分析

python - 与 main 一起终止 GObject.Mainloop() 线程

python - 如何在 pandas 中填充直到一天结束?

opencv - 立体校准后将相机 1 图像中的 2d 点投影到相机 2 图像

machine-learning - 当我运行 inception 预处理脚本时,它失败

python - 在不创建列表的情况下以不同的顺序迭代 itertools.product

python - 我可以在 Python 中使用过滤器获取函数列表吗?