我收到此错误: 输出数组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)
此代码用于从不同视图中获取两个相似图像中的相应特征。 请帮忙吗?
答案 0 :(得分:2)
更改此行:
img = np.hstack((I1, I2))
为:
img = np.array(np.hstack((I1, I2)))