【问题标题】:SimpleBlobDetector Blob CountSimpleBlobDetector 斑点计数
【发布时间】:2016-02-27 17:35:29
【问题描述】:

如何确定在 Python 2.7 中使用 SimpleBlobDetector 找到的 blob 数量?我有示例代码查找和标记图像中的 blob,但还需要知道有多少 blob 与我的参数匹配。

#!/usr/bin/python

# Standard imports
import cv2
import numpy as np;
from matplotlib import pyplot as plt

# Read image
im = cv2.imread("blob.jpg")

# Setup SimpleBlobDetector parameters.
params = cv2.SimpleBlobDetector_Params()

# Change thresholds
params.minThreshold = 10
params.maxThreshold = 200

# Filter by Area.
params.filterByArea = True
params.minArea = 15

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

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

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

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

titles = ['Blobs Detected']
images = [im_with_keypoints]


for i in xrange(1):    
    plt.subplot(1,1,i+1), plt.imshow(images[i],'gray')
    plt.title(titles[i])
    plt.xticks([]), plt.yticks([])  # to hide tick values on X and Y axis    
plt.show()

【问题讨论】:

  • 显示一些代码来展示你迄今为止所做的尝试。这将鼓励其他人提供帮助。
  • 每个关键点都是一个 blob。只计算关键点。

标签: python python-2.7 opencv


【解决方案1】:

你只需要

nblobs = len(keypoints)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-25
    • 2019-06-21
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 2012-05-21
    • 2020-09-17
    • 1970-01-01
    相关资源
    最近更新 更多