【问题标题】:Why won't OpenCV SimpleBlobDetector detect the blobs in this image?为什么 OpenCV SimpleBlobDetector 不能检测到这张图片中的斑点?
【发布时间】:2019-06-21 18:17:42
【问题描述】:

我正在尝试检测图像中的斑点,如下图:

尽管如此,没有检测到 blob。我检查了一些测试图像,以下代码工作正常。我也尝试调整参数,但没有任何成功。知道我做错了什么吗?

这是我正在使用的代码:

procpred = cv2.bitwise_not(procpred)
blur = cv2.blur(procpred, (15,15), 0)

params = cv2.SimpleBlobDetector_Params() 
# Change thresholds
params.minThreshold = 10
params.maxThreshold = 200

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

# Filter by Circularity
params.filterByCircularity = False
params.minCircularity = 0.1

# Filter by Convexity
params.filterByConvexity = False
params.minConvexity = 0.87

# Filter by Inertia
params.filterByInertia = False
params.minInertiaRatio = 0.01

# Create a detector with the parameters
ver = (cv2.__version__).split('.')
if int(ver[0]) < 3 :
    detector = cv2.SimpleBlobDetector(params)
else: 
    detector = cv2.SimpleBlobDetector_create(params)

# Detect blobs.
keypoints = detector.detect(blur)
print(keypoints)

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

plt.imshow(im_with_keypoints)

【问题讨论】:

  • procpred 是您提供的图像还是其他任何东西(例如,经过一些处理)?如果可能,请提供代码在其中起作用的另一张图片。
  • 我的回答解决了你的问题吗?如果是这样,请考虑接受它作为您的答案 - 通过单击计票旁边的空心对勾/复选标记。如果没有,请说出什么不起作用,以便我或其他人可以进一步帮助您。谢谢。 meta.stackexchange.com/questions/5234/…

标签: python opencv blob


【解决方案1】:

不确定你在代码开头做了什么,但我这样做了,它似乎工作正常:

#!/usr/bin/env python3

import cv2
import numpy as np

# Read image
im = cv2.imread("blobs.png", cv2.IMREAD_GRAYSCALE)

params = cv2.SimpleBlobDetector_Params() 
# Change thresholds
params.minThreshold = 10
params.maxThreshold = 200

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

# Filter by Circularity
params.filterByCircularity = False
params.minCircularity = 0.1

# Filter by Convexity
params.filterByConvexity = False
params.minConvexity = 0.87

# Filter by Inertia
params.filterByInertia = False
params.minInertiaRatio = 0.01

# Create a detector with the parameters
ver = (cv2.__version__).split('.')
if int(ver[0]) < 3 :
    detector = cv2.SimpleBlobDetector(params)
else: 
    detector = cv2.SimpleBlobDetector_create(params)

# Detect blobs.
keypoints = detector.detect(im)
print(keypoints)
im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.imwrite("result.png",im_with_keypoints)

【讨论】:

    猜你喜欢
    • 2021-02-19
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 1970-01-01
    相关资源
    最近更新 更多