Merge branch 'yoshiko2:master' into master
This commit is contained in:
@@ -1,14 +1,19 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import config
|
import config
|
||||||
import importlib
|
import importlib
|
||||||
|
from PIL import Image
|
||||||
|
import shutil
|
||||||
|
|
||||||
def face_crop(filename, width, height):
|
|
||||||
|
def face_crop_width(filename, width, height):
|
||||||
# 新宽度是高度的2/3
|
# 新宽度是高度的2/3
|
||||||
cropWidthHalf = int(height/3)
|
cropWidthHalf = int(height/3)
|
||||||
try:
|
try:
|
||||||
locations_model = filter(lambda x: x, config.getInstance().face_locations_model().lower().split(','))
|
locations_model = config.getInstance().face_locations_model().lower().split(',')
|
||||||
|
locations_model = filter(lambda x: x, locations_model)
|
||||||
for model in locations_model:
|
for model in locations_model:
|
||||||
center = face_center(filename, model)
|
center, top = face_center(filename, model)
|
||||||
# 如果找到就跳出循环
|
# 如果找到就跳出循环
|
||||||
if center:
|
if center:
|
||||||
cropLeft = center-cropWidthHalf
|
cropLeft = center-cropWidthHalf
|
||||||
@@ -27,12 +32,63 @@ def face_crop(filename, width, height):
|
|||||||
return (width-cropWidthHalf*2, 0, width, height)
|
return (width-cropWidthHalf*2, 0, width, height)
|
||||||
|
|
||||||
|
|
||||||
|
def face_crop_height(filename, width, height):
|
||||||
|
cropHeight = int(width*3/2)
|
||||||
|
try:
|
||||||
|
locations_model = config.getInstance().face_locations_model().lower().split(',')
|
||||||
|
locations_model = filter(lambda x: x, locations_model)
|
||||||
|
for model in locations_model:
|
||||||
|
center, top = face_center(filename, model)
|
||||||
|
# 如果找到就跳出循环
|
||||||
|
if top:
|
||||||
|
# 头部靠上
|
||||||
|
cropTop = top
|
||||||
|
cropBottom = cropHeight + top
|
||||||
|
if cropBottom > height:
|
||||||
|
cropTop = 0
|
||||||
|
cropBottom = cropHeight
|
||||||
|
return (0, cropTop, width, cropBottom)
|
||||||
|
except:
|
||||||
|
print('[-]Not found face! ' + filename)
|
||||||
|
# 默认从顶部向下切割
|
||||||
|
return (0, 0, width, cropHeight)
|
||||||
|
|
||||||
|
|
||||||
|
def cutImage(imagecut, path, fanart_path, poster_path):
|
||||||
|
fullpath_fanart = os.path.join(path, fanart_path)
|
||||||
|
fullpath_poster = os.path.join(path, poster_path)
|
||||||
|
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))
|
||||||
|
elif width/height < 2/3: # 如果高度大于3
|
||||||
|
# 从底部向上切割
|
||||||
|
img2 = img.crop(face_crop_height(fullpath_fanart, width, height))
|
||||||
|
else: # 如果等于2/3
|
||||||
|
img2 = img
|
||||||
|
img2.save(fullpath_poster)
|
||||||
|
print('[+]Image Cutted! ' + fullpath_poster)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
print('[-]Cover cut failed!')
|
||||||
|
elif imagecut == 0: # 复制封面
|
||||||
|
shutil.copyfile(fullpath_fanart, fullpath_poster)
|
||||||
|
print('[+]Image Copyed! ' + fullpath_poster)
|
||||||
|
|
||||||
|
|
||||||
def face_center(filename, model):
|
def face_center(filename, model):
|
||||||
print('[+]Use model ' + model)
|
print('[+]Use model ' + model)
|
||||||
try:
|
try:
|
||||||
mod = importlib.import_module('.' + model,'ImageProcessing')
|
mod = importlib.import_module('.' + model, 'ImageProcessing')
|
||||||
return mod.face_center(filename, model)
|
return mod.face_center(filename, model)
|
||||||
except BaseException as e:
|
except Exception as e:
|
||||||
print('[-]Model found face ' + filename)
|
print('[-]Model found face ' + filename)
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
return 0
|
return (0, 0)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
cutImage(1,'H:\\test\\','12.jpg','test.jpg')
|
||||||
|
|
||||||
@@ -11,12 +11,15 @@ def face_center(filename, model):
|
|||||||
img = fp.read()
|
img = fp.read()
|
||||||
result = client.bodyAnalysis(img)
|
result = client.bodyAnalysis(img)
|
||||||
if 'error_code' in result:
|
if 'error_code' in result:
|
||||||
raise result['error_msg']
|
raise ValueError(result['error_msg'])
|
||||||
print('[+]Found person ' + str(result['person_num']))
|
print('[+]Found person ' + str(result['person_num']))
|
||||||
# 中心点取鼻子x坐标
|
# 中心点取鼻子x坐标
|
||||||
max = 0
|
maxRight = 0
|
||||||
|
maxTop = 0
|
||||||
for person_info in result["person_info"]:
|
for person_info in result["person_info"]:
|
||||||
x = int(person_info['body_parts']['nose']['x'])
|
x = int(person_info['body_parts']['nose']['x'])
|
||||||
if x > max:
|
top = int(person_info['location']['top'])
|
||||||
max = x
|
if x > maxRight:
|
||||||
return max
|
maxRight = x
|
||||||
|
maxTop = top
|
||||||
|
return maxRight,maxTop
|
||||||
|
|||||||
@@ -5,11 +5,13 @@ def face_center(filename, model):
|
|||||||
image = face_recognition.load_image_file(filename)
|
image = face_recognition.load_image_file(filename)
|
||||||
face_locations = face_recognition.face_locations(image, 1, model)
|
face_locations = face_recognition.face_locations(image, 1, model)
|
||||||
print('[+]Found person ' + str(len(face_locations)))
|
print('[+]Found person ' + str(len(face_locations)))
|
||||||
max = 0
|
maxRight = 0
|
||||||
|
maxTop = 0
|
||||||
for face_location in face_locations:
|
for face_location in face_locations:
|
||||||
top, right, bottom, left = face_location
|
top, right, bottom, left = face_location
|
||||||
# 中心点
|
# 中心点
|
||||||
x = int((right+left)/2)
|
x = int((right+left)/2)
|
||||||
if x > max:
|
if x > maxRight:
|
||||||
max = x
|
maxRight = x
|
||||||
return max
|
maxTop = top
|
||||||
|
return maxRight,maxTop
|
||||||
|
|||||||
@@ -446,7 +446,7 @@ def create_data_and_move_with_custom_number(file_path: str, custom_number, oCC):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
version = '6.0.1'
|
version = '6.0.2'
|
||||||
urllib3.disable_warnings() #Ignore http proxy warning
|
urllib3.disable_warnings() #Ignore http proxy warning
|
||||||
|
|
||||||
# Read config.ini first, in argparse_function() need conf.failed_folder()
|
# Read config.ini first, in argparse_function() need conf.failed_folder()
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import logging
|
|
||||||
import sys
|
import sys
|
||||||
sys.path.append('../')
|
sys.path.append('../')
|
||||||
import re
|
import re
|
||||||
|
|||||||
27
core.py
27
core.py
@@ -14,7 +14,7 @@ from datetime import datetime
|
|||||||
from ADC_function import *
|
from ADC_function import *
|
||||||
from WebCrawler import get_data_from_json
|
from WebCrawler import get_data_from_json
|
||||||
from number_parser import is_uncensored
|
from number_parser import is_uncensored
|
||||||
from ImageProcessing import face_crop
|
from ImageProcessing import cutImage
|
||||||
|
|
||||||
|
|
||||||
def escape_path(path, escape_literals: str): # Remove escape literals
|
def escape_path(path, escape_literals: str): # Remove escape literals
|
||||||
@@ -371,31 +371,6 @@ def print_files(path, leak_word, c_word, naming_rule, part, cn_sub, json_data, f
|
|||||||
moveFailedFolder(filepath)
|
moveFailedFolder(filepath)
|
||||||
return
|
return
|
||||||
|
|
||||||
def cutImage(imagecut, path, fanart_path, poster_path):
|
|
||||||
fullpath_fanart = os.path.join(path, fanart_path)
|
|
||||||
fullpath_poster = os.path.join(path, poster_path)
|
|
||||||
if imagecut == 1: # 剪裁大封面
|
|
||||||
try:
|
|
||||||
img = Image.open(fullpath_fanart)
|
|
||||||
width, height = img.size
|
|
||||||
if width/height > 2/3: # 如果宽度大于2
|
|
||||||
# 以人像为中心切取
|
|
||||||
img2 = img.crop(face_crop(fullpath_fanart, width, height))
|
|
||||||
elif width/height < 2/3: # 如果高度大于3
|
|
||||||
# 从底部向上切割
|
|
||||||
cropBottom = width*3/2
|
|
||||||
img2 = img.crop(0, 0, width, cropBottom)
|
|
||||||
else: # 如果等于2/3
|
|
||||||
img2 = img
|
|
||||||
img2.save(fullpath_poster)
|
|
||||||
print('[+]Image Cutted! ' + fullpath_poster)
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
print('[-]Cover cut failed!')
|
|
||||||
elif imagecut == 0: # 复制封面
|
|
||||||
shutil.copyfile(fullpath_fanart, fullpath_poster)
|
|
||||||
print('[+]Image Copyed! ' + fullpath_poster)
|
|
||||||
|
|
||||||
# 此函数从gui版copy过来用用
|
# 此函数从gui版copy过来用用
|
||||||
# 参数说明
|
# 参数说明
|
||||||
# poster_path
|
# poster_path
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import sys
|
|||||||
import config
|
import config
|
||||||
|
|
||||||
G_spat = re.compile(
|
G_spat = re.compile(
|
||||||
"^22-sht\.me|-fhd|_fhd|^fhd_|^fhd-|-hd|_hd|^hd_|^hd-|-sd|_sd|-1080p|_1080p|-720p|_720p|^hhd800\.com@|-uncensored|_uncensored|-leak|_leak",
|
"^22-sht\.me|-fhd|_fhd|^fhd_|^fhd-|-hd|_hd|^hd_|^hd-|-sd|_sd|-1080p|_1080p|-720p|_720p|"
|
||||||
|
"^hhd800\.com@|-uncensored|_uncensored|-leak|_leak|-4K|_4K",
|
||||||
re.IGNORECASE)
|
re.IGNORECASE)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user