profile_photo.utils.aws package¶
Submodules¶
profile_photo.utils.aws.client_cache module¶
- class profile_photo.utils.aws.client_cache.ClientCache(region_name: 'str' = 'us-east-1', profile_name: 'str | None' = None, init_client: 'InitVar[bool]' = False, max_pool_connections: 'int | None' = None)[source]¶
Bases:
object- SERVICE_NAME: ClassVar[str] = None¶
- THREAD_SAFE: ClassVar[bool] = False¶
- property client¶
- init_client: InitVar[bool] = False¶
- max_pool_connections: int | None = None¶
- profile_name: str | None = None¶
- region_name: str = 'us-east-1'¶
profile_photo.utils.aws.rekognition module¶
- class profile_photo.utils.aws.rekognition.Rekognition(region_name: 'str' = 'us-east-1', profile_name: 'str | None' = None, init_client: 'InitVar[bool]' = False, max_pool_connections: 'int | None' = None)[source]¶
Bases:
ClientCache- SERVICE_NAME: ClassVar[str] = 'rekognition'¶
- detect_faces(bucket: str, key: str, im_bytes: bytes | None = None, debug=False, all_attrs=True)[source]¶
Call the DetectFaces API on an image, or use the DynamoDB cache if needed.
- detect_labels(bucket: str, key: str, im_bytes: bytes | None = None, debug=False, confidence=55)[source]¶
Call the DetectLabels API on an image, or use the DynamoDB cache if needed.
profile_photo.utils.aws.rekognition_models module¶
- class profile_photo.utils.aws.rekognition_models.BoundingBox(width: float, height: float, left: float, top: float)[source]¶
Bases:
objectBoundingBox dataclass
- height: float¶
- left: float¶
- top: float¶
- width: float¶
- class profile_photo.utils.aws.rekognition_models.CompareFacesResp(source_image_face: SourceImageFace, face_matches: List[FaceMatch], unmatched_faces: List[UnmatchedFace])[source]¶
Bases:
JSONSerializableResponse from the Rekognition CompareFaces API
- face_matches: List[FaceMatch]¶
- source_image_face: SourceImageFace¶
- unmatched_faces: List[UnmatchedFace]¶
- class profile_photo.utils.aws.rekognition_models.Coordinates(x1: int, y1: int, x2: int, y2: int)[source]¶
Bases:
objectCoordinates dataclass.
Can be visualized using this diagram:
x1,y1 —————– | | | | | | | | | | —————— x2,y2
- classmethod from_box(im, box: BoundingBox, offset=0, y_offset=0)[source]¶
- x1: int¶
- x2: int¶
- y1: int¶
- y2: int¶
- class profile_photo.utils.aws.rekognition_models.DetectFacesResp(face_details: List[FaceDetail])[source]¶
Bases:
JSONSerializableResponse from the Rekognition DetectFaces API
- face_details: List[FaceDetail]¶
- get_face() FaceDetail | None[source]¶
Return the primary face that is detected, if available.
- class profile_photo.utils.aws.rekognition_models.DetectLabelsResp(labels: List[Label])[source]¶
Bases:
JSONSerializableResponse from Rekognition DetectLabels API
- get_person_box(face: FaceDetail | None) BoundingBox | None[source]¶
Get the bounding box for the ‘Person’ label.
If there are multiple instances of a ‘Person’, then the argument for face helps pinpoint a matching person.
- property label_name_to_value: DictWithLowerStore[str, Label]¶
Return a case-insensitive mapping of label name to label.
- property person_boxes: list[BoundingBox] | None¶
- class profile_photo.utils.aws.rekognition_models.Face(bounding_box: BoundingBox, confidence: float, landmarks: List[Landmark], pose: Pose, quality: Quality)[source]¶
Bases:
objectFace dataclass
- bounding_box: BoundingBox¶
- confidence: float¶
- pose: Pose¶
- quality: Quality¶
- class profile_photo.utils.aws.rekognition_models.FaceDetail(bounding_box: BoundingBox, age_range: AgeRange, smile: Smile, eyeglasses: Eyeglasses, sunglasses: Sunglasses, gender: Gender, beard: Beard, mustache: Mustache, eyes_open: EyesOpen, mouth_open: MouthOpen, emotions: List[Emotion], landmarks: List[Landmark], pose: Pose, quality: Quality, confidence: float)[source]¶
Bases:
objectFaceDetail dataclass
- age_range: AgeRange¶
- beard: Beard¶
- bounding_box: BoundingBox¶
- confidence: float¶
- property emotion_to_confidence: DictWithLowerStore[str, float]¶
Return a case-insensitive mapping of emotion name to its confidence.
- emotions: List[Emotion]¶
- eyeglasses: Eyeglasses¶
- eyes_open: EyesOpen¶
- gender: Gender¶
- mouth_open: MouthOpen¶
- mustache: Mustache¶
- pose: Pose¶
- quality: Quality¶
- smile: Smile¶
- sunglasses: Sunglasses¶
- class profile_photo.utils.aws.rekognition_models.Label(name: str, confidence: float, instances: List[Instance], parents: List[Parent])[source]¶
Bases:
objectLabel dataclass
- confidence: float¶
- instances: List[Instance]¶
- name: str¶
- parents: List[Parent]¶
- class profile_photo.utils.aws.rekognition_models.Landmark(type: str, x: float, y: float)[source]¶
Bases:
objectLandmark dataclass
- type: str¶
- x: float¶
- y: float¶
- class profile_photo.utils.aws.rekognition_models.RecognizeCelebritiesResp(celebrity_faces: List[CelebrityFace], unrecognized_faces: List[Face], orientation_correction: Literal['ROTATE_0', 'ROTATE_90', 'ROTATE_180', 'ROTATE_270'] = 'ROTATE_0')[source]¶
Bases:
JSONSerializableResponse from the Rekognition RecognizeCelebrities API
- celebrity_faces: List[CelebrityFace]¶
- orientation_correction: Literal['ROTATE_0', 'ROTATE_90', 'ROTATE_180', 'ROTATE_270'] = 'ROTATE_0'¶
profile_photo.utils.aws.rekognition_utils module¶
- class profile_photo.utils.aws.rekognition_utils.FillColor(value)[source]¶
Bases:
EnumAn enumeration.
- BLACK = '#000000'¶
- BLUE = '#0000ff'¶
- GREEN = '#00d400'¶
- RED = '#ff0000'¶
- WHITE = '#FFFFFF'¶
- YELLOW = '#ffff00'¶
- property bgr¶
Returns the BGR representation of the color.
- profile_photo.utils.aws.rekognition_utils.best_fit_coordinates(im, face_box: BoundingBox, *boxes: BoundingBox | None, fit=0.2857142857142857, x_offset=0.17, y_offset=0.17, constrain_width=True) Coordinates[source]¶
- profile_photo.utils.aws.rekognition_utils.draw_box(image: Image, box: BoundingBox, color: FillColor = FillColor.GREEN, line_width=3, offset=0)[source]¶
Draw a bounding box on the image at the specified coordinates box and with the specified border color and line_width. An optional offset can be provided to change box coordinates. For example, an offset of line_width + line_width can be used to create an “inner” bounding box.
Displays the image after the box has been drawn.
Ref: https://docs.aws.amazon.com/rekognition/latest/dg/images-displaying-bounding-boxes.html
Usage:
>>> im = Image.open('path/to/file.jpeg') >>> draw_box(im, data['FaceDetails'][0]['BoundingBox'], FillColor.YELLOW)
- profile_photo.utils.aws.rekognition_utils.draw_circle(im, landmark: Landmark, color: FillColor = FillColor.YELLOW, radius: int = 3, filled=True, font_scale=0.4, font_face=4, text: str | None = None, text_color: FillColor = FillColor.WHITE)[source]¶
Draw a (filled) circle on the image centered around the specified (x, y) coordinates for landmark and with the specified border color and radius radius.
Ref: https://www.pyimagesearch.com/2021/01/27/drawing-with-opencv/
Usage:
>>> img = cv.imread('path/to/file.jpeg') >>> draw_circle(img, data['FaceDetails'][0]['Landmarks'][0], FillColor.YELLOW, 3, False)
- profile_photo.utils.aws.rekognition_utils.draw_rectangle(im, coords_or_box: Coordinates | BoundingBox, color: FillColor = FillColor.GREEN, offset=0, y_offset=0, line_width=3)[source]¶
Draw a bounding box on the image at the specified coordinates box and with the specified border color and line_width.
An optional offset can be provided to enhance or “zoom out” on the box coordinates.
Usage:
>>> img = cv.imread('path/to/file.jpeg') >>> draw_rectangle(img, data['FaceDetails'][0]['BoundingBox'], FillColor.YELLOW)
profile_photo.utils.aws.s3 module¶
- class profile_photo.utils.aws.s3.S3Helper(region_name='us-east-1', profile_name=None, access_key: str | None = None, secret_key: str | None = None, use_sig_v4=False, init_client=False, max_pool_connections=None)[source]¶
Bases:
ClientCacheHelper class for interacting with the boto3 S3 client.
- SERVICE_NAME: ClassVar[str] = 's3'¶