为什么改变参数后斑点检测结果不改变?



我在以下网站获得了blob检测程序:https://www.learnopencv.com/blob-detection-using-opencv-python-c/

这是非常有用的,但我发现在我改变参数值后,结果没有任何变化。例如:即使我将颜色参数设置为255(它用于检测较亮的斑点),仍然可以检测到深色斑点。同样,在我改变最小面积的值后,也可以检测到最小的blob。

似乎没有什么变化,结果总是这样:斑点检测结果下面是代码:

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,而不是在段故障时结束。

相关内容

  • 没有找到相关文章

最新更新