我使用opencv 3.0.0和python 2.7.5_x32
这是我的代码(ORB_feature_detection):
import numpy as np
import cv2
from matplotlib import pyplot as plt
img1 = cv2.imread('C:\\Python27\\madar1.jpg',0) # queryImage
img2 = cv2.imread('C:\\Python27\\madar2.jpg',0) # trainImage
# Initiate SIFT detector
orb = cv2.ORB_create()
# line 12
# find the keypoints and descriptors with SIFT
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
# create BFMatcher object
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
# Match descriptors.
matches = bf.match(des1,des2)
# Sort them in the order of their distance.
matches = sorted(matches, key = lambda x:x.distance)
# Draw first 10 matches.
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10], flags=2)
plt.imshow(img3),plt.show()
cv2.waitKey()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
这是错误信息,错误信息在kp1,des1 = orb.detectAndCompute(img1,None)部分,我在opencv 2.4.11上工作,它在opencv 3.0.0上不起作用!
Traceback (most recent call last):
File "C:\Python27\orb_matcher.py", line 12, in <module>
kp1, des1 = orb.detectAndCompute(img1,None)
error: ..\..\..\modules\python\src2\cv2.cpp:163: error: (-215) The data should normally be NULL! in function NumpyAllocator::allocate
Run Code Online (Sandbox Code Playgroud)
请帮助我,我该怎么做才能做到这一点?
您可以尝试在导入cv2之后添加此脚本,而其他人cv2.ocl.setUseOpenCL(False)则解决了我的问题.
| 归档时间: |
|
| 查看次数: |
5346 次 |
| 最近记录: |