From ea3e1870e7f5bc2597327e3cc175de39b02b3239 Mon Sep 17 00:00:00 2001 From: hejianjun Date: Fri, 4 Feb 2022 03:49:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E9=9D=A0=E5=8F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ImageProcessing/baidu.py | 22 ++++++++++++++++++++++ ImageProcessing/hog.py | 15 ++++++++++----- WebCrawler/madou.py | 26 +++++++++++++------------- 3 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 ImageProcessing/baidu.py 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/hog.py b/ImageProcessing/hog.py index 28f53fb..6f0bbb3 100644 --- a/ImageProcessing/hog.py +++ b/ImageProcessing/hog.py @@ -1,10 +1,15 @@ import face_recognition + def face_center(filename, model): image = face_recognition.load_image_file(filename) - face_locations = face_recognition.face_locations(image, 0, model) - if face_locations: - top, right, bottom, left = face_locations[0] + 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 # 中心点 - return int((right+left)/2) - return 0 \ No newline at end of file + x = int((right+left)/2) + if x > max: + max = x + return max diff --git a/WebCrawler/madou.py b/WebCrawler/madou.py index 669f6d9..01fc19c 100644 --- a/WebCrawler/madou.py +++ b/WebCrawler/madou.py @@ -51,14 +51,6 @@ def getRelease(html): # 获取出版日期 def getRuntime(html): # 获取播放时长 return '' - -def getActor(html): # 获取女优 - b = [] - for player in html.xpath('//div[@class="article-tags"]/a/text()'): - b.append(player) - return b - - def getUrl(html): return str(html.xpath('//a[@class="share-weixin"]/@data-url')[0]) @@ -98,11 +90,18 @@ def getTag(html): # 获取标签 def getExtrafanart(html): # 获取剧照 return '' +def cutTags(tags): + actors = [] + tags = [] + for tag in tags: + actors.append(tag) + return actors,tags + def main(number): try: try: - number = number.lower() + number = number.lower().strip() url = "https://madou.club/" + number + ".html" htmlcode = get_html(url) except: @@ -110,6 +109,8 @@ def main(number): html = etree.fromstring(htmlcode, etree.HTMLParser()) url = getUrl(html) + tags = getTag(html) + actor,tags = cutTags(tags); dic = { # 标题 'title': getTitle(html, number), @@ -124,7 +125,7 @@ def main(number): # 导演 'director': getDirector(html), # 演员 - 'actor': getActor(html), + 'actor': actor, # 发售日 'release': getRelease(html), # 番号 @@ -135,7 +136,7 @@ def main(number): 'extrafanart': getExtrafanart(html), 'imagecut': 1, # - 'tag': getTag(html), + 'tag': tags, # 'label': getSerise(html), # 作者图片 @@ -160,5 +161,4 @@ def main(number): if __name__ == '__main__': - print(main('MD-0147')) - print(main('MD0147')) + print(main('MD0094'))