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))
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.