def store_face(): # store face retData = {'code': 0} imgdata = request.form['img'].split(',', 1)[1] username = request.form['username'] imgdata = base64.urlsafe_b64decode(imgdata) filename = './imgs/' + str(uuid.uuid4()) + '.png' with open(filename, 'ab') as f: f.write(imgdata) if face_handler.add_face_index(username, filename): retData['data'] = {'succ': 1} else: retData['data'] = {'succ': 0} return str(retData)
def insert(): start = time.time() uploadfile = request.files.get('photo') # 获取上传的文件 uploadfile.save("upload.jpg", overwrite=True)# overwrite参数是指覆盖同名文件 path = os.getcwd() + '/upload.jpg' id = get_id() re = face_handler.add_face_index(id, path) if re: pass else: id = 0 result = { "id": id } return json.dumps(result)
def handle_request(data): arrData=demjson.decode(data) retData={'code':0} #查找 if arrData['cmd']=='search': retData['data'] = face_handler.query_face(arrData['pic']) #添加 if arrData['cmd']=='add_index': if face_handler.add_face_index(arrData['id'],arrData['pic']): retData['data']={'succ':1} else: retData['data']={'succ':0} #检测 if arrData['cmd']=='face_detect': retData['data']=face_handler.detect_face(arrData['pic']) retData['data']['boxes'] = retData['data']['boxes'].tolist() return face_comm.trans_string(retData)