OpenCV Python HoughCircles 错误
我正在开发一个检测图像中圆形形状的程序。我认为霍夫变换是最好的,并且我在 OpenCV 库中找到了一个。问题是,当我尝试使用它时,我收到一个错误,我不知道如何修复。 OpenCV for Python 还没有完全实现吗?程序运行所需的库是否有修复?
这是代码:
import cv
#cv.NamedWindow("camera", 1)
capture = cv.CaptureFromCAM(0)
while True:
img = cv.QueryFrame(capture)
gray = cv.CreateImage(cv.GetSize(img), 8, 1)
edges = cv.CreateImage(cv.GetSize(img), 8, 1)
cv.CvtColor(img, gray, cv.CV_BGR2GRAY)
cv.Canny(gray, edges, 50, 200, 3)
cv.Smooth(gray, gray, cv.CV_GAUSSIAN, 9, 9)
storage = cv.CreateMat(1, 2, cv.CV_32FC3)
#This is the line that throws the error
cv.HoughCircles(edges, storage, cv.CV_HOUGH_GRADIENT, 2, gray.height/4, 200, 100)
#cv.ShowImage("camera", img)
if cv.WaitKey(10) == 27:
break
这是我收到的错误:
OpenCV 错误:未知函数中的 Null pinter (), 文件..\..\..\..\ocv\openc\src\cxcore\cxdatastructs.cpp,第 408 行 回溯(最近一次调用最后一次): 文件“ellipse-detect-webcam.py”,第 20 行,位于 cv.HoughCircles(边缘, 存储, cv.CV_HOUGH_GRADIENT, 2, grey.height/4, 200, 100) 简历错误
预先感谢您的帮助。
I'm working on a program that detects circular shapes in images. I decided a Hough Transform would be the best, and I found one in the OpenCV library. The problem is that when I try to use it I get an error that I have no idea how to fix. Is OpenCV for Python not fully implemented? Is there a fix to the library I need for the program to work?
Here's the code:
import cv
#cv.NamedWindow("camera", 1)
capture = cv.CaptureFromCAM(0)
while True:
img = cv.QueryFrame(capture)
gray = cv.CreateImage(cv.GetSize(img), 8, 1)
edges = cv.CreateImage(cv.GetSize(img), 8, 1)
cv.CvtColor(img, gray, cv.CV_BGR2GRAY)
cv.Canny(gray, edges, 50, 200, 3)
cv.Smooth(gray, gray, cv.CV_GAUSSIAN, 9, 9)
storage = cv.CreateMat(1, 2, cv.CV_32FC3)
#This is the line that throws the error
cv.HoughCircles(edges, storage, cv.CV_HOUGH_GRADIENT, 2, gray.height/4, 200, 100)
#cv.ShowImage("camera", img)
if cv.WaitKey(10) == 27:
break
And here is the error I'm getting:
OpenCV Error: Null pinter () in unknown function,
file ..\..\..\..\ocv\openc\src\cxcore\cxdatastructs.cpp, line 408
Traceback (most recent call last):
File "ellipse-detect-webcam.py", line 20, in
cv.HoughCircles(edges, storage, cv.CV_HOUGH_GRADIENT, 2, gray.height/4, 200, 100)
cv.error
Thanks in advance for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
存储必须更大,我认为 cvMat 不是动态分配的,因此您必须将行:更改
为:
The storage must to be bigger, I thought that cvMat isn't dinamically allocated so you have to for example change the line:
to:
无论如何,我发现如果 cv.HoughCircles 无法检测到图像中的圆形形状,它就会中止,而不是优雅地返回一个空列表。
For what it's worth, I've found that
cv.HoughCircles
aborts if it can't detect a circular shape in the image, instead of gracefully returning an empty list.图片有效吗?
你能显示它们(原始的和灰度的)吗?
否则你确定函数的参数是正确的吗?您是否正确传递指针或引用
Are the images valid?
Can you display them (the original and the grayscaled)
Otherwise are you sure the args to the function are correct? Are you passing pointers or references correctly