【问题标题】:why the result of blob detection does not change after the change of parameters?为什么参数变化后blob检测结果没有变化?
【发布时间】:2016-08-16 16:02:40
【问题描述】:

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

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

【问题讨论】:

    标签: python opencv blob


    【解决方案1】:

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

    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

    【讨论】:

      猜你喜欢
      • 2021-11-01
      • 2015-08-04
      • 2021-09-22
      • 2017-06-26
      • 1970-01-01
      • 1970-01-01
      • 2021-05-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多