123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import time
- from flask import Flask, request
- import json
- import MTCNN_person
- app = Flask(__name__)
- @app.route('/')
- def hello_world():
- return 'Hello World!'
- import requests
- #图片链接
- headers ={
- 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
- }
- dir = 'C:\\Users\\yufen\\Pictures\\face\\'
- def do_download(url):
- url1 = url.split('?')[0]
- name = url1.split('/')[-1]
- r = requests.get(url, headers=headers)
- # 下载图片
- # 二进制数据需要用r.content 进行提取
- # 将图片放在‘图库’文件夹下,‘图库’是文件夹的名称,将图片放入该文件夹中,该文件夹与py文件在同一目录下
- f = open(dir + name, 'wb')
- f.write(r.content)
- f.close()
- return name
- @app.route('/download')
- def download():
- url = request.args.get('url')
- time1 = int(round(time.time() * 1000))
- print('info=%s' % url)
- do_download(url)
- time2 = int(round(time.time() * 1000))
- print('over %s from %s' % (time2 - time1, time1))
- return 'Hello World!'
- @app.route('/face')
- def face():
- info = request.args.get('url')
- time1 = int(round(time.time() * 1000))
- print('info=%s' % info)
- name = do_download(info)
- time2 = int(round(time.time() * 1000))
- faces = MTCNN_person.detector(dir + name)
- time3 = int(round(time.time() * 1000))
- print('over %s from %s' % (time3 - time1, time1))
- return json.dumps(faces)
- if __name__ == '__main__':
- app.run(port=5000)
- # do_download(url='https://img.bbztx.com/article/live150178/team217182/20230913192631_tmp_9fbaaecf98fd1a3e91a6571f744f4b34511300d6c5a5b358.jpg?x-oss-process=image/resize,h_1000,m_lfit')
- # MTCNN_person.detector('C:\\Users\\yufen\\Pictures\\face\\20230913192631_tmp_9fbaaecf98fd1a3e91a6571f744f4b34511300d6c5a5b358.jpg')
|