Created
November 14, 2024 21:13
-
-
Save yuchen-xue/9454fe6595c425f6e878409fe8482b90 to your computer and use it in GitHub Desktop.
This function is useful for printing out multiple passport photos. It duplicates the input image and produces a 3*3 duplication of the input image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
WHITE = (255, 255, 255) | |
def dup_img_9( | |
file_in: str, file_out: str, pad_horizontal: int = 10, pad_vertical: int = 10 | |
): | |
""" | |
This function is useful for printing out multiple passport photos. | |
It duplicates the input image and produces a 3*3 duplication of the input image. | |
Args: | |
file_in (str): the path to the input image | |
file_out (str): the path to the output image | |
pad_horizontal (ing): the size of the horizontal white padding around each image | |
pad_vertical (ing): the size of the vertical white padding around each image | |
""" | |
# Read the original image | |
im = cv2.imread(file_in) | |
# Add white padding for each input image | |
im_pad = cv2.copyMakeBorder( | |
im, | |
pad_vertical, | |
pad_vertical, | |
pad_horizontal, | |
pad_horizontal, | |
cv2.BORDER_CONSTANT, | |
value=WHITE, | |
) | |
# Duplicate images | |
arr = np.concat((im_pad, im_pad, im_pad), axis=1) | |
arr = np.concat((arr, arr, arr), axis=0) | |
# Save the new image | |
cv2.imwrite(file_out, arr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment