Created
December 15, 2021 21:42
-
-
Save yasushisakai/90db5877a823d6fd0190ee469ff60332 to your computer and use it in GitHub Desktop.
upscale images using opencv + deeplearning
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 | |
from cv2 import dnn_superres | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--in_dir', help='where is the images?') | |
parser.add_argument('--out_dir', help='where should I save the images?') | |
parser.add_argument('--num', help='id'); | |
if __name__ == "__main__": | |
args = parser.parse_args() | |
num = args.num.zfill(4); | |
# image path | |
image_path = f'{args.in_dir}/upscaled_{num}.png' | |
# Create an SR object | |
sr = dnn_superres.DnnSuperResImpl_create() | |
# Read image | |
image = cv2.imread(image_path); | |
# Read the desired model | |
path = "models/EDSR_x3.pb" | |
sr.readModel(path) | |
# Set the desired model and scale to get correct pre- and post-processing | |
sr.setModel("edsr", 3) | |
# Upscale the image | |
result = sr.upsample(image) | |
# Save the image | |
cv2.imwrite(f'{args.out_dir}/upscaled_{num}.png', result) | |
print(f'upscaled {num}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment