简体   繁体   English

TypeError:不能理解的数据类型opencv python

[英]TypeError: data type not understood opencv python

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 ? 多数民众赞成在我的python3 opencv3代码我运行此代码时收到此错误,但我还没有完成它,那是该错误可以帮助一些吗?

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 1.在2张图片中找到关键点
2. Calculate descriptors for the two images 2.计算两个图像的描述符
3. Perform the matching. 3.执行匹配。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM