mirror of
				https://github.com/k4yt3x/video2x.git
				synced 2025-10-31 04:40:59 +01:00 
			
		
		
		
	fixed upscaler diff threshold bug
This commit is contained in:
		
							parent
							
								
									7eabac2175
								
							
						
					
					
						commit
						ac80de9399
					
				| @ -104,16 +104,13 @@ class VideoDecoder(threading.Thread): | ||||
|                     "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( | ||||
|                         ( | ||||
|                             frame_index, | ||||
|                             (previous_image, image), | ||||
|                             self.processing_settings, | ||||
|                         ) | ||||
|                 self.processing_queue.put( | ||||
|                     ( | ||||
|                         frame_index, | ||||
|                         (previous_image, image), | ||||
|                         self.processing_settings, | ||||
|                     ) | ||||
|                 ) | ||||
|                 previous_image = image | ||||
| 
 | ||||
|                 frame_index += 1 | ||||
|  | ||||
| @ -56,6 +56,11 @@ class Interpolator(multiprocessing.Process): | ||||
|                     time.sleep(0.1) | ||||
|                     continue | ||||
| 
 | ||||
|                 # if image0 is None, image1 is the first frame | ||||
|                 # skip this round | ||||
|                 if image0 is None: | ||||
|                     continue | ||||
| 
 | ||||
|                 difference = ImageChops.difference(image0, image1) | ||||
|                 difference_stat = ImageStat.Stat(difference) | ||||
|                 difference_ratio = ( | ||||
|  | ||||
| @ -74,11 +74,15 @@ class Upscaler(multiprocessing.Process): | ||||
|                     time.sleep(0.1) | ||||
|                     continue | ||||
| 
 | ||||
|                 difference = ImageChops.difference(image0, image1) | ||||
|                 difference_stat = ImageStat.Stat(difference) | ||||
|                 difference_ratio = ( | ||||
|                     sum(difference_stat.mean) / (len(difference_stat.mean) * 255) * 100 | ||||
|                 ) | ||||
|                 difference_ratio = -1 | ||||
|                 if image0 is not None: | ||||
|                     difference = ImageChops.difference(image0, image1) | ||||
|                     difference_stat = ImageStat.Stat(difference) | ||||
|                     difference_ratio = ( | ||||
|                         sum(difference_stat.mean) | ||||
|                         / (len(difference_stat.mean) * 255) | ||||
|                         * 100 | ||||
|                     ) | ||||
| 
 | ||||
|                 # if the difference is lower than threshold | ||||
|                 # process the interpolation | ||||
| @ -150,8 +154,9 @@ class Upscaler(multiprocessing.Process): | ||||
|                 else: | ||||
| 
 | ||||
|                     # make sure the previous frame has been processed | ||||
|                     while self.processed_frames[frame_index - 1] is None: | ||||
|                         time.sleep(0.1) | ||||
|                     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[ | ||||
|  | ||||
| @ -378,8 +378,8 @@ def parse_arguments() -> argparse.Namespace: | ||||
|         "-t", | ||||
|         "--threshold", | ||||
|         type=float, | ||||
|         help="if the % difference between two adjacent frames exceeds this value, two images are deemed the same", | ||||
|         default=0.1, | ||||
|         help="if the % difference between two adjacent frames exceeds this value, two images are deemed the same; 0 is off", | ||||
|         default=0, | ||||
|     ) | ||||
| 
 | ||||
|     # interpolator arguments | ||||
| @ -400,7 +400,7 @@ def parse_arguments() -> argparse.Namespace: | ||||
|         "-t", | ||||
|         "--threshold", | ||||
|         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, | ||||
|     ) | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user