OPENCV:霍夫圆圈,检测对象的麻烦
当谈到 OpenCV 时,我是一个完全的初学者,当尝试检测特定大小的圆圈时,我不知道从哪里开始,下面是我当前的代码(不多)以及我试图检测的图像,如果有人可以的话帮助我或给我一些建议,我将不胜感激,(我已将图像转换为灰度并添加高斯模糊,以便更容易检测)谢谢!
import cv2
import numpy as np
test = cv2.imread('test.jpg')
gray_img = cv2.cvtColor(test, cv2.COLOR_BGR2GRAY)
img = cv2.medianBlur(gray_img, 5)
cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
cv2.imshow("HoughCirlces", test)
cv2.waitKey()
cv2.destroyAllWindows()
I am a complete beginner when it comes to OpenCV, I have no clue where to start when trying to detect circles of a certain size, below is my current code (not much) along with the image I am trying to detect, if anyone could help me or give me some advice it would be much appreciated, (i have converted image to grayscale and added gaussian blur so it is easier to detect) Thanks!
import cv2
import numpy as np
test = cv2.imread('test.jpg')
gray_img = cv2.cvtColor(test, cv2.COLOR_BGR2GRAY)
img = cv2.medianBlur(gray_img, 5)
cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
cv2.imshow("HoughCirlces", test)
cv2.waitKey()
cv2.destroyAllWindows()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
干得好,你已经快到了,你现在所要做的就是实际应用 CHT。您正在寻找的函数是 cv2.HoughCircles()。您需要传递图像,在您的情况下,您可以使用 img 或 cimg 以及一些可能需要调整的参数。这是一些模板代码
您也可以查看文档和教程。我将在下面链接它们。
教程:https://docs.opencv.org/4.x/ da/d53/tutorial_py_houghcircles.html
文档: https://docs.opencv.org/4.x/dd/d1a/group__imgproc__feature.html#ga47849c3be0d0406ad3ca45db65a25d2d
great work, you're almost there, all you have to do now is actually apply the CHT. The function you are looking for is cv2.HoughCircles(). You need to pass the image, in your case you can use either img or cimg and some parameters that might require tuning. Here is some template code
You can also take a look at the documentation and tutorial. I'll link them below.
Tutorial: https://docs.opencv.org/4.x/da/d53/tutorial_py_houghcircles.html
Docs: https://docs.opencv.org/4.x/dd/d1a/group__imgproc__feature.html#ga47849c3be0d0406ad3ca45db65a25d2d