2016-08-16 66 views
0

我得到了以下網站中的斑點檢測程序:https://www.learnopencv.com/blob-detection-using-opencv-python-c/爲什麼參數更改後斑點檢測的結果不會改變?

這很安靜有用,但是我在更改參數值後發現結果沒有任何變化。 喜歡:即使我設置顏色的參數爲255(它用於檢測點亮的斑點),仍然可以檢測到深色斑點。此外,我改變最小面積的值後,也可以檢測到最小的斑點。

似乎沒有什麼變化,結果總是像下面的一個: the result of blob detection 下面是代碼:

import cv2 
import numpy as np; 

# Read image 
im = cv2.imread("blob.jpg", cv2.IMREAD_GRAYSCALE) 


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

params = cv2.SimpleBlobDetector_Params() 

# Change thresholds 
params.minThreshold = 10; # the graylevel of images 
params.maxThreshold = 200; 

params.filterByColor = True 
params.blobColor = 255 

# Filter by Area. 
params.filterByArea = False 
params.minArea = 10000 

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

# 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(im, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) 

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

誰能幫助我?非常感謝!!!

回答

0

您可以更改參數,但它們不會被檢測器使用。設置它們,然後設置探測器:

import cv2 
import numpy as np 

# Read image 
im = cv2.imread('blob.jpg', cv2.IMREAD_GRAYSCALE) 

# Setup SimpleBlobDetector parameters. 
params = cv2.SimpleBlobDetector_Params() 

# Change thresholds 
params.minThreshold = 10 # the graylevel of images 
params.maxThreshold = 200 

# Filter by Area. 
params.filterByArea = True 
params.minArea = 1500 

# Create a detector with the parameters 
detector = cv2.SimpleBlobDetector(params) 

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

# 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(
    im, keypoints, np.array([]), (0, 0, 255), 
    cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) 

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

注意:你有,如果你想使用這個參數並沒有在段錯誤終止使用Trueparams.filterByArea

+0

haha​​ha ....我是多麼愚蠢!!謝謝!! –

相關問題