OpenCV Python HoughCircles错误 [英] OpenCV Python HoughCircles error
问题描述
我正在开发一个程序来检测图像中的圆形.我决定使用Hough转换是最好的,我在OpenCV库中找到了一个.问题是,当我尝试使用它时,出现错误,我不知道如何解决. Python的OpenCV是否未完全实现?我需要该程序才能正常运行的库吗?
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?
代码如下:
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错误:未知函数中为空pinter(), 文件.. \ .. \ .. \ .. \ ocv \ openc \ src \ cxcore \ cxdatastructs.cpp,第408行 追溯(最近一次通话): 在第20行中输入文件"ellipse-detect-webcam.py" cv.HoughCircles(edges,storage,cv.CV_HOUGH_GRADIENT,2,gray.height/4,200,100) 错误
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
预先感谢您的帮助.
推荐答案
对于它的价值,我发现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.
这篇关于OpenCV Python HoughCircles错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!