0

thats my python3 opencv3 code i get this error when i run this code i did't finished it yet that's are the error can some one help ?

line 19, in <module>
matches = bf.match(np.array(kpTrain, desTrain))
TypeError: data type not understood

that's my code

import numpy as np
import cv2


camera = cv2.VideoCapture(0)
orb = cv2.ORB_create()

img = cv2.imread('/home/shar/home.jpg')
imggray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)


kpTrain = orb.detect(imggray,None)
kpTrain, desTrain = orb.compute(imggray, kpTrain)

ret, imgCamColor = camera.read()

bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)

matches = bf.match(np.array(kpTrain, desTrain))
6
  • Try - bf.match(kpTrain, desTrain) Commented Jul 30, 2015 at 1:56
  • 1
    TypeError: queryDescriptors is not a numpy array, neither a scalar Commented Jul 30, 2015 at 2:09
  • Ok sorry , try - bf.match(np.array(kpTrain),np.array(desTrain)) Commented Jul 30, 2015 at 2:10
  • 1
    don't be sorry i get a new erorr TypeError: queryDescriptors data type = 17 is not supported Commented Jul 30, 2015 at 2:14
  • it's a conceptual error: you have to match 2 descriptors from 2 images, not the keypoints and descriptors from 1 image Commented Jul 30, 2015 at 7:21

1 Answer 1

1

Again here, as in this question you are trying to to match keypoints and the descriptors from one image. The matching of descriptors is done with two images.
1. Find Keypoints in 2 images
2. Calculate descriptors for the two images
3. Perform the matching.

In your case it should be something like this:

import numpy as np
import cv2

orb = cv2.ORB_create()

img = cv2.imread('/home/shar/home.jpg')
imggray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# load second image in grayscale
imggray2=cv2.imread('/path/to/image.jpg',0)

#Detector and descriptors for 1st image
kpTrain = orb.detect(imggray,None)
kpTrain, desTrain = orb.compute(imggray, kpTrain)

#Detector and descriptors for 2nd image
kpTrain2 = orb.detect(imggray2,None)
kpTrain2, desTrain2 = orb.compute(imggray2, kpTrain2)

bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)

matches = bf.match(desTrain,desTrain2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.