输出数组img的布局与cv::Mat不兼容(步骤[ndims-1]!=elemsize或步骤[1]!=元素化*n通道)

2024-06-21 20:32:21 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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)

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


Tags: 代码img步骤cv2cvintjpgmatches