我想将我的图像分析脚本之一从Mathematica移植到Python OpenCV,但是我遇到了涉及的某个函数的问题。OpenCV简单的Blob检测器没有检测到所有的斑点
我设法将图像进行二值化和分水岭化,就像Mathematica中的一样。但是,筛选连接组件的属性的步骤似乎无法正常工作。
输入图像是如下:
然而,我试图运行下面的代码:
import cv2
import numpy as np
img = cv2.imread('test2.4.png', 1)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Set up the detector and configure its params.
params = cv2.SimpleBlobDetector_Params()
params.minDistBetweenBlobs = 0
params.filterByColor = True
params.blobColor = 255
params.filterByArea = True
params.minArea = 10
params.maxArea = 300000
params.filterByCircularity = False
params.filterByConvexity = False
params.filterByInertia = True
params.minInertiaRatio = 0.01
params.maxInertiaRatio = 1
detector = cv2.SimpleBlobDetector_create(params)
# Detect blobs.
keypointsb = detector.detect(img)
# Draw detected blobs as red circles.
im_with_keypoints = cv2.drawKeypoints(img, keypointsb, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
# Show keypoints
cv2.imwrite('test3.png',im_with_keypoints)
如该代码所示,我已经为团块的参数检测尽可能宽容。然而,大部分的斑点没有被检测到,也没有检测到分水斑点。
我检查了documentation for the function,并调整了其中的大部分阈值和repeatability(因为图像已经被二进制化)。为了让函数能够检测到所有的斑点,是否还有其他配置需要执行?
或者,是否有任何其他最近/孔更新的库,通过成分测量是能够过滤的?
@C王惊人的工作我必须尝试一下:D –