aboutsummaryrefslogtreecommitdiffstats
path: root/main.py
blob: 7dfd3a46e27b05985c394f152d984862cc90106b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
"""Superscaler benchmarks. sorta."""
# https://learnopencv.com/super-resolution-in-opencv/
# https://github.com/xinntao/ESRGAN
# https://github.com/xinntao/Real-ESRGAN
# https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan

# modls
# https://github.com/Saafke/EDSR_Tensorflow/tree/master/models
# https://github.com/fannymonori/TF-ESPCN/tree/master/export
# https://github.com/Saafke/FSRCNN_Tensorflow/tree/master/models
# https://github.com/fannymonori/TF-LapSRN/tree/master/export

import time

import cv2


def edsr_superscaler(img):
    """EDSR superscaler."""
    sr = cv2.dnn_superres.DnnSuperResImpl_create()
    path = "./models/EDSR_x4.pb"
    sr.readModel(path)
    sr.setModel("edsr", 4)
    result = sr.upsample(img)
    return result


def espcn_superscaler(img):
    """ESPCN superscaler."""
    sr = cv2.dnn_superres.DnnSuperResImpl_create()
    path = "./models/ESPCN_x3.pb"
    sr.readModel(path)
    sr.setModel("espcn", 3)
    result = sr.upsample(img)
    return result


def fsrcnn_superscaler(img):
    """FSRCNN superscaler"""
    sr = cv2.dnn_superres.DnnSuperResImpl_create()
    path = "./models/FSRCNN_x3.pb"
    sr.readModel(path)
    sr.setModel("fsrcnn", 3)
    result = sr.upsample(img)
    return result


def lapsrn_superscaler(img):
    """LapSRN superscaler"""
    sr = cv2.dnn_superres.DnnSuperResImpl_create()
    path = "./models/LapSRN_x8.pb"
    sr.readModel(path)
    sr.setModel("lapsrn", 8)
    result = sr.upsample(img)
    return result


def main():
    img = cv2.imread("./21-o.jpg")

    time_begin = time.time()
    edsr_super_img = edsr_superscaler(img)
    cv2.imwrite("./edsr_super.jpg", edsr_super_img)
    time_end = time.time()
    print("time {}".format(time_end - time_begin))

    time_begin = time.time()
    espcn_super_img = espcn_superscaler(img)
    cv2.imwrite("./espcn_super.jpg", espcn_super_img)
    time_end = time.time()
    print("time {}".format(time_end - time_begin))

    time_begin = time.time()
    fsrcnn_super_img = fsrcnn_superscaler(img)
    cv2.imwrite("./fsrcnn_super.jpg", fsrcnn_super_img)
    time_end = time.time()
    print("time {}".format(time_end - time_begin))

    time_begin = time.time()
    lapsrn_super_img = lapsrn_superscaler(img)
    cv2.imwrite("./lapsrn_super_img.jpg", lapsrn_super_img)
    time_end = time.time()
    print("time {}".format(time_end - time_begin))


if __name__ == "__main__":
    main()