6060from sleap_io .model .instance import Instance , PredictedInstance
6161from sleap .sleap_io_adaptors .instance_utils import fill_missing , node_points
6262from sleap .sleap_io_adaptors .video_utils import get_last_frame_idx
63- from sleap_io import Video
63+ from sleap_io import Video , LabeledFrame
6464from sleap .prefs import prefs
6565from sleap_io import Node
6666
@@ -484,7 +484,7 @@ def scene(self):
484484 """Returns `QGraphicsScene` for viewer."""
485485 return self .view .scene
486486
487- def addInstance (self , instance , ** kwargs ):
487+ def addInstance (self , instance , frame : Optional [ LabeledFrame ] = None , ** kwargs ):
488488 """Add a skeleton instance to the video.
489489
490490 Args:
@@ -494,7 +494,7 @@ def addInstance(self, instance, **kwargs):
494494 """
495495 # Check if instance is an Instance (or subclass of Instance)
496496 if issubclass (type (instance ), Instance ):
497- instance = QtInstance (instance = instance , player = self , ** kwargs )
497+ instance = QtInstance (instance = instance , frame = frame , player = self , ** kwargs )
498498 if type (instance ) != QtInstance :
499499 return
500500 if instance .instance .n_visible > 0 or not isinstance (
@@ -1415,6 +1415,7 @@ def __init__(
14151415 predicted = False ,
14161416 show_non_visible = True ,
14171417 callbacks = None ,
1418+ frame : Optional [LabeledFrame ] = None ,
14181419 * args ,
14191420 ** kwargs ,
14201421 ):
@@ -1425,7 +1426,7 @@ def __init__(
14251426 self .radius = radius
14261427 self .color_manager = self .player .color_manager
14271428 self .color = self .color_manager .get_item_color (
1428- self .node , self ._parent_instance .instance
1429+ self .node , self ._parent_instance .instance , frame = frame
14291430 )
14301431 self .edges = []
14311432 self .name = node .name
@@ -1676,6 +1677,7 @@ def __init__(
16761677 src : QtNode ,
16771678 dst : QtNode ,
16781679 show_non_visible : bool = True ,
1680+ frame : Optional [LabeledFrame ] = None ,
16791681 * args ,
16801682 ** kwargs ,
16811683 ):
@@ -1702,7 +1704,9 @@ def __init__(
17021704 )
17031705
17041706 edge_pair = (src .node , dst .node )
1705- color = player .color_manager .get_item_color (edge_pair , parent .instance )
1707+ color = player .color_manager .get_item_color (
1708+ edge_pair , parent .instance , frame = frame
1709+ )
17061710 pen_width = player .color_manager .get_item_pen_width (edge_pair , parent .instance )
17071711 pen = QPen (QColor (* color ), pen_width )
17081712 pen .setCosmetic (True )
@@ -1834,6 +1838,7 @@ def __init__(
18341838 markerRadius = 4 ,
18351839 nodeLabelSize = 12 ,
18361840 show_non_visible = True ,
1841+ frame : Optional [LabeledFrame ] = None ,
18371842 * args ,
18381843 ** kwargs ,
18391844 ):
@@ -1844,7 +1849,7 @@ def __init__(
18441849 self .predicted = hasattr (instance , "score" )
18451850
18461851 color_manager = self .player .color_manager
1847- color = color_manager .get_item_color (self .instance )
1852+ color = color_manager .get_item_color (self .instance , frame = frame )
18481853
18491854 self .show_non_visible = show_non_visible
18501855 self .selectable = not self .predicted or color_manager .color_predicted
@@ -1875,7 +1880,9 @@ def __init__(
18751880 if self .predicted :
18761881 self .box = QGraphicsRectItem (parent = self )
18771882 else :
1878- self .box = VisibleBoundingBox (rect = self ._bounding_rect , parent = self )
1883+ self .box = VisibleBoundingBox (
1884+ rect = self ._bounding_rect , parent = self , frame = frame
1885+ )
18791886 box_pen_width = color_manager .get_item_pen_width (self .instance )
18801887 box_pen = QPen (QColor (* color ), box_pen_width )
18811888 box_pen .setStyle (Qt .DashLine )
@@ -1924,6 +1931,7 @@ def __init__(
19241931 predicted = self .predicted ,
19251932 radius = self .markerRadius ,
19261933 show_non_visible = self .show_non_visible ,
1934+ frame = frame ,
19271935 )
19281936
19291937 self .nodes [node .name ] = node_item
@@ -1938,6 +1946,7 @@ def __init__(
19381946 src = self .nodes [src ],
19391947 dst = self .nodes [dst ],
19401948 show_non_visible = self .show_non_visible ,
1949+ frame = frame ,
19411950 )
19421951 self .nodes [src ].edges .append (edge_item )
19431952 self .nodes [dst ].edges .append (edge_item )
@@ -2254,11 +2263,12 @@ def __init__(
22542263 parent : QtInstance ,
22552264 opacity : float = 0.8 ,
22562265 scaling_padding : float = 10.0 ,
2266+ frame : Optional [LabeledFrame ] = None ,
22572267 ):
22582268 super ().__init__ (rect , parent )
22592269 self .box_width = parent .markerRadius
22602270 color_manager = parent .player .color_manager
2261- int_color = color_manager .get_item_color (parent .instance )
2271+ int_color = color_manager .get_item_color (parent .instance , frame = frame )
22622272 self .int_color = QColor (* int_color )
22632273 self .corner_opacity = opacity
22642274 self .scaling_padding = scaling_padding
@@ -2512,6 +2522,7 @@ def plot_instances(scene, frame_idx, labels, video=None, fixed=True):
25122522 color = color_manager .get_track_color (pseudo_track ),
25132523 predicted = fixed ,
25142524 color_predicted = True ,
2525+ frame = labeled_frame ,
25152526 show_non_visible = False ,
25162527 )
25172528 inst .showLabels (False )
0 commit comments