Skip to content

Instantly share code, notes, and snippets.

@Saafke
Created March 31, 2020 10:03
Show Gist options
  • Save Saafke/e8380cc925ece7cf283f2d7726eb49d9 to your computer and use it in GitHub Desktop.
Save Saafke/e8380cc925ece7cf283f2d7726eb49d9 to your computer and use it in GitHub Desktop.
Python code for upscaling an image via OpenCV
import cv2
from cv2 import dnn_superres
# Create an SR object
sr = dnn_superres.DnnSuperResImpl_create()
# Read image
image = cv2.imread('./input.png')
# Read the desired model
path = "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("./upscaled.png", result)
@Swati81
Copy link

Swati81 commented Feb 18, 2022

not importing dnn_superres from opencv-contrib-python== 4.5.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment