-
Notifications
You must be signed in to change notification settings - Fork 0
/
firstflask.py
59 lines (32 loc) · 1.66 KB
/
firstflask.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from flask import Flask, request
import requests
import cv2
app = Flask(__name__)
@app.route('/crop-avatar', methods=['POST'])
def crop_avatar():
if request.headers['Service-Token'] == "service_token_ava":
response = requests.get(request.form['passport_url']) # Скачивание фото пасспорта из URL
file = open("image"+ request.form['user_id'] +".png", "wb") # Cохранение в файле image.png
file.write(response.content)
file.close()
#Вырезание лица из фото
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') #
img = cv2.imread("image"+ request.form['user_id'] +".png")
while True:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.1, 5)
for (x, y, w, h) in faces:
padding = 40
crop_face = img[y - padding: y + h + padding, x - padding: x + w + padding]
cv2.imwrite('upload'+ request.form['user_id'] + '.jpg', crop_face)
if cv2.error:
break
cv2.destroyAllWindows()
#Пост на данный урл с указанным id юзера
url= 'https://services.test.aliftech.uz/api/gate/users/' + request.form["user_id"] + '/upload-avatar'
headers = {'Service-Token': 'service-token-merchant'}
files = {'image': open('upload'+ request.form['user_id'] + '.jpg', 'rb')}
requests.post(url, headers=headers, files=files)
return request.form
if __name__ == '__main__':
app.run(host='localhost',port=8080, debug=True)