I need to iterate with a Python functions into images dir, for every image I need to add extra bottom part:
I was thinking to load image, calculate dimension, create bigger black image, and paste on it:
import numpy as np
import cv2
def add_border(image):
s_img = cv2.imread(image)
dimensions = s_img.shape
blank_image = np.zeros((s_img.shape[0]+200,s_img.shape[1],3), np.uint8)
x_offset=y_offset=50
blank_image[y_offset:y_offset+s_img.shape[0], x_offset:x_offset+s_img.shape[1]] = s_img
cv2.imshow("black", blank_image)
cv2.imwrite('C:\\test\\' + 'black.jpg', blank_image)
return (True)
add_border('C:\\test\\img001.JPG')
I receive following error:
blank_image[y_offset:y_offset+s_img.shape[0], x_offset:x_offset+s_img.shape[1]] = s_img
ValueError: could not broadcast input array from shape (522,928,3) into shape (522,878,3)
Any suggestion? Thank you