为什么改变参数后blob检测的结果没有改变?

why the result of blob detection does not change after the change of parameters?

我在以下网站获得了斑点检测程序: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)

谁能帮帮我?非常感谢!!!

您更改了参数,但检测器未使用它们。设置它们然后设置检测器:

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)

注意:如果您希望使用此参数并且不以段错误结束,则必须将 True 用于 params.filterByArea