gpt4 book ai didi

python - 输出数组 img 的布局与 cv::Mat 不兼容(step[ndims-1] != elemsize 或 step[1] != elemsize*nchannels)

转载 作者:太空狗 更新时间:2023-10-30 00:14:59 25 4
gpt4 key购买 nike

我得到这个错误:输出数组 img 的布局与 cv::Mat 不兼容(step[ndims-1] != elemsize 或 step[1] != elemsize*nchannels)运行以下代码时:

I1 = cv2.imread('library1.jpg');
I2 = cv2.imread('library2.jpg');
# Load matching points
matches = np.loadtxt('library_matches.txt');
img = np.hstack((I1, I2))
# Plot corresponding points
radius = 2
thickness = 2
for m in matches:
# draw the keypoints
pt1 = (int(m[0]), int(m[1]))
pt2 = (int(m[2] + I1.shape[1]), int(m[3]))
lineColor = cv2.cv.CV_RGB(255, 0, 0)
ptColor = cv2.cv.CV_RGB(0, 255, 0)
cv2.circle(img, pt1, radius, ptColor, thickness)
cv2.line(img, pt1, pt2, lineColor, thickness)
cv2.circle(img, pt2, radius, ptColor, thickness)
cv2.imshow("Matches", img)

此代码用于从不同 View 获取两个相似图像中的相应特征。有什么帮助吗??

最佳答案

改变这一行:

img = np.hstack((I1, I2))

到:

img = np.array(np.hstack((I1, I2)))

关于python - 输出数组 img 的布局与 cv::Mat 不兼容(step[ndims-1] != elemsize 或 step[1] != elemsize*nchannels),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16461560/

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