Skip to content

instance

sleap.gui.overlays.instance

Overlay for showing instances.

Classes:

Name Description
InstanceOverlay

Class for adding instances as overlays on video frames.

InstanceOverlay

Bases: BaseOverlay

Class for adding instances as overlays on video frames.

Mostly this overlay just adds the relevant instances to the player (i.e., QtVideoPlayer) which does the actual drawing.

Attributes:

Name Type Description
labels Labels | None

The :class:Labels dataset from which to get overlay data.

player QtVideoPlayer | None

The video player in which to show overlay.

state GuiState

Object used to communicate with application.

Methods:

Name Description
add_to_scene

Adds overlay for frame to player scene.

Source code in sleap/gui/overlays/instance.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
@attr.s(auto_attribs=True)
class InstanceOverlay(BaseOverlay):
    """Class for adding instances as overlays on video frames.

    Mostly this overlay just adds the relevant instances to the player (i.e.,
    `QtVideoPlayer`) which does the actual drawing.

    Attributes:
        labels: The :class:`Labels` dataset from which to get overlay data.
        player: The video player in which to show overlay.
        state: Object used to communicate with application.
    """

    state: GuiState = None

    def __attrs_post_init__(self):
        if self.state is None:
            raise ValueError(
                "InstanceOverlay initialized without application GuiState."
            )

    def add_to_scene(self, video, frame_idx):
        """Adds overlay for frame to player scene."""
        if self.labels is None:
            return

        lf = self.labels.find(video, frame_idx, return_new=True)[0]

        instances = get_instances_to_show(lf)

        has_predicted = any((True for inst in instances if hasattr(inst, "score")))
        has_user = any((True for inst in instances if not hasattr(inst, "score")))

        for instance in instances:
            self.player.addInstance(
                instance=instance,
                markerRadius=self.state.get("marker size", 4),
                nodeLabelSize=self.state.get("node label size", 12),
                show_non_visible=self.state.get("show non-visible nodes", default=True),
            )

        self.player.showInstances(self.state.get("show instances", default=True))
        self.player.showLabels(self.state.get("show labels", default=True))
        self.player.showEdges(self.state.get("show edges", default=True))

        if has_user and has_predicted:
            self.player.highlightPredictions("not in training data")

add_to_scene(video, frame_idx)

Adds overlay for frame to player scene.

Source code in sleap/gui/overlays/instance.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def add_to_scene(self, video, frame_idx):
    """Adds overlay for frame to player scene."""
    if self.labels is None:
        return

    lf = self.labels.find(video, frame_idx, return_new=True)[0]

    instances = get_instances_to_show(lf)

    has_predicted = any((True for inst in instances if hasattr(inst, "score")))
    has_user = any((True for inst in instances if not hasattr(inst, "score")))

    for instance in instances:
        self.player.addInstance(
            instance=instance,
            markerRadius=self.state.get("marker size", 4),
            nodeLabelSize=self.state.get("node label size", 12),
            show_non_visible=self.state.get("show non-visible nodes", default=True),
        )

    self.player.showInstances(self.state.get("show instances", default=True))
    self.player.showLabels(self.state.get("show labels", default=True))
    self.player.showEdges(self.state.get("show edges", default=True))

    if has_user and has_predicted:
        self.player.highlightPredictions("not in training data")