如何在openCV 3中使用STAR探测器和python?

时间:2016-07-14 16:21:14

标签: python python-3.x opencv opencv3.0

我正在尝试在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

这是图像: grand_central_terminal.png

使用python 3.5和anaconda在64位的ubuntu 16.04LTS上运行。

1 个答案:

答案 0 :(得分:2)

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

kps = star.detect(gray)