Concatenate Images Vertically and Horizontally Using Python OpenCV

In this tutorial, we will learn how to concatenate images vertically and horizontally using python opencv.

1. Import library

import numpy
import cv2

2. Read an image using opencv

img = cv2.imread('C:/Users/N/Desktop/Test.jpg')

3. Concatenate images vertically

verticalAppendedImg = numpy.vstack((img,img))

4. Concatenate images horizontally

horizontalAppendedImg = numpy.hstack((img,img,img))

5. Show final images

cv2.imshow('Vertical Appended', verticalAppendedImg)
cv2.imshow('Horizontal Appended', horizontalAppendedImg)
 
cv2.waitKey(0)
cv2.destroyAllWindows()