python - opencv simpleblobdetector - 获取已识别 blob 的 blob 属性

标签 python opencv

我正在使用 opencv 中的 simpleblobdetector 和 python 来识别图像中的 Blob 。

我能够让简单的 Blob 检测器工作,并为我提供已识别 Blob 的位置。但是我也可以得到已识别 Blob 的惯性/凸性/圆度/等属性吗?

img = cv2.imread('image.png', cv2.IMREAD_GRAYSCALE)

# set up blob detector params
detector_params = cv2.SimpleBlobDetector_Params()
detector_params.filterByInertia = True
detector_params.minInertiaRatio = 0.001
detector_params.filterByArea = True
detector_params.maxArea = 10000000
detector_params.minArea = 1000
detector_params.filterByCircularity = True
detector_params.minCircularity = 0.0001
detector_params.filterByConvexity = True
detector_params.minConvexity = 0.01

detector = cv2.SimpleBlobDetector_create(detector_params)

# Detect blobs.
keypoints = detector.detect(img)

# print properties of identified blobs
for p in keypoints:
    print(p.pt) # locations of blobs
    # circularity???
    # inertia???
    # area???
    # convexity???
    # etc...

谢谢

最佳答案

根据 opencv.org,检测器返回的关键点不包含有关找到它们的算法的任何信息:

cv::KeyPoint: Data structure for salient point detectors.

The class instance stores a keypoint, i.e. a point feature found by one of many available keypoint detectors, such as Harris corner detector, cv::FAST, cv::StarDetector, cv::SURF, cv::SIFT, cv::LDetector etc.

The keypoint is characterized by the 2D position, scale (proportional to the diameter of the neighborhood that needs to be taken into account), orientation and some other parameters.

您可以绘制关键点,显示大小和旋转:

img = cv2.drawKeypoints(img, keypoints, None, color=(0,255,0), flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

关于python - opencv simpleblobdetector - 获取已识别 blob 的 blob 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41032639/

相关文章:

python - cx_freeze 不适用于 __init__ == __main__

opencv - 如何编译与 libstdc++ 静态链接的 OpenCV

Python JSON 提取

python - 带有嵌套 JSON 对象的 Pandas

c++ - opencv中的 mask

c++ - 通过引用传递一个 mat 对象 OpenCv

visual-studio-2010 - 如何使用 opencv 创建 cvSobel 函数

ubuntu - 我在哪里可以找到要在 Ubuntu 8.10 中安装的这些库?

Python双端队列范围?

python - 在 Python 中,函数是执行所需操作的代码块,而方法是特定于某些对象的函数。这个说法是真的吗?