Image Processing #8 - Image Append
Occasionally, images need to be pasted horizontally or vertically. In this article, we will implement this function using the numpy function commonly used in OpenCV and PIL. Convert image to numpy array The first thing you must do is to convert the image to a numpy array. This is explained at https://opencvcooking.blogspot.com/2019/11/basic-cooking-1.html . OpenCV Image to numpy vice versa OpenCV images (Mat) have a numpy array and can be used directly without conversion. import cv2 img = cv2 . imread( "dog.jpg" , cv2 . IMREAD_COLOR) print(type(img)); And you can convert numpy array to an OpenCV image using fromarray function. import cv2 img = cv . fromarray(array) height, width, channels = img . shape PIL Image to numpy vice versa from PIL import Image im = Image . fromarray(np . uint8(array)) array = np . asarray(im, dtype = "uint8" ) And you can convert numpy array to an PIL image using fromarray functio...