Ask Your Question

SK's profile - activity

2017-09-20 12:17:52 -0600 received badge  Notable Question (source)
2017-09-20 12:17:52 -0600 received badge  Popular Question (source)
2016-03-07 04:27:22 -0600 received badge  Editor (source)
2016-03-07 03:36:46 -0600 asked a question Image data cannot convert to float

The error is for the following line in the code:- plt.imshow(img3), plt.show() Please find the attachments. One of the two attachments contains the source code, whereas the second contains the Traceback Error.

Text Version of Code.:-

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

img1 = cv2.imread('../CarData/TestImages/test-0.pgm',0)# queryImage
img2 = cv2.imread('../CarData/TestImages/test-1.pgm',0) # trainImage

# Initiate SIFT detector
#sift = cv2.SIFT()
#Initiate the ORB detector
orb = cv2.ORB_create()

# find the keypoints and descriptors with SIFT
#kp1, des1 = sift.detectAndCompute(img1,None)
#kp2, des2 = sift.detectAndCompute(img2,None)

# find the keypoints and descriptors with ORB
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)

# BFMatcher with default params
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1,des2, k=2)

# Apply ratio test
good = []
for m,n in matches:
    if m.distance < 0.75*n.distance:
        good.append([m])

# cv2.drawMatchesKnn expects list of lists as matches.
img_temp = np.zeros((1,1))
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,img_temp,flags=2)

----------------------------------------------------------------------------------------------------------------------------------------------------------------------
plt.imshow(img3),plt.show()

BFMatchingthree.png BFMatching_three.png