gpt4 book ai didi

python - 使用 "cv2.drawMatches"时,出现错误 : "outImg is not a numpy array, neither a scalar"

转载 作者:行者123 更新时间:2023-12-02 16:13:43 24 4
gpt4 key购买 nike

关闭。这个问题需要debugging details .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

4年前关闭。




Improve this question




我有以下 ORB 匹配关键帧的代码:

import numpy as np
import cv2
from matplotlib import pyplot as plt

img1 = cv2.imread("C:\\Users\\user\\Desktop\\picture\\Pikachu_Libre.png",0)
img2 = cv2.imread("C:\\Users\\user\\Desktop\\picture\\Pikachu_Libre.png",0)
# Initiate STAR detector
orb = cv2.ORB_create()

# find the keypoints with ORB
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
# Match descriptors.
matches = bf.match(des1,des2)
# Sort them in the order of their distance.
matches = sorted(matches, key = lambda x:x.distance)
# Draw first 10 matches.
img3 = cv2.drawMatches(img1,kp1,img2,kp2,None,matches[:10], flags=2)
plt.imshow(img3),plt.show()

运行后出现以下错误:
img3 = cv2.drawMatches(img1,kp1,img2,kp2,None,matches[:10], flags=2)
TypeError: outImg is not a numpy array, neither a scalar

任何人都可以帮助我吗?

最佳答案

注意 cv2.drawMatches() 的原型(prototype):

cv2.drawMatches(img1, keypoints1, img2, keypoints2, matches1to2, outImg[, matchColor[, singlePointColor[, matchesMask[, flags]]]]) -> outImg

所以你的参数顺序是错误的。

来自 :
img3 = cv2.drawMatches(img1,kp1,img2,kp2,None,matches[:10], flags=2)

:
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10], None,flags=2)

关于python - 使用 "cv2.drawMatches"时,出现错误 : "outImg is not a numpy array, neither a scalar",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48046864/

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