【发布时间】:2016-02-29 09:10:52
【问题描述】:
我正在尝试将我的一个图像分析脚本从 Mathematica 移植到 Python OpenCV,但是我在使用其中一个函数时遇到了问题。
我设法对图像进行二值化和分水岭处理,就像在 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)
从代码中可以看出,我已将 blob 检测的参数设置为尽可能宽松。但是,没有检测到很大比例的斑点,也没有检测到分水岭分裂的斑点。
我检查了documentation for the function 并调整了大多数,除了阈值和repeatability(因为图像已经二值化了)。为了让函数检测所有存在的 blob,我应该执行任何其他配置吗?
或者,是否有任何其他最近/更新良好的库能够通过组件测量进行过滤?
【问题讨论】:
标签: python opencv computer-vision