首页 文章

引发TypeError(“图像数据无法转换为浮动”)

提问于
浏览
1

所以我在使用python在opencv中进行特征提取 . 我得到了上面提到的错误 . 图像数据无法转换为浮动 . 我不明白这个错误 . 我使用的代码是:

import cv2
import matplotlib.pyplot as plt

img = cv2.imread('template.jpg',0)
img2 =cv2.imread('match.jpeg',0)

orb= cv2.ORB_create()
k1,d1=orb.detectAndCompute(img,None)
k2,d2=orb.detectAndCompute(img2,None)

bf=cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches =bf.match(d1,d2) 
matches=sorted(matches,key=lambda x:x.distance)

img3=cv2.drawMatches(img,k1,img2,k2,matches[:10],None,flags=2)
plt.imshow(img3)
plt.show()

帮我解决错误 . 我甚至提到了这里提出的类似问题 . 我什么都不明白 . 我是一个初学者...所以尝试解释一下 .

谢谢..

1 回答

  • 2

    此错误通常意味着您没有正确读取图像 . 我会添加一些这样的代码,以确保您实际获得图像:

    path1="template.jpg"
    if os.path.isfile(path1):
        img1 = cv2.imread(path1, 0)
    else:
        print ("The file " + path1 + " does not exist.")
    

相关问题