2022-04-09 18:40:43 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import utils
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
from video2x import Upscaler, Video2X
|
|
|
|
|
|
|
|
|
|
|
|
def test_upscaling():
|
|
|
|
video2x = Video2X()
|
2023-09-24 07:33:07 +00:00
|
|
|
|
|
|
|
output_path = Path("tests/data/test_video_output.mp4")
|
|
|
|
|
2022-04-09 18:40:43 +00:00
|
|
|
video2x.upscale(
|
2023-09-24 07:33:07 +00:00
|
|
|
Path("tests/data/test_video.mp4"),
|
2022-04-09 18:40:43 +00:00
|
|
|
output_path,
|
|
|
|
None,
|
|
|
|
720,
|
|
|
|
3,
|
|
|
|
5,
|
|
|
|
0,
|
|
|
|
"waifu2x",
|
|
|
|
)
|
|
|
|
output_path.unlink()
|
|
|
|
|
|
|
|
|
|
|
|
def test_upscale_image():
|
|
|
|
# initialize upscaler instance
|
2023-05-31 15:23:53 +00:00
|
|
|
upscaler = Upscaler()
|
2022-04-09 18:40:43 +00:00
|
|
|
|
2023-09-24 07:33:07 +00:00
|
|
|
image = Image.open("tests/data/test_image.png")
|
2022-04-09 18:40:43 +00:00
|
|
|
upscaled_image = upscaler.upscale_image(image, 1680, 960, "waifu2x", 3)
|
2023-09-24 07:33:07 +00:00
|
|
|
reference_image = Image.open("tests/data/test_image_ref.png")
|
2022-04-09 18:40:43 +00:00
|
|
|
assert utils.get_image_diff(upscaled_image, reference_image) < 0.5
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_scaling_tasks():
|
|
|
|
dimensions = [320, 240, 3840, 2160]
|
|
|
|
|
|
|
|
for algorithm, correct_answer in [
|
|
|
|
("waifu2x", [2, 2, 2, 2]),
|
|
|
|
["srmd", [3, 4]],
|
|
|
|
("realsr", [4, 4]),
|
|
|
|
("realcugan", [3, 4]),
|
|
|
|
]:
|
|
|
|
assert Upscaler._get_scaling_tasks(*dimensions, algorithm) == correct_answer
|