问题
I'm trying to use the STAR detector in openCV 3, and it's throwing an error:
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
The error it gives is:
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
Here's the image:
Running on ubuntu 16.04LTS 64-bit with python 3.5 and anaconda.
回答1:
The error code -213
you are receiving indicates that the detectAndCompute
method is not implemented for the STAR detector. That is because STAR is only a feature detector, not a combination detector and descriptor. Your code can be fixed by calling the detect
method instead:
kps = star.detect(gray)
来源:https://stackoverflow.com/questions/38379365/how-to-use-star-detector-in-opencv-3-with-python