gpt4 book ai didi

python - SimpleBlobDetector Blob 计数

转载 作者:太空宇宙 更新时间:2023-11-03 22:52:56 24 4
gpt4 key购买 nike

如何确定在 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()

最佳答案

你只需要

nblobs = len(keypoints)

关于python - SimpleBlobDetector Blob 计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35673072/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com