2017-03-03 63 views
0

我想在圖像中簡單地找到白色圓形斑點。當我嘗試用houghcircles去時,我總是把字母和數字誤認爲圈子,而我只需要完整的圈子,即斑點。無法檢測到任何白色斑點 - opencv python

所以我用自定義參數運行這個斑點檢測器代碼來找到左上角的圓形IC引腳標記。但是我一直在'9'和'0'之內得到黑眼圈。 它根本沒有檢測到任何白色斑點。

這裏是我試過的代碼:

import cv2 
import numpy as np; 

# Read image 
img = cv2.imread("C:\chi4.jpg", cv2.IMREAD_GRAYSCALE) 
retval, threshold = cv2.threshold(img, 200, 255, cv2.THRESH_BINARY) 

params = cv2.SimpleBlobDetector_Params() 

# Change thresholds 
params.minThreshold = 10; 
params.maxThreshold = 255; 

blur = cv2.GaussianBlur(img,(5,5),0) 

params.filterByCircularity = True 
params.minCircularity = 0.2 

params.filterByArea = True; 
params.minArea = 1000; 

ver = (cv2.__version__).split('.') 
if int(ver[0]) < 3 : 
    detector = cv2.SimpleBlobDetector(params) 
else : 
    detector = cv2.SimpleBlobDetector_create(params) 

# Set up the detector with default parameters. 
#detector = cv2.SimpleBlobDetector() 

# Detect blobs. 
keypoints = detector.detect(threshold) 

# Draw detected blobs as red circles. 
# cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures the size of the circle corresponds to the size of blob 
im_with_keypoints = cv2.drawKeypoints(img, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) 

# Show keypoints 
cv2.imshow("Keypoints", im_with_keypoints) 
cv2.waitKey(0) 

這裏是我的輸出圖像: Output image

紅色圓圈是檢測的。我想要白色的圓形斑點,在藍色的頂部被檢測到。

我試着改變閾值參數,仍然沒有影響。請讓我知道我出錯的地方或者提高產量的建議。 在此先感謝:D

+0

您可以上傳原始圖像? –

+0

這是原始圖像。使用USB數字顯微鏡拍攝 –

回答

4

Blob一般假定爲灰色/黑色。在你的情況下,字母邊上的斑點是黑色的。然而你想要的blob是白色的。因此它不被認可。

在你的代碼必須更改第四行:

retval, threshold = cv2.threshold(img, 200, 255, cv2.THRESH_BINARY_INV) 

我遵循以下相同的方法:

我下面的圖像進行斑點檢測:

enter image description here

但沒有找到任何blob:

enter image description here

我倒二進制圖像以下列:

enter image description here

現在我能夠探測到它們,如下所示:

enter image description here

+0

謝謝。有效!我從來不知道斑點檢測器只在黑色/灰色斑點上起作用! –