5
我試圖從紅色圓形類型對象的黑色背景中檢測圓圈。使用python打開cv中的圓圈檢測
import cv2
import cv2.cv as cv
import numpy as np
img = cv2.imread('extracted.jpg',0)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(img,cv.CV_HOUGH_GRADIENT,1,20,
param1=50,param2=30,minRadius=0,maxRadius=0)
circles = np.uint8(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow('detected circles',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
我已經加載灰度模式的圖像,它仍然給我一個錯誤
"circles = np.uint8(np.around(circles))
File "/usr/lib/python2.7/dist-packages/numpy/core/fromnumeric.py", line 2277, in around
return _wrapit(a, 'round', decimals, out)
File "/usr/lib/python2.7/dist-packages/numpy/core/fromnumeric.py", line 37, in _wrapit
result = getattr(asarray(obj),method)(*args, **kwds)
AttributeError: rint"
我不能發佈圖片,因爲我現在的名聲。
PLZ忽略縮進錯誤 – Anuradha
試試這個代碼:https://github.com/Itseez/opencv/blob/master/samples/python2/houghcircles.py –
阿比德感謝,我試過的代碼,但它給了我CV2。圓(cimg,(圓[0] [i] [0],圓[0] [i] [1]),圓[0] [i] [2],(0,0,255),3,cv .LINE_AA) AttributeError:'模塊'對象沒有屬性'LINE_AA' – Anuradha