def createHumanDetection(image: VLImage, detection: Detection, landmarks17: Optional[CoreLandmarks17]): """ Create human detection structure from core detection result. Args: image: origin image detection: sdk human detection landmarks17: estimated landsmarks17 Returns: HumanDetection structure """ human = Human() human.img = image.coreImage human.detection = detection if landmarks17: human.landmarks17_opt.set(landmarks17) return HumanDetection(human, image)
def detectOne( self, image: VLImage, detectArea: Optional[Rect] = None, limit: int = 5, detectLandmarks: bool = True ) -> Union[None, HumanDetection]: """ Detect just one best detection on the image. Args: image: image. Format must be R8G8B8 detectArea: rectangle area which contains human to detect. If not set will be set image.rect limit: max number of detections for input image detectLandmarks: detect or not landmarks Returns: human detection if human is found otherwise None Raises: LunaSDKException: if detectOne is failed or image format has wrong the format """ assertImageForDetection(image) detectionType = self._getDetectionType(detectLandmarks) if detectArea is None: forDetection = ImageForDetection(image=image, detectArea=image.rect) else: forDetection = ImageForDetection(image=image, detectArea=detectArea) imgs, detectAreas = getArgsForCoreDetectorForImages([forDetection]) error, detectRes = self._detector.detect(imgs, detectAreas, limit, detectionType) assertError(error) detections = detectRes.getDetections(0) landmarks17Array = detectRes.getLandmarks17(0) isReplyNotAssumesDetection = detectRes.getSize() == 1 if isReplyNotAssumesDetection: isDetectionExistsNValid = len(detections) != 0 and detections[0].isValid() if not isDetectionExistsNValid: return None human = Human() human.img = image.coreImage human.detection = detections[0] if landmarks17Array and landmarks17Array[0] is not None: human.landmarks17_opt.set(landmarks17Array[0]) return HumanDetection(human, image)
def detect( self, images: List[Union[VLImage, ImageForDetection]], limit: int = 5, detectLandmarks: bool = True ) -> List[List[HumanDetection]]: """ Batch detect human bodies on images. Args: images: input images list. Format must be R8G8B8 limit: max number of detections per input image detectLandmarks: detect or not landmarks Returns: return list of lists detection, order of detection lists is corresponding to order input images """ coreImages, detectAreas = getArgsForCoreDetectorForImages(images) detectionType = self._getDetectionType(detectLandmarks) validateBatchDetectInput(self._detector, coreImages, detectAreas) error, fsdkDetectRes = self._detector.detect(coreImages, detectAreas, limit, detectionType) assertError(error) res = [] for imageIdx in range(fsdkDetectRes.getSize()): imagesDetections = [] detections = fsdkDetectRes.getDetections(imageIdx) landmarks17Array = fsdkDetectRes.getLandmarks17(imageIdx) for idx, detection in enumerate(detections): human = Human() human.img = coreImages[imageIdx] human.detection = detection if detectLandmarks: human.landmarks17_opt.set(landmarks17Array[idx]) imagesDetections.append(human) image = images[imageIdx] vlImage = image if isinstance(image, VLImage) else image.image res.append([HumanDetection(human, vlImage) for human in imagesDetections]) return res
def _createCoreHumans(image: ImageForRedetection) -> List[Human]: """ Create core humans for redetection Args: image: image and bounding boxes for redetection Returns: Human object list. one object for one bbox """ humans = [Human() for _ in range(len(image.bBoxes))] for index, human in enumerate(humans): human.img = image.image.coreImage human.detection.rect = image.bBoxes[index].coreRectF human.detection.score = 1 return humans