From 7494e5a6d12a39bf68d80ed1739e315d08b0bfa7 Mon Sep 17 00:00:00 2001 From: Andros1993 <1756238821@qq.com> Date: Thu, 7 May 2020 10:38:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=A4=B4=E5=83=8F=E5=BD=B1?= =?UTF-8?q?=E5=93=8D=EF=BC=8C=E5=8F=AA=E8=AF=86=E5=88=AB=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E8=84=B8=E9=83=A8=EF=BC=9B=E5=8F=AA=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E7=AC=A6=E5=90=88=E8=A6=81=E6=B1=82=E7=9A=84=E8=84=B8?= =?UTF-8?q?=E9=83=A8=E5=9B=BE=E7=89=87=EF=BC=88=E6=BC=82=E4=BA=AE=E5=A6=B9?= =?UTF-8?q?=E5=AD=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/compression.py | 4 ++-- common/debug.py | 2 +- common/screenshot.py | 12 +++++++++--- douyin-bot.py | 28 +++++++++++++++++++--------- example/test_crop.py | 2 +- example/test_plot.py | 2 +- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/common/compression.py b/common/compression.py index 3ff8c56..f20f3d5 100644 --- a/common/compression.py +++ b/common/compression.py @@ -17,10 +17,10 @@ def resize_image(origin_img, optimize_img, threshold): width, height = im.size if width >= height: - new_width = int(math.sqrt(threshold / 2)) + new_width = int(math.sqrt(threshold * 1.5)) new_height = int(new_width * height * 1.0 / width) else: - new_height = int(math.sqrt(threshold / 2)) + new_height = int(math.sqrt(threshold * 1.5)) new_width = int(new_height * width * 1.0 / height) resized_im = im.resize((new_width, new_height)) diff --git a/common/debug.py b/common/debug.py index b9ab0a5..55e6c6c 100644 --- a/common/debug.py +++ b/common/debug.py @@ -39,7 +39,7 @@ def backup_screenshot(ts): 为了方便失败的时候 debug """ make_debug_dir(screenshot_backup_dir) - shutil.copy('{}{}autojump.png'.format(os.getcwd(), path_split), + shutil.copy('{}{}cropped.png'.format(os.getcwd(), path_split), os.path.join(os.getcwd(), screenshot_backup_dir, str(ts) + '.png')) diff --git a/common/screenshot.py b/common/screenshot.py index 24db0b3..d755b7a 100644 --- a/common/screenshot.py +++ b/common/screenshot.py @@ -47,17 +47,23 @@ def check_screenshot(): 检查获取截图的方式 """ global SCREENSHOT_WAY - if os.path.isfile('autojump.png'): + if os.path.isfile('cropped.png'): try: - os.remove('autojump.png') + os.remove('cropped.png') except Exception: pass + else: + print("没有发现旧图片") if SCREENSHOT_WAY < 0: print('暂不支持当前设备') sys.exit() try: im = pull_screenshot() - im.load() + + cropped = im.crop((0, 0, 916, 1920)) # (left, upper, right, lower) + cropped.load() + cropped.save("./cropped.png") + cropped.close() im.close() print('采用方式 {} 获取截图'.format(SCREENSHOT_WAY)) except Exception: diff --git a/douyin-bot.py b/douyin-bot.py index d0f3f6a..bebc81a 100644 --- a/douyin-bot.py +++ b/douyin-bot.py @@ -3,7 +3,8 @@ import random import time from PIL import Image - +import ssl +ssl._create_default_https_context = ssl._create_unverified_context if sys.version_info.major != 3: print('Please run under Python3') @@ -23,8 +24,8 @@ # 我申请的 Key,随便用,嘻嘻嘻 # 申请地址 http://ai.qq.com -AppID = '1106858595' -AppKey = 'bNUNgOpY6AeeJjFu' +AppID = 'xxx' +AppKey = 'xxx' DEBUG_SWITCH = True FACE_PATH = 'face/' @@ -113,6 +114,8 @@ def main(): main :return: """ + global img + global imgOrg print('程序版本号:{}'.format(VERSION)) print('激活窗口并按 CONTROL + C 组合键退出') debug.dump_device_info() @@ -122,9 +125,14 @@ def main(): next_page() time.sleep(1) - screenshot.pull_screenshot() + im = screenshot.pull_screenshot() + cropped = im.crop((0, 0, 916, 1920)) # (left, upper, right, lower) + cropped.load() + cropped.save("./cropped.png") + cropped.close() + im.close() - resize_image('autojump.png', 'optimized.png', 1024*1024) + resize_image('cropped.png', 'optimized.png', 1024*1024) with open('optimized.png', 'rb') as bin_data: image_data = bin_data.read() @@ -142,8 +150,7 @@ def main(): face_area = (face['x'], face['y'], face['x']+face['width'], face['y']+face['height']) print(face_area) img = Image.open("optimized.png") - cropped_img = img.crop(face_area).convert('RGB') - cropped_img.save(FACE_PATH + face['face_id'] + '.png') + # imgOrg = Image.open("optimized.png") # 性别判断 if face['beauty'] > beauty and face['gender'] < 50: beauty = face['beauty'] @@ -155,9 +162,12 @@ def main(): # 是个美人儿~关注点赞走一波 if beauty > BEAUTY_THRESHOLD and major_total > minor_total: + cropped_img = img.crop(face_area).convert('RGB') + cropped_img.save(FACE_PATH + face['face_id'] + '.png') + # imgOrg.save(FACE_PATH + face['face_id'] + 'a.png') print('发现漂亮妹子!!!') - thumbs_up() - follow_user() + # thumbs_up() + # follow_user() else: print(rsp) diff --git a/example/test_crop.py b/example/test_crop.py index d21dfb5..e6c18fe 100644 --- a/example/test_crop.py +++ b/example/test_crop.py @@ -1,6 +1,6 @@ from PIL import Image -im = Image.open("../autojump.png") +im = Image.open("../cropped.png") w, h = im.size area = (0, 0, 50, 50) diff --git a/example/test_plot.py b/example/test_plot.py index 2daae2d..2411a68 100644 --- a/example/test_plot.py +++ b/example/test_plot.py @@ -9,7 +9,7 @@ # img = mpimg.imread('../screenshot/comment_comment.jpeg') # img = mpimg.imread('../screenshot/add_comment.jpeg') -img = mpimg.imread('../autojump.png') +img = mpimg.imread('../cropped.png') imgplot = plt.imshow(img) plt.show() \ No newline at end of file