def user_register(self, faceset_id, face_list): ''' OpenAPI 注册用户接口,内部对指定人脸库注册用户并异步注册给绑定的IPC。返回本次操作的操作id,状态码与错误信息。 注册用户操作为批量操作,一次最多输入10个用户。每个用户只支持1 张照片,照片为Base64形式编码。 :param faceset_id: :param face_list: :return: ''' method = 'POST' path = self.api_version + '/facesets/%s/faces' % faceset_id if not isinstance(face_list, tuple): raise ValueError('face_list must be a arry') data = {'face_list': face_list} headers = {'host': self.host, 'content-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) url = '{0}{1}'.format(self.base_url, path) print(url) ret, info = dohttp._post(url, json.dumps(data), authorization, headers=headers) return ret, info
def screenshot(self, device_sn): ''' 获取指定设备预览图,该接口是一个异步接口,若要获取最新的结果,需要根据返回的request_id调用获取异步请求状态获取 :param device_sn: :return: ''' method = 'POST' path = self.api_version + '/devices/screenshot' data = {'device_sn': device_sn} headers = {'host': self.host, 'content-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) # url = 'http://{0}{1}?authorization={2}'.format(self.host, path, authorization) url = '{0}{1}'.format(self.base_url, path) print(url) ret, info = dohttp._post(url, json.dumps(data), authorization, headers=headers) return ret, info
def faceset_ipc_sync(self, faceset_id, face_id, device_sn): ''' OpenAPI获取同步IPC人脸库用户指令,内部依据云端人脸库用户数据同步至IPC人脸库,如云端人脸库不存在用户id,则删除IPC内此用户数据。 返回本次操作的操作id,状态码与错误信息 :param faceset_id: :param face_id: :return: ''' method = 'POST' path = self.api_version + '/facesets/%s/faces/%s/sync' % (faceset_id, face_id) data = {'device_sn': device_sn} headers = {'host': self.host, 'content-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) url = '{0}{1}'.format(self.base_url, path) print(url) ret, info = dohttp._post(url, data=json.dumps(data), auth=authorization, headers=headers) return ret, info
def faceset_build(self, name): ''' OpenAPI获取创建人脸库指令,内部创建空照片库,返回本次操作的状态码与错误信息 :param name:string 是 人脸库名称,允许中文,数字、大小写字母、下划线组成,长度限制1-16字符 :return: ''' method = 'POST' path = self.api_version + '/facesets' data = {'name': name} headers = {'host': self.host, 'content-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) # url = 'http://{0}{1}?authorization={2}'.format(self.host, path, authorization) url = '{0}{1}'.format(self.base_url, path) print(url) ret, info = dohttp._post(url, json.dumps(data), authorization, headers=headers) return ret, info
def device_behavior_recognition(self, reqbody): ''' :param reqbody: :return: ''' method = 'POST' path = self.api_version + '/driver_behavior' if not isinstance(reqbody, dict): raise ValueError('Reqeust Body is a dict [%s] ', str(_drive_behavior_body_feild)) data = reqbody headers = {'host': self.host, 'content-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) url = '{0}{1}'.format(self.base_url, path) print(url) ret, info = dohttp._post(url, json.dumps(data), authorization, headers=headers) return ret, info
def faceset_ipc_bind(self, faceset_id, device_list): ''' OpenAPI获取绑定人脸库和IPC的指令,内部建立人脸库与IPC的关联关系,并将人脸库数据同步至IPC,返回本次操作的操作id,状态码与错误信息。 绑定时可以设定IPC 人脸库阈值,可选,默认值为0.74,有效范围为(0.0,1.0)。重复绑定人脸库会返回错误 :param faceset_id: :param device_list: :return: ''' method = 'POST' path = self.api_version + '/facesets/%s/bind' % faceset_id if not isinstance(device_list, tuple): raise ValueError( 'device_list is a arry[{"device_sn":xx,"threshold":xx}]') data = {'device_list': device_list} headers = {'host': self.host, 'content-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) url = '{0}{1}'.format(self.base_url, path) print(url) ret, info = dohttp._post(url, data=json.dumps(data), auth=authorization, headers=headers) return ret, info
def attach_facesets_to_space(self, space_ids, faceset_ids): ''' 将人脸库指定要用的设备空间,这样设备空间下的ipc上来的数据就会去检索该人脸库,确定是否属于人脸库中的人员 :param space_ids: string array 是 设备空间数组 :param faceset_ids: string array 是 人脸库ID数组 :return: ''' method = 'POST' path = self.api_version + '/analysis_tools/attach_space' data = {'space_ids': space_ids, 'faceset_ids': faceset_ids} headers = {'host': self.host, 'content-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) url = '{0}{1}'.format(self.base_url, path) print(url) ret, info = dohttp._post(url, json.dumps(data), authorization, headers=headers) return ret, info
def enable_analysis(self, space_id, enable_auto_reg=True): ''' :param space_id: string 是 设备空间id :param enable_auto_reg:boolean 否 是否使用自动建档,true:使用自动建档功能,false:不使用自动建档功能,不传默认开启自动建档 :return: ''' method = 'POST' path = self.api_version + '/analysis_tools/enable' data = {'space_id': space_id, 'enable_auto_reg': enable_auto_reg} headers = {'host': self.host, 'content-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) url = '{0}{1}'.format(self.base_url, path) print(url) ret, info = dohttp._post(url, json.dumps(data), authorization, headers=headers) return ret, info
def build(self, name, **kwargs): ''' 为当前api调用者创建人脸库 :param name string 是 人脸库名, 长度限制80字符 extra string 否 人脸库额外信息,长度限制512字符 description string 否 人脸库描述,长度限制512字符 :return: ''' method = 'POST' path = self.api_version + '/facesets' data = {'name': name} for k, v in kwargs.items(): if k in _faseset_feild: data.update({k: v}) headers = {'host': self.host, 'content-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) # url = 'http://{0}{1}?authorization={2}'.format(self.host, path, authorization) url = '{0}{1}'.format(self.base_url, path) print(url) ret, info = dohttp._post(url, json.dumps(data), authorization, headers=headers) return ret, info
def register(self, faceset_id, images, **kwargs): ''' 用于向人脸库中新增用户 :param faceset_id: :param kwargs: :return: ''' method = 'POST' path = self.api_version + '/facesets/%s/faces' % faceset_id data = {'images': images} for k, v in kwargs.items(): if k in _face_user_register_feild: data.update({k: v}) else: raise ValueError('error param [%s]' % k) headers = {'host': self.host, 'content-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) url = '{0}{1}'.format(self.base_url, path) print(url) ret, info = dohttp._post(url, json.dumps(data), authorization, headers=headers) return ret, info
def update_user_image(self, faceset_id, face_id, images, **kwargs): ''' 用于向人脸库中指定用户添加人脸特征图片 :param faceset_id: :param face_id: :param images: :return: ''' method = 'POST' path = self.api_version + '/facesets/%s/faces/%s/images_add' % ( faceset_id, face_id) data = {'images': images} for k, v in kwargs.items(): if k in _face_user_register_feild: data.update({k: v}) headers = {'host': self.host, 'conent-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) url = '{0}{1}'.format(self.base_url, path) print(url) ret, info = dohttp._post(url, data=json.dumps(data), auth=authorization, headers=headers) return ret, info
def build(self, name, **kwargs): ''' 创建设备空间 :param name: 设备空间名字 :param description: 设备空间描述 :param extra: 其他冗余扩展信息,dict 格式 :return: ''' method = 'POST' path = self.api_version + '/device_spaces' data = {'name': name} for k, v in kwargs.items(): if k in _space_config_feild: data.update({k: v}) headers = {'host': self.host, 'content-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) url = '{0}{1}'.format(self.base_url, path) print(url) ret, info = dohttp._post(url, json.dumps(data), authorization, '', headers=headers) return ret, info
def search(self, image_type, image_obj, faceset_ids, **kwargs): ''' :param image_type: :param image_obj: :param faceset_ids: :param kwargs: :return: ''' method = 'POST' path = self.api_version + '/faces/search' data = {'image_type': image_type} if image_type: data.update({'image_base64': image_obj}) else: if self.__checkurl(image_obj): data.update({'image_url': image_obj}) else: raise ValueError('error image_url [%s..]' % (image_obj[:10])) data.update({'faceset_ids': faceset_ids}) for k, v in kwargs.items(): if k in _face_search_feild: data.update({k: v}) headers = {'host': self.host, 'content-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) url = '{0}{1}'.format(self.base_url, path) ret, info = dohttp._post(url, json.dumps(data), authorization, headers=headers) return ret, info
def pf_line_config(self, device_sn, lines, start_time, end_time): ''' 用于配置画线信息,如画线朝向,点的信息 :param device_sn: :param lines:[ { 'line_type':xx 'point':{} }, {} ] :param start_time: 指统计开始的时间 :param end_time: 指统计结束的时间 :return: ''' method = 'POST' path = self.api_version + '/passengerflow/lines_config' data = { 'device_sn': device_sn, 'lines': lines, 'start_time': start_time, 'end_time': end_time } headers = {'host': self.host, 'content-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) url = '{0}{1}'.format(self.base_url, path) print(url) ret, info = dohttp._post(url, json.dumps(data), authorization, headers=headers) return ret, info
def match(self, image_type, image_obj_1, image_obj_2, **kwargs): ''' 将两个人脸进行比对,来判断是否为同一个人 :param image_type: :param image_obj: :param kwargs: :return: ''' method = 'POST' path = self.api_version + '/faces/match' data = {'image_type': image_type} if image_type: data.update({'image_base64_1': image_obj_1}) data.update({'image_base64_2': image_obj_2}) else: data.update({'image_url_1': image_obj_1}) data.update({'image_url_2': image_obj_2}) for k, v in kwargs.items(): if k in _face_match_feild: data.update({k: v}) headers = {'host': self.host, 'content-type': self.content_type} authorization = self.auth.get_sign(http_method=method, path=path, params=None, headers=headers) url = '{0}{1}'.format(self.base_url, path) print(url) ret, info = dohttp._post(url, json.dumps(data), authorization, headers=headers) return ret, info