超分辨率技术(2)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import cv2
from cv2 import dnn_superres

img_path = "D:/20210921_78339.png"
scale = 4
algorithm = "bicubic"

# 载入图像
img = cv2.imread(img_path)

# 创建模型
sr = dnn_superres.DnnSuperResImpl_create()

if algorithm == "bilinear":
img_new = cv2.resize(img, None, fx=scale, fy=scale, interpolation=cv2.INTER_LINEAR)
elif algorithm == "bicubic":
img_new = cv2.resize(img, None, fx=scale, fy=scale, interpolation=cv2.INTER_CUBIC)

print("Upsampling succeeded. \n")

# 保存图片
cv2.imwrite("saved.jpg", img_new)
0%