多数民众赞成我的python3 opencv3代码当我运行此代码时我得到了这个错误我没有完成它但是错误可以帮助一些吗?
line 19, in <module>
matches = bf.match(np.array(kpTrain, desTrain))
TypeError: data type not understood
这是我的代码
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))
答案 0 :(得分:1)
再次在这里,就像在这个question中一样,你试图匹配一个图像中的关键点和描述符。描述符的匹配用两个图像完成
1.在2张图像中找到关键点
2.计算两个图像的描述符
3.执行匹配。
在你的情况下它应该是这样的:
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)