Opencv Tutorials (Python)Errors & Solutions(LTS)

1. AttributeError: module ‘cv2’ has no attribute ‘SIFT’

Traceback (most recent call last):
  File "F:/PyCharm/pydir/t3.py", line 4, in <module>
    sift = cv2.SIFT()
AttributeError: module 'cv2' has no attribute 'SIFT'

原因:opencv将SIFT等算法整合到xfeatures2d集合里面了。变更后写法如下:

import cv2

img = cv2.imread('test3.jpg')
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
sift = cv2.xfeatures2d.SIFT_create()
kp = sift.detect(gray,None)
img=cv2.drawKeypoints(gray,kp,img)
cv2.imwrite('sift_keypoints.jpg',img)

2. TypeError: Incorrect type of self (must be ‘Feature2D’ or its derivative)
Opencv-3.1.0文档未更新。提供的代码不起作用。FAST algorithm in OpenCV 的例子应该修改为:

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('simple.jpg',0)

# Initiate FAST object with default values
fast = cv2.FastFeatureDetector_create(threshold=25)

# find and draw the keypoints
kp = fast.detect(img,None)
img2 = cv2.drawKeypoints(img, kp, None,color=(255,0,0))

print("Threshold: ", fast.getThreshold())
print("nonmaxSuppression: ", fast.getNonmaxSuppression())
print("neighborhood: ", fast.getType())
print("Total Keypoints with nonmaxSuppression: ", len(kp))

cv2.imwrite('fast_true.png',img2)

# Disable nonmaxSuppression
fast.setNonmaxSuppression(0)
kp = fast.detect(img,None)

print ("Total Keypoints without nonmaxSuppression: ", len(kp))

img3 = cv2.drawKeypoints(img, kp, None, color=(255,0,0))

cv2.imwrite('fast_false.png',img3)

3. AttributeError: ‘module’ object has no attribute ‘FeatureDetector_create’

orb = cv2.ORB()

Regarding the 3.1 version, these functions have been removed in favor of functions like

detector = cv2.TYPE_create()

where TYPE can be ORB or other detector of your choosing but not SURF and SIFT which have been moved to a nonfree package.
4. TypeError: Required argument ‘outImage’ (pos 3) not found

img2 = cv2.drawKeypoints(img,kp,color=(0,255,0), flags=0)
img2 = cv2.drawKeypoints(img,kp,img,color=(0,255,0), flags=0)
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值