fixed upscaler diff threshold bug

This commit is contained in:
K4YT3X 2021-07-06 01:27:32 +00:00
parent 7eabac2175
commit ac80de9399
4 changed files with 26 additions and 19 deletions

View File

@ -104,9 +104,6 @@ class VideoDecoder(threading.Thread):
"RGB", (self.input_width, self.input_height), buffer "RGB", (self.input_width, self.input_height), buffer
) )
# if this is the first frame
# there wouldn't be a "previous image"
if previous_image is not None:
self.processing_queue.put( self.processing_queue.put(
( (
frame_index, frame_index,

View File

@ -56,6 +56,11 @@ class Interpolator(multiprocessing.Process):
time.sleep(0.1) time.sleep(0.1)
continue continue
# if image0 is None, image1 is the first frame
# skip this round
if image0 is None:
continue
difference = ImageChops.difference(image0, image1) difference = ImageChops.difference(image0, image1)
difference_stat = ImageStat.Stat(difference) difference_stat = ImageStat.Stat(difference)
difference_ratio = ( difference_ratio = (

View File

@ -74,10 +74,14 @@ class Upscaler(multiprocessing.Process):
time.sleep(0.1) time.sleep(0.1)
continue continue
difference_ratio = -1
if image0 is not None:
difference = ImageChops.difference(image0, image1) difference = ImageChops.difference(image0, image1)
difference_stat = ImageStat.Stat(difference) difference_stat = ImageStat.Stat(difference)
difference_ratio = ( difference_ratio = (
sum(difference_stat.mean) / (len(difference_stat.mean) * 255) * 100 sum(difference_stat.mean)
/ (len(difference_stat.mean) * 255)
* 100
) )
# if the difference is lower than threshold # if the difference is lower than threshold
@ -150,6 +154,7 @@ class Upscaler(multiprocessing.Process):
else: else:
# make sure the previous frame has been processed # make sure the previous frame has been processed
if frame_index > 0:
while self.processed_frames[frame_index - 1] is None: while self.processed_frames[frame_index - 1] is None:
time.sleep(0.1) time.sleep(0.1)

View File

@ -378,8 +378,8 @@ def parse_arguments() -> argparse.Namespace:
"-t", "-t",
"--threshold", "--threshold",
type=float, type=float,
help="if the % difference between two adjacent frames exceeds this value, two images are deemed the same", help="if the % difference between two adjacent frames exceeds this value, two images are deemed the same; 0 is off",
default=0.1, default=0,
) )
# interpolator arguments # interpolator arguments
@ -400,7 +400,7 @@ def parse_arguments() -> argparse.Namespace:
"-t", "-t",
"--threshold", "--threshold",
type=float, type=float,
help="if the % difference between two adjacent frames exceeds this value, no interpolation will be performed", help="if the % difference between two adjacent frames exceeds this value, no interpolation will be performed; 0 is off",
default=10, default=10,
) )