Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Layout of the output array img is incompatible with cv::Mat (step[ndims-1] != elemsize or step[1] != elemsize*nchannels)

Tags:

python

opencv

I get this error: Layout of the output array img is incompatible with cv::Mat (step[ndims-1] != elemsize or step[1] != elemsize*nchannels) when running the following code:

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)

This code is for getting corresponding features in two similar images from different views. Any help please ??

like image 264
Fadi Makram Avatar asked May 09 '13 12:05

Fadi Makram


1 Answers

change this line:

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

to:

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

like image 84
M.ElSaka Avatar answered Oct 23 '22 22:10

M.ElSaka