如何在 python 的 openCV 3 中使用 STAR 检测器?

How to use STAR detector in openCV 3 with python?

我正在尝试在 openCV 3 中使用 STAR 检测器,但出现错误:

import cv2

image = cv2.imread('grand_central_terminal.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

star = cv2.xfeatures2d.StarDetector_create()
(kps, descs) = star.detectAndCompute(gray, None)
print("# of keypoints: {}".format(len(kps))) # should be 459

它给出的错误是:

Traceback (most recent call last):
  File "quiz.py", line 8, in <module>
    (kps, descs) = star.detectAndCompute(gray, None)
cv2.error: /home/travis/miniconda/conda-bld/work/opencv-3.1.0/modules/features2d/src/feature2d.cpp:144: error: (-213)  in function detectAndCompute

图片如下:

运行 ubuntu 16.04LTS 64 位 python 3.5 和 anaconda。

您收到的错误代码 -213 表示 detectAndCompute 方法未针对 STAR 检测器实施。那是因为 STAR 只是一个特征检测器,而不是检测器和描述符的组合。您的代码可以通过调用 detect 方法来修复:

kps = star.detect(gray)