gpt4 book ai didi

python - 使用opencv(python)时出现 "orb.detectAndCompute"错误

转载 作者:太空宇宙 更新时间:2023-11-03 23:12:40 28 4
gpt4 key购买 nike

我正在尝试使用 ORB 来查找先前生成的频谱图的关键点和描述符。我有这段代码:

start = time.time()
x = 1
img = range(101)
imgname = range(101)

# Directory Images
os.chdir("/home/undead/Documents/TempSongSpectro/") #1,2,3
for file in glob.glob("*.png"):
img[x] = cv2.imread(file, 0) # trainImage
imgname[x] = os.path.splitext(file)[0]
# print "%s: %d " % (os.path.splitext(file)[0],(x))
x = x + 1

# Initiate ORB detector
orb = cv2.ORB_create(3000)

# find the keypoints and descriptors with ORB
a = 1
des = range(101)
kp = range(101)

for a in range(1, 101):
kp[a], des[a] = orb.detectAndCompute(img[a], None)

end = time.time()
print("Initialize time: %f seconds" % (end - start))

但是,我得到了错误:

OpenCV Error: Assertion failed (depth == CV_8U || depth == CV_16U || depth == CV_32F) in cvtColor, file /home/undead/opencv/opencv-3.2.0/modules/imgproc/src/color.cpp, line 9710

Traceback (most recent call last):
File "/home/undead/PycharmProjects/KavTest/Test3.py", line 37, in <module>
kp[a], des[a] = orb.detectAndCompute(img[a], None)

cv2.error: /home/undead/opencv/opencv-3.2.0/modules/imgproc/src/color.cpp:9710: error: (-215) depth == CV_8U || depth == CV_16U || depth == CV_32F in function cvtColor

据我所知,错误可能与 kp、des 或 img 的数据类型有关,但我不太确定如何解决它。有人可以提供一些帮助吗?

最佳答案

我认为您的代码有问题。

这是我的代码,几乎是一样的。

start = time.time()

imgnames = glob.glob("/home/undead/Documents/TempSongSpectro/*.png")
#imgnames = imgnames[:100]

sz = len(imgnames)
imgs = list(range(sz))

for i, name in enumerate(imgnames, start=0):
imgs[i] = cv2.imread(name, 0)

orb = cv2.ORB_create(3000)

# find the keypoints and descriptors with ORB
des = list(range(sz))
kp = list(range(sz))

for i in range(sz):
kp[i], des[i] = orb.detectAndCompute(img[i], None)

end = time.time()
print("Initialize time: {:.4f} seconds".format(end - start))

关于python - 使用opencv(python)时出现 "orb.detectAndCompute"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46514455/

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