def facesFactory(image: ImageForRedetection) -> List[Face]: faces = [ Face(image.image.coreImage, DetectionFloat(bBox.coreRectF, 1.0)) for bBox in image.bBoxes ] return faces
def _collectDetectionsResult( fsdkDetectRes: IFaceDetectionBatchPtr, images: Union[List[Union[VLImage, ImageForDetection]], List[ImageForRedetection]], isRedectResult: bool = False, ) -> Union[List[List[Optional[FaceDetection]]], List[List[Optional[FaceDetection]]]]: """ Collect detection results from core reply and prepare face detections Args: fsdkDetectRes: fsdk (re)detect results images: incoming images Returns: return list of lists detection, order of detection lists is corresponding to order input images Raises: RuntimeError: if any detection is not valid and it is not redection result """ res = [] for imageIdx in range(fsdkDetectRes.getSize()): imagesDetections = [] detections = fsdkDetectRes.getDetections(imageIdx) landmarks5Array = fsdkDetectRes.getLandmarks5(imageIdx) landmarks68Array = fsdkDetectRes.getLandmarks68(imageIdx) image = images[imageIdx] vlImage = image if isinstance(image, VLImage) else image.image faceDetections = [] for detectionIdx, detection in enumerate(detections): face = Face(vlImage.coreImage, detection) if landmarks5Array: face.landmarks5_opt.set(landmarks5Array[detectionIdx]) if landmarks68Array: face.landmarks68_opt.set(landmarks68Array[detectionIdx]) imagesDetections.append(face) if not face.isValid(): if not isRedectResult: raise RuntimeError("Invalid detection") faceDetection = None else: faceDetection = FaceDetection(face, vlImage) faceDetections.append(faceDetection) res.append(faceDetections) return res
def _createCoreFaces(image: ImageForRedetection) -> List[Face]: """ Create core faces for redetection Args: image: image and bounding boxes for redetection Returns: Face object list. one object for one bbox """ return [Face(image.image.coreImage, DetectionFloat(bBox.coreRectF, 1.0)) for bBox in image.bBoxes]
def postProcessingRedetectOne(error: FSDKErrorResult, detectRes: Face, image: VLImage) -> Optional[FaceDetection]: """ Convert core face detection to `FaceDetection` after redect and error check. Args: error: detection error, usually error.isError is False detectRes: detections image: original image Raises: LunaSDKException: if detect is failed Returns: face detection if detection is valid (face was found) otherwise None (face was not found) """ assertError(error) if detectRes.isValid(): return FaceDetection(detectRes, image) return None
def postProcessingOne(error: FSDKErrorResult, detectRes: Face, image: VLImage) -> Optional[FaceDetection]: """ Convert core face detection to `FaceDetection` after detect one and error check. Args: error: detection error, usually error.isError is False detectRes: detections image: original image Raises: LunaSDKException: if detect is failed Returns: face detection """ assertError(error) if not detectRes.isValid(): return None return FaceDetection(detectRes, image)
def collectDetectionsResult( fsdkDetectRes: IFaceDetectionBatchPtr, coreImages: List[CoreImage], images: Union[List[Union[VLImage, ImageForDetection]], List[ImageForRedetection]], ): """ Collect detection results from core reply and prepare face detections Args: fsdkDetectRes: fsdk (re)detect results coreImages: core images images: incoming images Returns: return list of lists detection, order of detection lists is corresponding to order input images """ res = [] for imageIdx in range(fsdkDetectRes.getSize()): imagesDetections = [] detections = fsdkDetectRes.getDetections(imageIdx) landmarks5Array = fsdkDetectRes.getLandmarks5(imageIdx) landmarks68Array = fsdkDetectRes.getLandmarks68(imageIdx) for detectionIdx, detection in enumerate(detections): face = Face(coreImages[imageIdx], detection) if landmarks5Array: face.landmarks5_opt.set(landmarks5Array[detectionIdx]) if landmarks68Array: face.landmarks68_opt.set(landmarks68Array[detectionIdx]) imagesDetections.append(face) image = images[imageIdx] vlImage = image if isinstance(image, VLImage) else image.image res.append([ FaceDetection(coreDetection, vlImage) if coreDetection.isValid() else None for coreDetection in imagesDetections ]) return res