From 09c81d7f5975eea75b7dfe89596dfa9610c6e318 Mon Sep 17 00:00:00 2001 From: lededev Date: Sun, 10 Apr 2022 07:14:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=80=89=E9=A1=B9:1.?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E6=A8=A1=E5=BC=8F3=E8=B7=B3=E8=BF=87?= =?UTF-8?q?=E4=BA=BA=E8=84=B8=E8=AF=86=E5=88=AB=202.=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E5=AF=B9=E6=9C=89=E7=A0=81=E5=B0=81=E9=9D=A2=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E4=BA=BA=E8=84=B8=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ImageProcessing/__init__.py | 14 ++++++++++---- config.ini | 6 +++++- config.py | 22 ++++++++++------------ core.py | 4 ++-- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/ImageProcessing/__init__.py b/ImageProcessing/__init__.py index dafbb55..f0b7fe5 100644 --- a/ImageProcessing/__init__.py +++ b/ImageProcessing/__init__.py @@ -55,18 +55,24 @@ def face_crop_height(filename, width, height): return (0, 0, width, cropHeight) -def cutImage(imagecut, path, fanart_path, poster_path): +def cutImage(imagecut, path, fanart_path, poster_path, skip_facerec=False): fullpath_fanart = os.path.join(path, fanart_path) fullpath_poster = os.path.join(path, poster_path) - if config.getInstance().download_only_missing_images() and not file_not_exist_or_empty(fullpath_poster): + if config.getInstance().face_aways_imagecut(): + imagecut = 1 + elif config.getInstance().download_only_missing_images() and not file_not_exist_or_empty(fullpath_poster): return if imagecut == 1: # 剪裁大封面 try: img = Image.open(fullpath_fanart) width, height = img.size if width/height > 2/3: # 如果宽度大于2 - # 以人像为中心切取 - img2 = img.crop(face_crop_width(fullpath_fanart, width, height)) + if skip_facerec: + # 有码封面默认靠右切 + img2 = img.crop((width - int(height/3) * 2, 0, width, height)) + else: + # 以人像为中心切取 + img2 = img.crop(face_crop_width(fullpath_fanart, width, height)) elif width/height < 2/3: # 如果高度大于3 # 从底部向上切割 img2 = img.crop(face_crop_height(fullpath_fanart, width, height)) diff --git a/config.ini b/config.ini index 25a19c8..6e40cc4 100755 --- a/config.ini +++ b/config.ini @@ -119,6 +119,10 @@ vars=outline,series,studio,tag,title [javdb] sites=38,39 -; 人脸识别 hog:方向梯度直方图(不太准确,速度快) cnn:深度学习模型(准确,需要GPU/CUDA,速度慢) +; 人脸识别 locations_model=hog:方向梯度直方图(不太准确,速度快) cnn:深度学习模型(准确,需要GPU/CUDA,速度慢) +; uncensored_only=0:对全部封面进行人脸识别 1:只识别无码封面,有码封面直接切右半部分 +; aways_imagecut=0:按各网站默认行为 1:总是裁剪封面,开启此项将无视[common]download_only_missing_images=1总是覆盖封面 [face] locations_model=hog +uncensored_only=1 +aways_imagecut=0 diff --git a/config.py b/config.py index 7dfc702..586ee8f 100644 --- a/config.py +++ b/config.py @@ -346,22 +346,20 @@ class Config: return 1 def cc_convert_vars(self) -> str: - try: - return self.conf.get("cc_convert", "vars") - except: - return "actor,director,label,outline,series,studio,tag,title" + return self.conf.get("cc_convert", "vars", + fallback="actor,director,label,outline,series,studio,tag,title") def javdb_sites(self) -> str: - try: - return self.conf.get("javdb", "sites") - except: - return "33,34" + return self.conf.get("javdb", "sites", fallback="38,39") def face_locations_model(self) -> str: - try: - return self.conf.get("face", "locations_model") - except: - return "hog" + return self.conf.get("face", "locations_model", fallback="hog") + + def face_uncensored_only(self) -> bool: + return self.conf.getboolean("face", "uncensored_only", fallback=True) + + def face_aways_imagecut(self) -> bool: + return self.conf.getboolean("face", "aways_imagecut", fallback=False) @staticmethod def _exit(sec: str) -> None: diff --git a/core.py b/core.py index fff055d..f8ef23c 100644 --- a/core.py +++ b/core.py @@ -717,7 +717,7 @@ def core_main(file_path, number_th, oCC): # 裁剪图 - cutImage(imagecut, path, fanart_path, poster_path) + cutImage(imagecut, path, fanart_path, poster_path, bool(conf.face_uncensored_only() and not uncensored)) # 添加水印 if conf.is_watermark(): @@ -760,7 +760,7 @@ def core_main(file_path, number_th, oCC): extrafanart_download(json_data.get('extrafanart'), path, number, filepath) # 裁剪图 - cutImage(imagecut, path, fanart_path, poster_path) + cutImage(imagecut, path, fanart_path, poster_path, bool(conf.face_uncensored_only() and not uncensored)) # 添加水印 if conf.is_watermark():