Skip to content

Instantly share code, notes, and snippets.

@agtbaskara
Created January 30, 2023 07:37
Show Gist options
  • Save agtbaskara/4c49277104c29babadf394487bd47ede to your computer and use it in GitHub Desktop.
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
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