4
我得到這個錯誤: 輸出數組img的佈局是與CV ::墊(!步驟[爲ndims-1] =可達elemsize或步驟[1] =可達elemsize * nchannels)不相容 運行下面的代碼時:輸出數組img的佈局與cv :: Mat不兼容(步驟[ndims-1]!= elemsize或步驟[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)
該代碼可用於兩個獲得相應的特徵來自不同視圖的類似圖像。 請幫忙嗎?
IY是一個很好的答案。問題在於「hstack」。我用兩行代碼替換了它。在每一個我只是複製每個圖像的位置。這比使用「hstack」要好得多。 – 2013-05-11 19:28:33
你能解釋一下底層的問題嗎?使用cv2.findContours時遇到同樣的錯誤。從您的回答中不清楚錯誤實際上是什麼意思,因爲您只提供解決OPs非常具體的問題。 – angela 2015-06-27 08:50:33