我試圖檢測所有的光學圈,但我面臨着圓圈邊緣相當碎裂的困難。某些地方,由於噪音二元化後,圓圈彼此接觸。有沒有解決方法?如何在存在噪聲的情況下斷開圓圈並在邊緣斷裂時檢測圓圈?
pattern = [{0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9},
{0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9},
{0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9},
{0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9},
{0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9},
{0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9},
{0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9},
{0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9},
{0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9},
{0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9}
]
stringLen = len(pattern)
blobCnts = sum([len(d) for d in pattern])
raw_image = cv2.imread(imagePath)
gray = cv2.cvtColor(raw_image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
bloblist = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0]
blobcnts = contours.sort_contours(bloblist)[0]
contour_list = []
sorted_contour = []
for blob in blobcnts:
approx = cv2.approxPolyDP(blob,0.01*cv2.arcLength(blob,True),True)
area = cv2.contourArea(blob)
(x,y),r = cv2.minEnclosingCircle(blob)
center = (int(x),int(y))
r = int(r)
if ((len(approx) >= 8) & (len(approx) <= 23) & (area > 30) & (8 < r < 20)):
contour_list.append(blob)
numlist = []
if blobCnts == len(contour_list):
for (l, i) in enumerate(np.arange(0, blobCnts, stringLen)):
cnts = contours.sort_contours(contour_list[i:i + 10],method="top-to-bottom")[0]
numlist.append(cnt)
print cnt
我申請了,但我不能夠微調它按我的要求 – Zara
我實現了,但我怎麼能解決所有圖像的一些參數?它基於照明改變 – Zara
函數包含爲canny定義閾值的param1。我將它設置爲最初的30個,當時從100個圈子中我獲得了99個圈子,用於少量樣本。後來,當我減少它時,檢測100個圈子的比率減少了。之後,我首先通過canny檢測邊緣,然後通過邊緣圖像作爲此函數的輸入。從58個樣本中只有2個被拒絕。所以,我只想問,這種情況的結論是什麼? – Zara