Python OpenCV ORB 描述符:TypeError:自我类型不正确(必须是“Feature2D”或其派生词)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49971484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:20:25  来源:igfitidea点击:

OpenCV ORB descriptor: TypeError: Incorrect type of self (must be 'Feature2D' or its derivative)

pythonopencvimage-processingcomputer-visionopencv3.0

提问by Wesam

I followed this simple OpenCV Feature Matching exampleexactly:

我完全遵循了这个简单的OpenCV 特征匹配示例

import cv2

img = cv2.imread('box.png',0) # queryImage
orb = cv2.ORB()               # Initiate ORB detector

# find the keypoints and descriptors with ORB
kp1, des1 = orb.detectAndCompute(img, None)

and have been getting the following error:

并且一直收到以下错误:

TypeError: Incorrect type of self (must be 'Feature2D' or its derivative)

I'm using OpenCV 3.3.1

我正在使用 OpenCV 3.3.1

回答by Wesam

This is a OpenCV version compatibility issue. Just use cv2.ORB_create()instead of cv2.ORB().

这是 OpenCV 版本兼容性问题。只需使用cv2.ORB_create()代替cv2.ORB().

The code should look like:

代码应如下所示:

import cv2

img = cv2.imread('box.png',0) # queryImage
orb = cv2.ORB_create()        # Initiate SIFT detector

# find the keypoints and descriptors with SIFT
kp1, des1 = orb.detectAndCompute(img, None)

回答by Kaolin Fire

Note the python structures change "frequently" (in internet history years anyway). It's a good idea to pay attention to version.

注意 python 结构“经常”改变(无论如何在互联网历史上)。注意版本是个好主意。

Go here to find the right link: https://docs.opencv.org/

去这里找到正确的链接:https: //docs.opencv.org/

3.1.1 --> 3.1.0 --> https://docs.opencv.org/3.1.0/( OpenCV-Python Tutorials --> https://docs.opencv.org/3.1.0/d6/d00/tutorial_py_root.html) ... not as pretty as that (old) readthedocs site, but more accurate. :)

3.1.1 --> 3.1.0 --> https://docs.opencv.org/3.1.0/( OpenCV-Python 教程 --> https://docs.opencv.org/3.1.0/d6/ d00/tutorial_py_root.html) ... 不像那个(旧的)readthedocs 站点那么漂亮,但更准确。:)

回答by sameer maurya

use cv2.ORB_create() will do it

使用 cv2.ORB_create() 会做到