Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

去除头像影响,只识别视频中的脸部;只保存符合要求的脸部图片(漂亮妹子) #105

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion common/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down
12 changes: 9 additions & 3 deletions common/screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 21 additions & 8 deletions douyin-bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import time
from PIL import Image
import argparse
import ssl
ssl._create_default_https_context = ssl._create_unverified_context



if sys.version_info.major != 3:
print('Please run under Python3')
Expand All @@ -23,8 +27,8 @@

# 我申请的 Key,随便用,嘻嘻嘻
# 申请地址 http://ai.qq.com
AppID = '1106858595'
AppKey = 'bNUNgOpY6AeeJjFu'
AppID = 'xxx'
AppKey = 'xxx'

DEBUG_SWITCH = True
FACE_PATH = 'face/'
Expand Down Expand Up @@ -151,6 +155,8 @@ def main():
main
:return:
"""
global img
global imgOrg
print('程序版本号:{}'.format(VERSION))
print('激活窗口并按 CONTROL + C 组合键退出')
debug.dump_device_info()
Expand All @@ -162,9 +168,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()
Expand All @@ -188,8 +199,7 @@ def main():
print(msg_log)
face_area = (face['x'], face['y'], face['x']+face['width'], face['y']+face['height'])
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']
Expand All @@ -201,9 +211,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()

if cmd_args['reply']:
auto_reply()
Expand Down
2 changes: 1 addition & 1 deletion example/test_crop.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion example/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()