【问题标题】:OpenCV 3 in Python 2.7 gives error while using Brute-Force MatcherPython 2.7 中的 OpenCV 3 在使用 Brute-Force Matcher 时出错
【发布时间】:2015-08-05 12:58:47
【问题描述】:

我在 Windows 上使用 OpenCV 3 和 Python 2.7。

这是我正在使用的代码:

import numpy as np
import cv2
from matplotlib import pyplot as plt
img1 = cv2.imread('feature.jpg',0)  
img2 = cv2.imread('large-pic.jpg',0)
orb = cv2.ORB_create()
# cv2.ORB() doesn't work as mentioned in the documentation

kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = bf.match(des1,des2)
matches = sorted(matches, key = lambda x:x.distance)

img3 = np.zeros((1,1))
img4 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10],img3,flags=2)
plt.imshow(img4)

在尝试使用 ORB 描述符实现蛮力特征匹配时,我在 plt.imshow(img4) 之后收到以下错误:

Traceback (most recent call last):
  File "<pyshell#18>", line 1, in <module>
    plt.imshow(img4)
   File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 2368, in imshow
    ret = ax.imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, **kwargs)
   File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 6734, in imshow
im.set_data(X)
  File "C:\Python27\lib\site-packages\matplotlib\image.py", line 412, in set_data
    raise TypeError("Image data can not convert to float")
TypeError: Image data can not convert to float

可能是什么原因?

【问题讨论】:

    标签: python opencv computer-vision opencv3.0


    【解决方案1】:

    根据this,你应该这样做:

    img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10], flags=2)
    plt.imshow(img3),plt.show()
    

    【讨论】:

    • 感谢 Miki 和 J. Richard Snape 的解决方案 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-13
    • 1970-01-01
    • 2016-10-04
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    相关资源
    最近更新 更多