def redetectOne( # noqa: F811 self, image: VLImage, bBox: Union[Rect, HumanDetection], detectLandmarks: bool = True, asyncEstimate=False, ) -> Union[RedetectResult, AsyncTask[RedetectResult]]: """ Redetect human body on an image in area, restricted with image.bBox, bBox or detection. Args: image: image with a bounding box, or just VLImage. If VLImage provided, one of bBox or detection should be defined. bBox: detection bounding box detectLandmarks: detect or not landmarks Returns: detection if human body found otherwise None if asyncEstimate is false otherwise async task Raises: LunaSDKException if an error occurs """ assertImageForDetection(image) if isinstance(bBox, Rect): coreBBox = Detection(bBox.coreRectF, 1.0) else: coreBBox = bBox.coreEstimation.detection if asyncEstimate: task = self._detector.asyncRedetectOne( image.coreImage, coreBBox, self._getDetectionType(detectLandmarks)) return AsyncTask(task, partial(postProcessingRedetectOne, image=image)) error, detectRes = self._detector.redetectOne( image.coreImage, coreBBox, self._getDetectionType(detectLandmarks)) return postProcessingRedetectOne(error, detectRes, image)
def redetectOne( # noqa: F811 self, image: VLImage, bBox: Union[Rect, HumanDetection] ) -> Union[None, HumanDetection]: """ Redetect human body on an image in area, restricted with image.bBox, bBox or detection. Args: image: image with a bounding box, or just VLImage. If VLImage provided, one of bBox or detection should be defined. bBox: detection bounding box Returns: detection if human body found otherwise None Raises: LunaSDKException if an error occurs """ assertImageForDetection(image) if isinstance(bBox, Rect): coreBBox = Detection(bBox.coreRectF, 1.0) else: coreBBox = bBox.coreEstimation.detection error, detectRes = self._detector.redetectOne(image.coreImage, coreBBox, self._getDetectionType(True)) assertError(error) if detectRes.isValid(): return HumanDetection(detectRes, image) return None
def redetectOne( # noqa: F811 self, image: VLImage, bBox: Union[Rect, FaceDetection], detect5Landmarks=True, detect68Landmarks=False) -> Union[None, FaceDetection]: """ Redetect face on an image in area, restricted with image.bBox, bBox or detection. Args: image: image with a bounding box, or just VLImage. If VLImage provided, one of bBox or detection should be defined. bBox: detection bounding box detect5Landmarks: detect or not landmarks5 detect68Landmarks: detect or not landmarks68 Returns: detection if face found otherwise None Raises: LunaSDKException if an error occurs """ if isinstance(bBox, Rect): coreBBox = Detection(bBox.coreRectF, 1.0) else: coreBBox = bBox.coreEstimation.detection self._validateReDetectInput(image.coreImage, coreBBox) error, detectRes = self._detector.redetectOne( image.coreImage, coreBBox, self._getDetectionType(detect5Landmarks, detect68Landmarks)) assertError(error) if detectRes.isValid(): return FaceDetection(detectRes, image) return None
def test_estimate_head_pose_by_image_and_bounding_box_empty_bounding_box(self): """ Estimating head pose by image and empty bounding box """ fakeDetection = Detection(RectFloat(0.0, 0.0, 0.0, 0.0), 0.9) bBox = BoundingBox(fakeDetection) with pytest.raises(LunaSDKException) as exceptionInfo: self.headPoseEstimator.estimateByBoundingBox(ImageWithFaceDetection(self.image, bBox)) self.assertLunaVlError(exceptionInfo, LunaVLError.InvalidDetection.format("Invalid detection"))
def test_estimate_head_pose_by_image_and_bounding_box_without_intersection(self): """ Estimating head pose by image and bounding box without intersection """ fakeDetection = Detection(RectFloat(3000.0, 3000.0, 100.0, 100.0), 0.9) bBox = BoundingBox(fakeDetection) with pytest.raises(LunaSDKException) as exceptionInfo: self.headPoseEstimator.estimateByBoundingBox(ImageWithFaceDetection(self.image, bBox)) self.assertLunaVlError(exceptionInfo, LunaVLError.InvalidRect.format("Invalid rectangle"))
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, Detection(bBox.coreRectF, 1.0)) for bBox in image.bBoxes ]
def test_estimate_background_by_image_and_bounding_box_without_intersection( self): """ Estimating background by image and bounding box without intersection """ fakeDetection = Detection(RectFloat(3000.0, 3000.0, 100.0, 100.0), 0.9) bBox = BoundingBox(fakeDetection) with pytest.raises(LunaSDKException) as exceptionInfo: self.backgroundEstimator.estimate( ImageWithFaceDetection(VLImage.load(filename=ONE_FACE), bBox)) self.assertLunaVlError( exceptionInfo, LunaVLError.InvalidRect.format("Invalid rectangle"))
def test_estimate_background_by_image_and_bounding_box_empty_bounding_box( self): """ Estimating background by image and empty bounding box """ fakeDetection = Detection(RectFloat(0.0, 0.0, 0.0, 0.0), 0.9) bBox = BoundingBox(fakeDetection) with pytest.raises(LunaSDKException) as exceptionInfo: self.backgroundEstimator.estimate( ImageWithFaceDetection(VLImage.load(filename=ONE_FACE), bBox)) self.assertLunaVlError( exceptionInfo, LunaVLError.InvalidDetection.format("Invalid detection"))
def getArgsForCoreRedetect( images: List[ImageForRedetection] ) -> Tuple[List[CoreImage], List[List[Detection]]]: """ Create args for redetect for image list Args: images: list of images for redetection Returns: tuple: first - list core images second - list detect area for corresponding images """ coreImages, detectAreas = [], [] for image in images: coreImages.append(image.image.coreImage) detectAreas.append( [Detection(bbox.coreRect, 1.0) for bbox in image.bBoxes]) return coreImages, detectAreas
def redetectOne( # noqa: F811 self, image: VLImage, bBox: Union[Rect, FaceDetection], detect5Landmarks=True, detect68Landmarks=False, asyncEstimate=False, ) -> Union[FaceRedetectResult, AsyncTask[FaceRedetectResult]]: """ Redetect face on an image in area, restricted with image.bBox, bBox or detection. Args: image: image with a bounding box, or just VLImage. If VLImage provided, one of bBox or detection should be defined. bBox: detection bounding box detect5Landmarks: detect or not landmarks5 detect68Landmarks: detect or not landmarks68 asyncEstimate: estimate or run estimation in background Returns: detection if face found otherwise None if asyncEstimate is false otherwise async task Raises: LunaSDKException if an error occurs """ if isinstance(bBox, Rect): coreBBox = Detection(bBox.coreRectF, 1.0) else: coreBBox = bBox.coreEstimation.detection self._validateReDetectInput(image.coreImage, coreBBox) if asyncEstimate: task = self._detector.asyncRedetectOne( image.coreImage, coreBBox, self._getDetectionType(detect5Landmarks, detect68Landmarks)) return AsyncTask(task, partial(postProcessingRedetectOne, image=image)) error, detectRes = self._detector.redetectOne( image.coreImage, coreBBox, self._getDetectionType(detect5Landmarks, detect68Landmarks)) return postProcessingRedetectOne(error, detectRes, image)