def detect_safe_search(self, limit=10): """Retreive safe search properties from an image. :type limit: int :param limit: The number of faces to try and detect. :rtype: list :returns: List of :class:`~google.cloud.vision.sage.SafeSearchAnnotation`. """ safe_detection_feature = Feature(FeatureTypes.SAFE_SEARCH_DETECTION, limit) result = self.client.annotate(self, [safe_detection_feature]) safe_search_response = result['safeSearchAnnotation'] return SafeSearchAnnotation.from_api_repr(safe_search_response)
def _entity_from_response_type(feature_type, results): """Convert a JSON result to an entity type based on the feature.""" detected_objects = [] feature_key = _REVERSE_TYPES[feature_type] if feature_type == _FACE_DETECTION: detected_objects.extend( Face.from_api_repr(face) for face in results[feature_key]) elif feature_type == _IMAGE_PROPERTIES: detected_objects.append( ImagePropertiesAnnotation.from_api_repr(results[feature_key])) elif feature_type == _SAFE_SEARCH_DETECTION: result = results[feature_key] detected_objects.append(SafeSearchAnnotation.from_api_repr(result)) else: for result in results[feature_key]: detected_objects.append(EntityAnnotation.from_api_repr(result)) return detected_objects
def _entity_from_response_type(feature_type, results): """Convert a JSON result to an entity type based on the feature. :rtype: list :returns: List containing any of :class:`~google.cloud.vision.color.ImagePropertiesAnnotation`, :class:`~google.cloud.vision.entity.EntityAnnotation`, :class:`~google.cloud.vision.face.Face`, :class:`~google.cloud.vision.safe.SafeSearchAnnotation`. """ detected_objects = [] if feature_type == _FACE_ANNOTATIONS: detected_objects.extend(Face.from_api_repr(face) for face in results) elif feature_type == _IMAGE_PROPERTIES_ANNOTATION: detected_objects.append(ImagePropertiesAnnotation.from_api_repr(results)) elif feature_type == _SAFE_SEARCH_ANNOTATION: detected_objects.append(SafeSearchAnnotation.from_api_repr(results)) else: for result in results: detected_objects.append(EntityAnnotation.from_api_repr(result)) return detected_objects
def _entity_from_response_type(feature_type, results): """Convert a JSON result to an entity type based on the feature. :rtype: list :returns: List containing any of :class:`~google.cloud.vision.color.ImagePropertiesAnnotation`, :class:`~google.cloud.vision.entity.EntityAnnotation`, :class:`~google.cloud.vision.face.Face`, :class:`~google.cloud.vision.safe.SafeSearchAnnotation`. """ detected_objects = [] if feature_type == _FACE_ANNOTATIONS: detected_objects.extend(Face.from_api_repr(face) for face in results) elif feature_type == _IMAGE_PROPERTIES_ANNOTATION: detected_objects.append( ImagePropertiesAnnotation.from_api_repr(results)) elif feature_type == _SAFE_SEARCH_ANNOTATION: detected_objects.append(SafeSearchAnnotation.from_api_repr(results)) else: for result in results: detected_objects.append(EntityAnnotation.from_api_repr(result)) return detected_objects