Source code for azure.cognitiveservices.vision.face.operations.face_list_operations

# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from msrest.pipeline import ClientRawResponse

from .. import models


[docs]class FaceListOperations(object): """FaceListOperations operations. :param client: Client for service requests. :param config: Configuration of service client. :param serializer: An object model serializer. :param deserializer: An object model deserializer. """ models = models def __init__(self, client, config, serializer, deserializer): self._client = client self._serialize = serializer self._deserialize = deserializer self.config = config
[docs] def create( self, face_list_id, name=None, user_data=None, custom_headers=None, raw=False, **operation_config): """Create an empty face list. Up to 64 face lists are allowed to exist in one subscription. :param face_list_id: Id referencing a particular face list. :type face_list_id: str :param name: User defined name, maximum length is 128. :type name: str :param user_data: User specified data. Length should not exceed 16KB. :type user_data: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: None or ClientRawResponse if raw=true :rtype: None or ~msrest.pipeline.ClientRawResponse :raises: :class:`APIErrorException<azure.cognitiveservices.vision.face.models.APIErrorException>` """ body = models.NameAndUserDataContract(name=name, user_data=user_data) # Construct URL url = self.create.metadata['url'] path_format_arguments = { 'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True), 'faceListId': self._serialize.url("face_list_id", face_list_id, 'str', max_length=64, pattern=r'^[a-z0-9-_]+$') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body body_content = self._serialize.body(body, 'NameAndUserDataContract') # Construct and send request request = self._client.put(url, query_parameters, header_parameters, body_content) response = self._client.send(request, stream=False, **operation_config) if response.status_code not in [200]: raise models.APIErrorException(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response
create.metadata = {'url': '/facelists/{faceListId}'}
[docs] def get( self, face_list_id, custom_headers=None, raw=False, **operation_config): """Retrieve a face list's information. :param face_list_id: Id referencing a particular face list. :type face_list_id: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: FaceList or ClientRawResponse if raw=true :rtype: ~azure.cognitiveservices.vision.face.models.FaceList or ~msrest.pipeline.ClientRawResponse :raises: :class:`APIErrorException<azure.cognitiveservices.vision.face.models.APIErrorException>` """ # Construct URL url = self.get.metadata['url'] path_format_arguments = { 'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True), 'faceListId': self._serialize.url("face_list_id", face_list_id, 'str', max_length=64, pattern=r'^[a-z0-9-_]+$') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Accept'] = 'application/json' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters, header_parameters) response = self._client.send(request, stream=False, **operation_config) if response.status_code not in [200]: raise models.APIErrorException(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('FaceList', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized
get.metadata = {'url': '/facelists/{faceListId}'}
[docs] def update( self, face_list_id, name=None, user_data=None, custom_headers=None, raw=False, **operation_config): """Update information of a face list. :param face_list_id: Id referencing a particular face list. :type face_list_id: str :param name: User defined name, maximum length is 128. :type name: str :param user_data: User specified data. Length should not exceed 16KB. :type user_data: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: None or ClientRawResponse if raw=true :rtype: None or ~msrest.pipeline.ClientRawResponse :raises: :class:`APIErrorException<azure.cognitiveservices.vision.face.models.APIErrorException>` """ body = models.NameAndUserDataContract(name=name, user_data=user_data) # Construct URL url = self.update.metadata['url'] path_format_arguments = { 'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True), 'faceListId': self._serialize.url("face_list_id", face_list_id, 'str', max_length=64, pattern=r'^[a-z0-9-_]+$') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body body_content = self._serialize.body(body, 'NameAndUserDataContract') # Construct and send request request = self._client.patch(url, query_parameters, header_parameters, body_content) response = self._client.send(request, stream=False, **operation_config) if response.status_code not in [200]: raise models.APIErrorException(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response
update.metadata = {'url': '/facelists/{faceListId}'}
[docs] def delete( self, face_list_id, custom_headers=None, raw=False, **operation_config): """Delete an existing face list according to faceListId. Persisted face images in the face list will also be deleted. :param face_list_id: Id referencing a particular face list. :type face_list_id: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: None or ClientRawResponse if raw=true :rtype: None or ~msrest.pipeline.ClientRawResponse :raises: :class:`APIErrorException<azure.cognitiveservices.vision.face.models.APIErrorException>` """ # Construct URL url = self.delete.metadata['url'] path_format_arguments = { 'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True), 'faceListId': self._serialize.url("face_list_id", face_list_id, 'str', max_length=64, pattern=r'^[a-z0-9-_]+$') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.delete(url, query_parameters, header_parameters) response = self._client.send(request, stream=False, **operation_config) if response.status_code not in [200]: raise models.APIErrorException(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response
delete.metadata = {'url': '/facelists/{faceListId}'}
[docs] def list( self, custom_headers=None, raw=False, **operation_config): """Retrieve information about all existing face lists. Only faceListId, name and userData will be returned. :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: list or ClientRawResponse if raw=true :rtype: list[~azure.cognitiveservices.vision.face.models.FaceList] or ~msrest.pipeline.ClientRawResponse :raises: :class:`APIErrorException<azure.cognitiveservices.vision.face.models.APIErrorException>` """ # Construct URL url = self.list.metadata['url'] path_format_arguments = { 'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True) } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Accept'] = 'application/json' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters, header_parameters) response = self._client.send(request, stream=False, **operation_config) if response.status_code not in [200]: raise models.APIErrorException(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('[FaceList]', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized
list.metadata = {'url': '/facelists'}
[docs] def delete_face( self, face_list_id, persisted_face_id, custom_headers=None, raw=False, **operation_config): """Delete an existing face from a face list (given by a persisitedFaceId and a faceListId). Persisted image related to the face will also be deleted. :param face_list_id: Id referencing a particular face list. :type face_list_id: str :param persisted_face_id: Id referencing a particular persistedFaceId of an existing face. :type persisted_face_id: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: None or ClientRawResponse if raw=true :rtype: None or ~msrest.pipeline.ClientRawResponse :raises: :class:`APIErrorException<azure.cognitiveservices.vision.face.models.APIErrorException>` """ # Construct URL url = self.delete_face.metadata['url'] path_format_arguments = { 'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True), 'faceListId': self._serialize.url("face_list_id", face_list_id, 'str', max_length=64, pattern=r'^[a-z0-9-_]+$'), 'persistedFaceId': self._serialize.url("persisted_face_id", persisted_face_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.delete(url, query_parameters, header_parameters) response = self._client.send(request, stream=False, **operation_config) if response.status_code not in [200]: raise models.APIErrorException(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response
delete_face.metadata = {'url': '/facelists/{faceListId}/persistedfaces/{persistedFaceId}'}
[docs] def add_face_from_url( self, face_list_id, url, user_data=None, target_face=None, custom_headers=None, raw=False, **operation_config): """Add a face to a face list. The input face is specified as an image with a targetFace rectangle. It returns a persistedFaceId representing the added face, and persistedFaceId will not expire. :param face_list_id: Id referencing a particular face list. :type face_list_id: str :param url: Publicly reachable URL of an image :type url: str :param user_data: User-specified data about the face for any purpose. The maximum length is 1KB. :type user_data: str :param target_face: A face rectangle to specify the target face to be added to a person in the format of "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there is more than one face in the image, targetFace is required to specify which face to add. No targetFace means there is only one face detected in the entire image. :type target_face: list[int] :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: PersistedFace or ClientRawResponse if raw=true :rtype: ~azure.cognitiveservices.vision.face.models.PersistedFace or ~msrest.pipeline.ClientRawResponse :raises: :class:`APIErrorException<azure.cognitiveservices.vision.face.models.APIErrorException>` """ image_url = models.ImageUrl(url=url) # Construct URL url = self.add_face_from_url.metadata['url'] path_format_arguments = { 'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True), 'faceListId': self._serialize.url("face_list_id", face_list_id, 'str', max_length=64, pattern=r'^[a-z0-9-_]+$') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if user_data is not None: query_parameters['userData'] = self._serialize.query("user_data", user_data, 'str', max_length=1024) if target_face is not None: query_parameters['targetFace'] = self._serialize.query("target_face", target_face, '[int]', div=',') # Construct headers header_parameters = {} header_parameters['Accept'] = 'application/json' header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body body_content = self._serialize.body(image_url, 'ImageUrl') # Construct and send request request = self._client.post(url, query_parameters, header_parameters, body_content) response = self._client.send(request, stream=False, **operation_config) if response.status_code not in [200]: raise models.APIErrorException(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('PersistedFace', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized
add_face_from_url.metadata = {'url': '/facelists/{faceListId}/persistedfaces'}
[docs] def add_face_from_stream( self, face_list_id, image, user_data=None, target_face=None, custom_headers=None, raw=False, callback=None, **operation_config): """Add a face to a face list. The input face is specified as an image with a targetFace rectangle. It returns a persistedFaceId representing the added face, and persistedFaceId will not expire. :param face_list_id: Id referencing a particular face list. :type face_list_id: str :param image: An image stream. :type image: Generator :param user_data: User-specified data about the face for any purpose. The maximum length is 1KB. :type user_data: str :param target_face: A face rectangle to specify the target face to be added to a person in the format of "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there is more than one face in the image, targetFace is required to specify which face to add. No targetFace means there is only one face detected in the entire image. :type target_face: list[int] :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param callback: When specified, will be called with each chunk of data that is streamed. The callback should take two arguments, the bytes of the current chunk of data and the response object. If the data is uploading, response will be None. :type callback: Callable[Bytes, response=None] :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: PersistedFace or ClientRawResponse if raw=true :rtype: ~azure.cognitiveservices.vision.face.models.PersistedFace or ~msrest.pipeline.ClientRawResponse :raises: :class:`APIErrorException<azure.cognitiveservices.vision.face.models.APIErrorException>` """ # Construct URL url = self.add_face_from_stream.metadata['url'] path_format_arguments = { 'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True), 'faceListId': self._serialize.url("face_list_id", face_list_id, 'str', max_length=64, pattern=r'^[a-z0-9-_]+$') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if user_data is not None: query_parameters['userData'] = self._serialize.query("user_data", user_data, 'str', max_length=1024) if target_face is not None: query_parameters['targetFace'] = self._serialize.query("target_face", target_face, '[int]', div=',') # Construct headers header_parameters = {} header_parameters['Accept'] = 'application/json' header_parameters['Content-Type'] = 'application/octet-stream' if custom_headers: header_parameters.update(custom_headers) # Construct body body_content = self._client.stream_upload(image, callback) # Construct and send request request = self._client.post(url, query_parameters, header_parameters, body_content) response = self._client.send(request, stream=False, **operation_config) if response.status_code not in [200]: raise models.APIErrorException(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('PersistedFace', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized
add_face_from_stream.metadata = {'url': '/facelists/{faceListId}/persistedfaces'}