Ejemplo n.º 1
0
    def to_detection(self, frame_size):
        """Returns a :class:`fiftyone.core.labels.Detection` representation of
        the box.

        Args:
            frame_size: the ``(width, height)`` of the video frames

        Returns:
            a :class:`fiftyone.core.labels.Detection`
        """
        label = self.label

        width, height = frame_size
        bounding_box = [
            self.xtl / width,
            self.ytl / height,
            (self.xbr - self.xtl) / width,
            (self.ybr - self.ytl) / height,
        ]

        attributes = {a.name: a.to_attribute() for a in self.attributes}

        if self.outside is not None:
            attributes["outside"] = fol.BooleanAttribute(value=self.outside)

        if self.occluded is not None:
            attributes["occluded"] = fol.BooleanAttribute(value=self.occluded)

        if self.keyframe is not None:
            attributes["keyframe"] = fol.BooleanAttribute(value=self.keyframe)

        return fol.Detection(
            label=label, bounding_box=bounding_box, attributes=attributes,
        )
Ejemplo n.º 2
0
    def _parse_attribute(self, value):
        if etau.is_str(value):
            return fol.CategoricalAttribute(value=value)

        if isinstance(value, bool):
            return fol.BooleanAttribute(value=value)

        if etau.is_numeric(value):
            return fol.NumericAttribute(value=value)

        return fol.Attribute(value=value)
Ejemplo n.º 3
0
    def to_attribute(self):
        """Returns a :class:`fiftyone.core.labels.Attribute` representation of
        the attribute.

        Returns:
            a :class:`fiftyone.core.labels.Attribute`
        """
        if isinstance(self.value, bool):
            return fol.BooleanAttribute(value=self.value)

        if etau.is_numeric(self.value):
            return fol.NumericAttribute(value=self.value)

        return fol.CategoricalAttribute(value=self.value)