gpt4 book ai didi

python - 如何正确使用 Feature2D(如 SimpleBlobDetector)? (Python + OpenCV)

转载 作者:IT老高 更新时间:2023-10-28 21:08:03 27 4
gpt4 key购买 nike

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

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)

但是我不断收到以下错误:

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(或 4.x),则使用 cv2.SimpleBlobDetector_create 创建检测器。

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

关于python - 如何正确使用 Feature2D(如 SimpleBlobDetector)? (Python + OpenCV),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48136978/

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