forked from SharpAI/DeepCamera
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_facesdata.py
More file actions
54 lines (48 loc) · 2.06 KB
/
Copy pathsync_facesdata.py
File metadata and controls
54 lines (48 loc) · 2.06 KB
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
# -*- coding: UTF-8 -*-
import os,sys
BASEDIR = os.path.join(os.getenv('RUNTIME_BASEDIR',os.path.abspath(os.path.join(os.path.dirname(__file__),'../'))))
sys.path.append(BASEDIR)
from faces.save_embedding import download_img_for_svm_sync, get_image_path_sync
from getDeviceInfo import get_current_groupid
from urllib2 import urlopen, URLError, HTTPError
import json
SVM_TRAIN_WITHOUT_CATEGORY=True
if __name__ == '__main__':
group_id = get_current_groupid()
#host="http://localhost:3000/restapi/datasync/token/" + str(group_id)
API_SERVER_ADDRESS = os.getenv('API_SERVER_ADDRESS','workaihost.tiegushi.com')
API_SERVER_PORT = os.getenv('API_SERVER_PORT','80')
host = 'http://'+API_SERVER_ADDRESS+':'+API_SERVER_PORT+'/restapi/datasync/token/' + str(group_id)
result = None
try:
response = urlopen(host, timeout=10)
except HTTPError as e:
print('HTTPError: ', e.code)
except URLError as e:
print('URLError: ', e.reason)
except Exception as e:
print('Error: ', e)
else:
# everything is fine
if 200 == response.getcode():
result = response.readline()
#print(result)
result = json.loads(result)
for person in result:
faceId = person.get("faceId")
urls = person.get("urls")
print('--> {}'.format(faceId))
for url in urls:
print(' {}'.format(url))
# url,faceid 从点圈群相册获取
# todo 可以用for循环解析群相册获取的json数据
img_url = url['url']
face_id = faceId
style = url['style']
if SVM_TRAIN_WITHOUT_CATEGORY is True:
style = 'front'
img_path = get_image_path_sync(img_url, group_id, face_id, style)
if not os.path.exists(img_path):
download_img_for_svm_sync(img_url, group_id, face_id, style)
else:
print('response code != 200')