diff --git a/ImageProcessing/__init__.py b/ImageProcessing/__init__.py new file mode 100644 index 0000000..0f519af --- /dev/null +++ b/ImageProcessing/__init__.py @@ -0,0 +1,38 @@ +import logging +import config +import importlib + +def face_crop(filename, width, height): + # 新宽度是高度的2/3 + cropWidthHalf = int(height/3) + try: + locations_model = filter(lambda x: x, config.getInstance().face_locations_model().lower().split(',')) + for model in locations_model: + center = face_center(filename, model) + # 如果找到就跳出循环 + if center: + cropLeft = center-cropWidthHalf + cropRight = center+cropWidthHalf + # 越界处理 + if cropLeft < 0: + cropLeft = 0 + cropRight = cropWidthHalf*2 + elif cropRight > width: + cropLeft = width-cropWidthHalf*2 + cropRight = width + return (cropLeft, 0, cropRight, height) + except: + print('[-]Not found face! ' + filename) + # 默认靠右切 + return (width-cropWidthHalf*2, 0, width, height) + + +def face_center(filename, model): + print('[+]Use model ' + model) + try: + mod = importlib.import_module('.' + model,'ImageProcessing') + return mod.face_center(filename, model) + except BaseException as e: + print('[-]Model found face ' + filename) + logging.error(e) + return 0 \ No newline at end of file diff --git a/ImageProcessing/baidu.py b/ImageProcessing/baidu.py new file mode 100644 index 0000000..7bbe3ae --- /dev/null +++ b/ImageProcessing/baidu.py @@ -0,0 +1,22 @@ +from aip import AipBodyAnalysis +import config + + +def face_center(filename, model): + app_id = config.getInstance().conf.get("face", "appid") + api_key = config.getInstance().conf.get("face", "key") + app_secret = config.getInstance().conf.get("face", "secret") + client = AipBodyAnalysis(app_id, api_key, app_secret) + with open(filename, 'rb') as fp: + img = fp.read() + result = client.bodyAnalysis(img) + if 'error_code' in result: + raise result['error_msg'] + print('[+]Found person ' + str(result['person_num'])) + # 中心点取鼻子x坐标 + max = 0 + for person_info in result["person_info"]: + x = int(person_info['body_parts']['nose']['x']) + if x > max: + max = x + return max diff --git a/ImageProcessing/cnn.py b/ImageProcessing/cnn.py new file mode 100644 index 0000000..4219c5d --- /dev/null +++ b/ImageProcessing/cnn.py @@ -0,0 +1,4 @@ +import hog + +def face_center(filename, model): + return hog.face_center(filename, model) \ No newline at end of file diff --git a/ImageProcessing/hog.py b/ImageProcessing/hog.py new file mode 100644 index 0000000..6f0bbb3 --- /dev/null +++ b/ImageProcessing/hog.py @@ -0,0 +1,15 @@ +import face_recognition + + +def face_center(filename, model): + image = face_recognition.load_image_file(filename) + face_locations = face_recognition.face_locations(image, 1, model) + print('[+]Found person ' + str(len(face_locations))) + max = 0 + for face_location in face_locations: + top, right, bottom, left = face_location + # 中心点 + x = int((right+left)/2) + if x > max: + max = x + return max diff --git a/WebCrawler/__init__.py b/WebCrawler/__init__.py index c661700..f690e0c 100644 --- a/WebCrawler/__init__.py +++ b/WebCrawler/__init__.py @@ -22,6 +22,8 @@ from . import xcity from . import dlsite from . import carib from . import fc2club +from . import mv91 +from . import madou def get_data_state(data: dict) -> bool: # 元数据获取失败检测 @@ -57,7 +59,9 @@ def get_data_from_json(file_number, oCC): # 从JSON返回元数据 # "javlib": javlib.main, "dlsite": dlsite.main, "carib": carib.main, - "fc2club": fc2club.main + "fc2club": fc2club.main, + "mv91": mv91.main, + "madou": madou.main } conf = config.getInstance() diff --git a/WebCrawler/javdb.py b/WebCrawler/javdb.py index 8a5de7a..e46cd7f 100755 --- a/WebCrawler/javdb.py +++ b/WebCrawler/javdb.py @@ -1,3 +1,4 @@ +import logging import sys sys.path.append('../') import re @@ -139,7 +140,8 @@ def getCover_small(html, index=0): def getTrailer(htmlcode): # 获取预告片 video_pather = re.compile(r'