You must use cv2 . Legacy uses cvmat. But numpy arrays are very easy to use.
As @ abid-rahman-k suggested , you can use hstack (which I did not know about), so I used this.
h1, w1 = img.shape[:2] h2, w2 = img1.shape[:2] nWidth = w1+w2 nHeight = max(h1, h2) hdif = (h1-h2)/2 newimg = np.zeros((nHeight, nWidth, 3), np.uint8) newimg[hdif:hdif+h2, :w2] = img1 newimg[:h1, w2:w1+w2] = img
But if you want to work with Legacy code, this should help
Suppose img0 is greater than image height
nW = img0.width+image.width nH = img0.height newCanvas = cv.CreateImage((nW,nH), cv.IPL_DEPTH_8U, 3) cv.SetZero(newCanvas) yc = (img0.height-image.height)/2 cv.SetImageROI(newCanvas,(0,yc,image.width,image.height)) cv.Copy(image, newCanvas) cv.ResetImageROI(newCanvas) cv.SetImageROI(newCanvas,(image.width,0,img0.width,img0.height)) cv.Copy(img0,newCanvas) cv.ResetImageROI(newCanvas)
Froyo
source share