gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 17:47:33 26 4
gpt4 key购买 nike

多数民众赞成在我的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))

最佳答案

再次在这里,就像在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)

关于python - TypeError:不能理解的数据类型opencv python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31713966/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com