def get(self): result = ReturnStruct() person_id = self.get_argument("person_id") jquery = '' try: jquery = str(self.get_argument('jsoncallback')) except Exception as e: pass track_info = self.person_model.get_track_list(person_id) result.data = track_info self.return_to_client(result, jquery) self.finish()
def post(self): message_mapping = [ 'success in oss', 'success in resource server', 'failed , not exist' ] result = ReturnStruct(message_mapping) key = self.get_argument('key') exist = self._picture_model.check_exist(key) if exist: url = self._picture_model.get_url(key) result.data = {'url': url} else: file_dir = self.temp_file_dir + str(key) if os.path.exists(file_dir): result.code = 1 url = 'http://' + self.application.host + ':' + self.application.port + self.application.prefix + '/project/redirect?key=' + str( key) result.data = {'url': url} else: result.code = 2 self.return_to_client(result) self.finish()
def get(self): """ { "info": [ { "lat": 118.88, "count": 34, "lng": 31.875 }, { "lat": 118.8, "count": 35, "lng": 31.895 }, { "lat": 118.82, "count": 49, "lng": 31.89 } ], "amount": 10 } """ result = ReturnStruct() range_longitude = float(self.get_argument("range_longitude")) range_latitude = float(self.get_argument("range_latitude")) spot = eval(self.get_argument("spot")) jquery = '' try: jquery = str(self.get_argument('jsoncallback')) except Exception as e: pass track_map = self.person_model.get_track_count_by_range( spot, range_longitude, range_latitude) track_info = [] for latitude, value in track_map.items(): for longitude, count in value.items(): track_info.append({ 'lng': longitude, 'lat': latitude, 'count': count }) result.data = {'info': track_info, 'amount': len(track_info)} self.return_to_client(result, jquery) self.finish()
def post(self): logging.info("in post upload") """ user_id: pro_id: file: """ message_mapping = ['success', 'failed'] result = ReturnStruct(message_mapping) for field_name, files in self.request.files.items(): for meta in files: filename, content_type = meta['filename'], meta['content_type'] body = meta['body'] logging.info('POST "%s" "%s" %d m', filename, content_type, len(body) / 1024.0 / 1024.0) user_id = self.get_argument('user_id') pro_id = self.get_argument('pro_id') logging.info("get user id %s" % user_id) # file = self.get_argument('file') # name = self.get_argument('filename') # try: # binary_picture = base64.b64decode(body) # del file # except TypeError as e: # raise ArgumentTypeError('upload project picture') logging.info("in uploading resource...") key = self._gen_key(user_id, pro_id, filename) file_dir = self.temp_file_dir + str(key) with open(file_dir, 'wb') as f: f.write(body) f.close() result.code = 0 result.data = {'key': key} self.return_to_client(result) self.finish() up_result = yield self.background_task( self._picture_model.upload_resource, key, body) if up_result: del body logging.info("after upload file key:%s. result code is %s " % (key, result.code)) os.remove(file_dir)
def add_new_person(self, person_id, person_name, picture_list): """Add face tokens to faceset; Args: face_tokens list. Returns: { "faceset_token": "42fb0d5bf81c5ac57c52344dddc3e7c9", "time_used": 479, "face_count": 1, "face_added": 1, "request_id": "1470293555,78637cd1-f773-47c6-8ba4-5af7153e4e00", "outer_id": "uabREDWZvshpHISwVsav", "failure_detail": [] } { u'added': 1, u'errormsg': u'OK', u'face_ids': [u'1989390683606093797', u'1989390686576709605', u'1989390689447710693'], u'session_id': u'', u'errorcode': 0, u'ret_codes': [-1312, 0, -1312] } { u'group_ids': [], u'suc_face': 0, u'errormsg': u'SDK_IMAGE_FACEDETECT_FAILED', u'session_id': u'', u'errorcode': -1101, u'suc_group': 0, u'person_id': u'3' } """ mapping = [ 'insert success', 'has low qualitity picture', 'insert failed', ] if type(person_id) == ObjectId: person_id = str(person_id) to_return = ReturnStruct(mapping) picture = picture_list[0] result = self.youtu.NewPerson(person_id, picture, [self.group_id], person_name=person_name, tag='', data_type=2) logging.info("new person result is %s" % result) # string_token='' # for item in face_tokens: # string_token = string_token+item+',' # string_token = string_token[0:-1] if result['errorcode'] == 0: # first picture detect success. del picture_list[0] if picture_list != []: result2 = self.youtu.AddFace(person_id, picture_list, tag='', data_type=2) logging.info("add face result is %s" % result2) if result2['errorcode'] == 0: if result2['added'] != len(picture_list): # some picture detect failed def find_all_index(arr, item): return [i for i, a in enumerate(arr) if a != item] invalid_index = find_all_index(result2['ret_codes'], 0) def find_all_index_item(arr, arr_index): return [arr[a] for a in arr_index] invalid_msg = find_all_index_item( result2['ret_codes'], invalid_index) to_return.code = 1 to_return.data = { 'invalid_msg': invalid_msg, 'invalid_index': [x + 1 for x in invalid_index] } else: to_return.code = 0 else: # insert failed to_return.code = 2 to_return.data = { 'errorcode': result2['errorcode'], 'errormsg': result2['errormsg'] } else: # only one picture. to_return.code = 0 else: to_return.code = 2 to_return.data = { 'errorcode': result['errorcode'], 'errormsg': result['errormsg'] } if to_return.code != 0: # delete add new person. self.youtu.DelPerson(person_id) return to_return
def detect_img_list(self, binary_picture_list, only): """detect face of a image list through face++, get face_token list as a result. Args: binary_picture_list only: if only, detect the higest quality picture. Returns: ReturnStruct. if code == 1: detect error, return low quality picture number in data['count'] if code == 0: return the faces list in data. example: [ { u'attributes': { u'facequality': 20.67800000000001 }, u'face_token': u'44f2a168abdb7770203ae924f3bfaa6c', u'face_rectangle': { u'width': 180, u'top': 88, u'height': 180, u'left': 99 } }, { u'attributes': { u'facequality': 12.599000000000004 }, u'face_token': u'6eb1852aceb54bb1f69cd66863e0718a', u'face_rectangle': { u'width': 138, u'top': 176, u'height': 138, u'left': 252 } } ] """ message_mapping = [ 'detect all pictures successful', 'has low quality picture' ] to_return = ReturnStruct(message_mapping) detect_result_list = [] count = 0 for binary_picture in binary_picture_list: # detect. detect_result = self.face_model.detect_faces(binary_picture) if detect_result == []: # the quality of pictures is too to detect any faces to_return.code = 1 to_return.data = {'failed_detect_count': count} break else: if only: max_index = 0 max_quality = 0 item_count = 0 # get the highest quality face. for item in detect_result: if item['attributes']['facequality'] > max_quality: max_index = item_count max_quality = item['attributes']['facequality'] item_count += 1 detect_result = detect_result[max_index] # appends. detect_result_list.append(detect_result) else: detect_result_list.extend(detect_result) count += 1 if to_return.code != 1: to_return.data = {'detect_result_list': detect_result_list} # logging.info("[detect result list] detect img list function : %s"%detect_result_list) return to_return
def post(self): """User can upload a picture for a specific person_id. System will compare it and tell user if this is a high confidence face. Besides, if it is a high confidence face, we should store this new message and pugh this message though LBS and pilice man. Args: person_id: picture: coordinate: user_id Returns: """ try: person_id = self.get_argument('person_id') coordinate = eval(self.get_argument('coordinate')) picture = self.get_argument('picture') description = self.get_argument('description') user_id = int(self.get_secure_cookie('user_id')) pic_type = self.get_argument('pic_type') except tornado.web.MissingArgumentError as e: raise MyMissingArgumentError(e.arg_name) try: binary_picture = base64.b64decode(picture) except TypeError as e: raise ArgumentTypeError('picture') message_mapping = [ 'find high confidence person', 'the person maybe not the missing one or you upload a low quality picture' ] result = ReturnStruct(message_mapping) event_happen_date = self.get_even_happen_data() # 1. get person's std picture. personid--> -->face_token # std_face_token = self.person_model.get_person_std_pic(person_id) # # 2. detect picture --> face_token2 # result_detect_struct = yield self.background_task(self.face_model.detect_img_list, [binary_picture], True) # result.merge_info(result_detect_struct) # # 3. compare face_token. # if result_detect_struct.code == 0: # # the result just one element # detect_result = result_detect_struct.data['detect_result_list'] # -----[base64]不需要检测人脸,只要比较person_id和base64;不需要std_face_token;不需要detect_result confidence = yield self.background_task(self.face_model.compare_face, person_id, picture) result.data = confidence logging.info("[compare]the confidence is %s" % confidence) # [change] if confidence['errorcode'] == 0 and confidence[ 'ismatch'] and confidence['level'] >= self.confirm_level: # 4. update info result.code = 0 #[change] 这里也不需要detect_result pic_key_list = yield self.background_task( self.picture_model.store_pictures, [binary_picture], "user" + str(user_id), pic_type) # 4. update track and person information shooter_info = {'user_id': user_id, 'description': description} event_info = { 'coordinate': coordinate, 'confidence': confidence['confidence'], 'pic_key': pic_key_list[0], 'person_id': person_id, 'date': event_happen_date } self.person_model.update_person_status(self.person_model.PERSON, event_info, shooter_info) # 5. send message. message_data = { 'spot': coordinate, 'date': event_happen_date, 'person_id': person_id, 'upload_user_id': user_id, 'confidence': confidence['confidence'], 'pic_key': pic_key_list[0] } self.message_model.send_message_factory(self.message_model.COMPARE, message_data) else: result.code = 1 result.data = confidence self.return_to_client(result) self.finish()
def get(self): """Get all of information of a specific missing person, include person's detail information adn his camera track list and person track list. Args: person_id: Returns: { "message": "default message", "code": 0, "data": { "person_info": { "last_update_time": 1482912276, "lost_time": 1482893944, "relation_telephone": "15195861108", "description": "please help me dear!!!!", "name": "俞敏洪", "lost_spot": [ 22.9, 22.9 ], "picture_key_list": [ "http://cloudeye.oss-cn-shanghai.aliyuncs.com/reporter%3A48%3A%3A1482893949.95.jpg?OSSAccessKeyId=LTAIkY3jD1E5hu8z&Expires=1482912353&Signature=tPpR%2FNFaDVN2cyg%2FmflSpZcZ4Lo%3D", "http://cloudeye.oss-cn-shanghai.aliyuncs.com/reporter%3A48%3A%3A1482893950.13.jpg?OSSAccessKeyId=LTAIkY3jD1E5hu8z&Expires=1482912353&Signature=Jsn00mREm%2BxF0p2n69Jgjn3qfO4%3D" ], "age": 20, "last_update_spot": [ 22.9, 22.9 ], "sex": 0, "relation_name": "chenxionghui", "relation_id": 48, "_id": "58632a7e16b2d67fa66fa9e9", "formal": 0 }, "machine_track": [ { "date": 1482911879, "coordinate": [ 22.9, 22.9 ], "confidence": 89.421, "pic_key": "http://cloudeye.oss-cn-shanghai.aliyuncs.com/camera1%3A%3A1482911881.05.jpg?OSSAccessKeyId=LTAIkY3jD1E5hu8z&Expires=1482912353&Signature=3PJal3HamwECLCeUWS2ivVHU2Uw%3D" }, { "date": 1482912135, "coordinate": [ 22.9, 22.9 ], "confidence": 89.421, "pic_key": "http://cloudeye.oss-cn-shanghai.aliyuncs.com/camera1%3A%3A1482912138.35.jpg?OSSAccessKeyId=LTAIkY3jD1E5hu8z&Expires=1482912353&Signature=yvIfz1Rj6spblpQy5g0n%2Fz%2FiPGY%3D" } ], "person_track": [ { "confidence": 89.543, "pic_key": "http://cloudeye.oss-cn-shanghai.aliyuncs.com/user48%3A%3A1482912281.63.jpg?OSSAccessKeyId=LTAIkY3jD1E5hu8z&Expires=1482912353&Signature=f4gzXa%2B1UwfKTVMSQBaiihkBPbI%3D", "user_id": 48, "description": "maybe I find this missing child!", "coordinate": [ 22.9, 22.9 ], "user_nick_name": "burningbear", "date": 1482912276 } ] } } """ result = ReturnStruct() person_id = self.get_argument("person_id") # temp for web request. jquery = '' try: jquery = str(self.get_argument('jsoncallback')) except Exception as e: pass person_info = self.person_model.get_person_detail(person_id) result.data = person_info self.return_to_client(result, jquery) self.finish()