例如SimpleBlobDetector

例如SimpleBlobDetector

本文介绍了如何正确使用Feature2D(例如SimpleBlobDetector)? (Python + OpenCV)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用一些简单的代码来运行blob检测:

I'm trying to run blob detection using some simple code:

img = cv2.imread(args["image"])
height, width, channels = img.shape

params = cv2.SimpleBlobDetector_Params()

params.filterByColor = True
params.blobColor = 0

blob_detector = cv2.SimpleBlobDetector(params)
keypoints = blob_detector.detect(img)

但是我仍然出现以下错误:

However I keep getting the following error:

Traceback (most recent call last):
  File "test2.py", line 37, in <module>
    keypoints = blob_detector.detect(img)
TypeError: Incorrect type of self (must be 'Feature2D' or its derivative)

有人知道怎么了吗?

推荐答案

如果您的OpenCV版本是2.x,请使用cv2.SimpleBlobDetector().否则,如果您的OpenCV版本是3.x (or 4.x),则使用cv2.SimpleBlobDetector_create创建检测器.

If your OpenCV version is 2.x, then use cv2.SimpleBlobDetector(). Otherwise if your OpenCV version 3.x (or 4.x), then use cv2.SimpleBlobDetector_create to create the detector.

## check opencv version and construct the detector
is_v2 = cv2.__version__.startswith("2.")
if is_v2:
    detector = cv2.SimpleBlobDetector()
else:
    detector = cv2.SimpleBlobDetector_create()

## detect
kpts = detector.detect(img)

这篇关于如何正确使用Feature2D(例如SimpleBlobDetector)? (Python + OpenCV)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:57