gpt4 book ai didi

python - 为什么 OpenCV SimpleBlobDetector 无法检测到此图像中的 Blob ?

转载 作者:太空宇宙 更新时间:2023-11-03 23:08:32 27 4
gpt4 key购买 nike

我正在尝试检测图像中的 Blob ,如下图所示:

The image after color inversion

然而,没有检测到 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)

最佳答案

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

#!/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)

enter image description here

关于python - 为什么 OpenCV SimpleBlobDetector 无法检测到此图像中的 Blob ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54407187/

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