2016-07-28 87 views
0

我与霍夫圈工作变换与我的树莓派,当我乘坐的投资回报率,以检查圈是这样的:OpenCV的霍夫圆变换需要8位图像

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 

enter image description here 我怎么能改造的投资回报率成为8位图像或根本错误的意思是别的东西

预先感谢您!

编辑:

enter image description here

+1

你可以将图像转换为灰度。使用'cv2.cvtColor(...,COLOR_BGR2GRAY)' – Miki

+0

@Miki当我使用灰度图像时,它给了我另一个错误,我用图片提出了我的问题。 – Loanb222

+0

@Miki它仍然给与一轮相同的错误。 – Loanb222

回答

0

谢谢三木bpachev的帮助!

第一个错误意味着你需要将其转换为灰度这样

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 

而且NoneType错误意味着没有哪个圈子会发现这么advoid可以if语句添加此错误

if circles is not None: 
    circles = numpy.round(circles[0, :]).astype("int") 

然后,因为没有找到圈子,我知道那里有圈子,我不得不玩弄探测器的设置。