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,16 +104,13 @@ 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 self.processing_queue.put(
# there wouldn't be a "previous image" (
if previous_image is not None: frame_index,
self.processing_queue.put( (previous_image, image),
( self.processing_settings,
frame_index,
(previous_image, image),
self.processing_settings,
)
) )
)
previous_image = image previous_image = image
frame_index += 1 frame_index += 1

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,11 +74,15 @@ class Upscaler(multiprocessing.Process):
time.sleep(0.1) time.sleep(0.1)
continue continue
difference = ImageChops.difference(image0, image1) difference_ratio = -1
difference_stat = ImageStat.Stat(difference) if image0 is not None:
difference_ratio = ( difference = ImageChops.difference(image0, image1)
sum(difference_stat.mean) / (len(difference_stat.mean) * 255) * 100 difference_stat = ImageStat.Stat(difference)
) difference_ratio = (
sum(difference_stat.mean)
/ (len(difference_stat.mean) * 255)
* 100
)
# if the difference is lower than threshold # if the difference is lower than threshold
# process the interpolation # process the interpolation
@ -150,8 +154,9 @@ class Upscaler(multiprocessing.Process):
else: else:
# make sure the previous frame has been processed # make sure the previous frame has been processed
while self.processed_frames[frame_index - 1] is None: if frame_index > 0:
time.sleep(0.1) while self.processed_frames[frame_index - 1] is None:
time.sleep(0.1)
# make the current image the same as the previous result # make the current image the same as the previous result
self.processed_frames[frame_index] = self.processed_frames[ self.processed_frames[frame_index] = self.processed_frames[

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,
) )