OpenCV Hough Circle Transform需要8位图像 [英] OpenCV Hough Circle Transform needs 8-bit image
问题描述
我正在使用RaspberryPi使用Hough Circle Transform,当我进行ROI检查像这样的圆形时:
I am working with Hough Circle Transform with my RaspberryPi and when I take a ROI to check for circle like this:
for (x,y,w,h) in trafficLights:
cv2.rectangle(image,(x,y),(x+w,y+h),(0,0,255),2)
roi = image[y:y+h,x:x+w]
roi = cv2.medianBlur(roi,5)
circles = cv2.HoughCircles(roi,cv2.HOUGH_GRADIENT,1,20,
param1=50,param2=60,minRadius=0,maxRadius=0)
circles = numpy.uint16(numpy.around(circles))
for i in circles[0,:]:
if i[2] < 100:
cv2.circle(image,(i[0],i[1]),i[2],(0,255,0),2)
cv2.circle(image,(i[0],i[1]),2,(0,0,255),3)
if i[1] > 315:
print "Green Light"
else:
print "Red Light"
我收到此错误
The source image must be 8-bit, single-channel in function cvHoughCircles
如何将ROI转换为8位图像,或者该错误表示其他什么意思
How can I transform the ROI to become an 8-bit image or does the error mean something else
先谢谢您!
推荐答案
感谢Miki和bpachev的帮助!
Thank you Miki and bpachev for the help!
第一个错误意味着您需要像这样将其转换为灰度
The first error means that you need to convert it to grayscale like this
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
NoneType错误意味着未找到任何圆圈,为避免错误,您可以添加此if语句
And the NoneType error means that no circles were found so to advoid the error you can add this if statement
if circles is not None:
circles = numpy.round(circles[0, :]).astype("int")
然后,因为在我知道没有圈的地方发现了任何圈,所以我必须在检测器的设置下玩转.
Then since no circles were found where I knew there were circles I had to play around with the settings of the detector.
这篇关于OpenCV Hough Circle Transform需要8位图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!