fixed another upscaler diff threshold calculation error

This commit is contained in:
K4YT3X 2021-07-06 02:19:38 +00:00
parent ac80de9399
commit f283a12a0b
2 changed files with 17 additions and 18 deletions

View File

@ -74,7 +74,7 @@ class Upscaler(multiprocessing.Process):
time.sleep(0.1) time.sleep(0.1)
continue continue
difference_ratio = -1 difference_ratio = 0
if image0 is not None: 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)
@ -85,9 +85,22 @@ class Upscaler(multiprocessing.Process):
) )
# if the difference is lower than threshold # if the difference is lower than threshold
# process the interpolation # skip this frame
if difference_ratio < difference_threshold: if difference_ratio < difference_threshold:
# make sure the previous frame has been processed
if frame_index > 0:
while self.processed_frames[frame_index - 1] is None:
time.sleep(0.1)
# make the current image the same as the previous result
self.processed_frames[frame_index] = self.processed_frames[
frame_index - 1
]
# if the difference is greater than threshold
# process this frame
else:
width, height = image1.size width, height = image1.size
# calculate required minimum scale ratio # calculate required minimum scale ratio
@ -149,20 +162,6 @@ class Upscaler(multiprocessing.Process):
image1 = image1.resize((output_width, output_height), Image.LANCZOS) image1 = image1.resize((output_width, output_height), Image.LANCZOS)
self.processed_frames[frame_index] = image1 self.processed_frames[frame_index] = image1
# if the difference is greater than threshold
# there's a change in camera angle, ignore
else:
# make sure the previous frame has been processed
if frame_index > 0:
while self.processed_frames[frame_index - 1] is None:
time.sleep(0.1)
# make the current image the same as the previous result
self.processed_frames[frame_index] = self.processed_frames[
frame_index - 1
]
# send exceptions into the client connection pipe # send exceptions into the client connection pipe
except (SystemExit, KeyboardInterrupt): except (SystemExit, KeyboardInterrupt):
break break

View File

@ -378,7 +378,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, two images are deemed the same; 0 is off", help="skip if the % difference between two adjacent frames is below this value; set to 0 to process all frames",
default=0, default=0,
) )
@ -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; 0 is off", help="skip if the % difference between two adjacent frames exceeds this value; set to 100 to interpolate all frames",
default=10, default=10,
) )