代码拉取完成,页面将自动刷新
#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
@time: 2017/3/24 16:04
@author: Silence
'''
import os
from flask import Flask, request,send_file,render_template,url_for,jsonify
from flask_uploads import UploadSet, configure_uploads, IMAGES,\
patch_request_class
import tool_output_landmarks_image
import time
app = Flask(__name__)
# app.config['UPLOADED_PHOTOS_DEST'] = os.path.join(os.getcwd(),'static','uploads') # 文件储存地址
# app.config['UPLOADED_PHOTOS_DEST'] = 'C:\Users\Silance\PycharmProjects\markFace\static\images\uploads' # 文件储存地址
app.config['UPLOADED_PHOTOS_DEST'] = os.path.join('static','images','uploads') # 文件储存地址
photos = UploadSet('photos', IMAGES)
configure_uploads(app, photos)
patch_request_class(app) # 文件大小限制,默认为16MB
@app.route('/', methods=['GET'])
def index():
return render_template('face.html')
@app.route('/markapi', methods=['POST'])
def upload_file():
if 'photo' in request.files:
filename = photos.save(request.files['photo'])
a,b = filename.split('.')
newFileName = a+'.jpg'
# print filename
file_url = photos.url(filename)
infile_path = os.path.join(os.getcwd(),'static','images','uploads',filename)
outfile_path = os.path.join(os.getcwd(),'static','images','markface',newFileName)
tool_output_landmarks_image.main(infile_path,outfile_path)
# return send_file('static/uploads/'+filename,mimetype='image/jpeg')
# return send_file(os.path.join('static','images','markface',filename),mimetype='image/jpeg')
url = url_for('static', filename='images/markface/%s' % newFileName)
if url:
data = {
'markImage': 'http://117.114.138.52:10302%s' % url,
'resultMessage': '200'
}
return jsonify(data)
else:
data = {
'resultMessage': '500'
}
return jsonify(data)
else:
return u'参数错误'
if __name__ == '__main__':
app.run()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。