How to use STAR detector in openCV 3 with python?

杀马特。学长 韩版系。学妹 提交于 2020-01-04 09:22:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!