From 8add9fe42454a94091942404063bd8cc5436f55a Mon Sep 17 00:00:00 2001 From: lededev Date: Sun, 10 Apr 2022 13:38:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=81=E5=89=AA=E5=B0=81=E9=9D=A2=E5=AE=BD?= =?UTF-8?q?=E9=AB=98=E6=AF=94=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ImageProcessing/__init__.py | 16 +++++++++------- Movie_Data_Capture.py | 7 ++++--- config.ini | 2 ++ config.py | 3 +++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ImageProcessing/__init__.py b/ImageProcessing/__init__.py index 539623e..e582e55 100644 --- a/ImageProcessing/__init__.py +++ b/ImageProcessing/__init__.py @@ -7,9 +7,9 @@ from PIL import Image import shutil from ADC_function import file_not_exist_or_empty -g_width_half_ratio = 2.12 def face_crop_width(filename, width, height): + aspect_ratio = config.getInstance().face_aspect_ratio() # 新宽度是高度的2/3 cropWidthHalf = int(height/3) try: @@ -24,15 +24,15 @@ def face_crop_width(filename, width, height): # 越界处理 if cropLeft < 0: cropLeft = 0 - cropRight = cropWidthHalf*g_width_half_ratio + cropRight = cropWidthHalf * aspect_ratio elif cropRight > width: - cropLeft = width-cropWidthHalf*g_width_half_ratio + cropLeft = width - cropWidthHalf * aspect_ratio cropRight = width return (cropLeft, 0, cropRight, height) except: print('[-]Not found face! ' + filename) # 默认靠右切 - return (width-cropWidthHalf * g_width_half_ratio, 0, width, height) + return (width-cropWidthHalf * aspect_ratio, 0, width, height) def face_crop_height(filename, width, height): @@ -58,11 +58,13 @@ def face_crop_height(filename, width, height): def cutImage(imagecut, path, fanart_path, poster_path, skip_facerec=False): + conf = config.getInstance() fullpath_fanart = os.path.join(path, fanart_path) fullpath_poster = os.path.join(path, poster_path) - if config.getInstance().face_aways_imagecut(): + aspect_ratio = conf.face_aspect_ratio() + if conf.face_aways_imagecut(): imagecut = 1 - elif config.getInstance().download_only_missing_images() and not file_not_exist_or_empty(fullpath_poster): + elif conf.download_only_missing_images() and not file_not_exist_or_empty(fullpath_poster): return if imagecut == 1: # 剪裁大封面 try: @@ -71,7 +73,7 @@ def cutImage(imagecut, path, fanart_path, poster_path, skip_facerec=False): if width/height > 2/3: # 如果宽度大于2 if skip_facerec: # 有码封面默认靠右切 - img2 = img.crop((width - int(height/3) * g_width_half_ratio, 0, width, height)) + img2 = img.crop((width - int(height/3) * aspect_ratio, 0, width, height)) else: # 以人像为中心切取 img2 = img.crop(face_crop_width(fullpath_fanart, width, height)) diff --git a/Movie_Data_Capture.py b/Movie_Data_Capture.py index a191ee2..2c8a5a2 100644 --- a/Movie_Data_Capture.py +++ b/Movie_Data_Capture.py @@ -101,9 +101,10 @@ is performed. It may help you correct wrong numbers before real job.""") no_net_op = False if conf.main_mode() == 3: no_net_op = args.no_network_operation - config.G_conf_override["common:stop_counter"] = 0 - config.G_conf_override["common:rerun_delay"] = '0s' - config.G_conf_override["face:aways_imagecut"] = True + if no_net_op: + config.G_conf_override["common:stop_counter"] = 0 + config.G_conf_override["common:rerun_delay"] = '0s' + config.G_conf_override["face:aways_imagecut"] = True return args.file, args.number, args.logdir, args.regexstr, args.zero_op, no_net_op diff --git a/config.ini b/config.ini index 6e40cc4..d46b1ac 100755 --- a/config.ini +++ b/config.ini @@ -122,7 +122,9 @@ sites=38,39 ; 人脸识别 locations_model=hog:方向梯度直方图(不太准确,速度快) cnn:深度学习模型(准确,需要GPU/CUDA,速度慢) ; uncensored_only=0:对全部封面进行人脸识别 1:只识别无码封面,有码封面直接切右半部分 ; aways_imagecut=0:按各网站默认行为 1:总是裁剪封面,开启此项将无视[common]download_only_missing_images=1总是覆盖封面 +; 封面裁剪的宽高比可配置,公式为aspect_ratio/3。默认aspect_ratio=2.12: 适配大部分有码影片封面,前一版本默认为2/3即aspect_ratio=2 [face] locations_model=hog uncensored_only=1 aways_imagecut=0 +aspect_ratio=2.12 diff --git a/config.py b/config.py index e5bb1bf..4dc0a9f 100644 --- a/config.py +++ b/config.py @@ -365,6 +365,9 @@ class Config: def face_aways_imagecut(self) -> bool: return self.getboolean_override("face", "aways_imagecut", fallback=False) + def face_aspect_ratio(self) -> float: + return self.conf.getfloat("face", "aspect_ratio", fallback=2.12) + @staticmethod def _exit(sec: str) -> None: print("[-] Read config error! Please check the {} section in config.ini", sec)