Created
January 30, 2023 07:37
-
-
Save agtbaskara/4c49277104c29babadf394487bd47ede to your computer and use it in GitHub Desktop.
Convert and resize images in a directory into grayscale images compatible with seqslam program
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 os | |
import argparse | |
import cv2 | |
# Setup Argument Parser | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-i', '--image_dir', type=str, default='', help='input directory') | |
parser.add_argument('-o', '--output_dir', type=str, default='', help='output directory') | |
args = parser.parse_args() | |
image_dir = args.image_dir | |
output_dir = args.output_dir | |
# create output directory | |
os.makedirs(os.path.join(output_dir), exist_ok=True) | |
file_list = os.listdir(image_dir) | |
for filename in file_list: | |
print(os.path.join(image_dir, filename)) | |
image = cv2.imread(os.path.join(image_dir, filename)) | |
image_resize = cv2.resize(image, (64, 32)) | |
image_grayscale = cv2.cvtColor(image_resize, cv2.COLOR_BGR2GRAY) | |
image_bgr = cv2.cvtColor(image_grayscale, cv2.COLOR_GRAY2BGR) | |
cv2.imwrite(os.path.join(output_dir, filename), image_bgr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment