为什么改变参数后,斑点检测的结果没有变化?

2024-06-07 08:11:26 发布

您现在位置:Python中文网/ 问答频道 /正文

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

这是非常有用的,但是在我改变参数值之后,我发现结果没有任何变化。 比如:即使我将color的参数设置为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)

有人能帮我吗?非常感谢!!!在


Tags: oftheimportaswithnpparamscv2
1条回答
网友
1楼 · 发布于 2024-06-07 08:11:26

您可以更改参数,但探测器不使用这些参数。设置它们,然后设置探测器:

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)

注意:如果您希望使用此参数且不以segfault结尾,则必须将True用于params.filterByArea。在

相关问题 更多 >

    热门问题