@@ -467,3 +467,164 @@ def test_resolve_labels_returns_expected(
467467 def test_resolve_labels_raises (self , labels , points_count , class_id , match ):
468468 with pytest .raises (ValueError , match = match ):
469469 sv .VertexLabelAnnotator ._resolve_labels (labels , points_count , class_id )
470+
471+
472+ class TestVertexAnnotatorColorLookup :
473+ """Verify VertexAnnotator respects each ColorLookup strategy with a ColorPalette."""
474+
475+ @pytest .fixture
476+ def key_points_with_class (self ) -> sv .KeyPoints :
477+ """Two-instance, three-keypoint set with class_id set."""
478+ return sv .KeyPoints (
479+ xy = np .array (
480+ [
481+ [[20.0 , 20.0 ], [40.0 , 40.0 ], [60.0 , 60.0 ]],
482+ [[25.0 , 25.0 ], [45.0 , 45.0 ], [65.0 , 65.0 ]],
483+ ],
484+ dtype = np .float32 ,
485+ ),
486+ class_id = np .array ([0 , 1 ], dtype = int ),
487+ )
488+
489+ @pytest .mark .parametrize (
490+ "color_lookup" ,
491+ [
492+ pytest .param (sv .ColorLookup .INDEX , id = "index" ),
493+ pytest .param (sv .ColorLookup .CLASS , id = "class" ),
494+ pytest .param (sv .ColorLookup .KEYPOINT , id = "keypoint" ),
495+ ],
496+ )
497+ def test_annotate_with_color_palette_returns_ndarray (
498+ self , scene , key_points_with_class , color_lookup
499+ ):
500+ """ColorPalette + each ColorLookup produces a modified ndarray output."""
501+ annotator = sv .VertexAnnotator (
502+ color = sv .ColorPalette .DEFAULT ,
503+ radius = 5 ,
504+ color_lookup = color_lookup ,
505+ )
506+ result = annotator .annotate (
507+ scene = scene .copy (), key_points = key_points_with_class
508+ )
509+
510+ assert isinstance (result , np .ndarray )
511+ assert result .shape == scene .shape
512+ assert not np .array_equal (result , scene )
513+
514+ def test_annotate_class_lookup_raises_when_class_id_none (self , scene ):
515+ """CLASS strategy raises ValueError when key_points.class_id is None."""
516+ key_points = sv .KeyPoints (
517+ xy = np .array ([[[30.0 , 30.0 ], [50.0 , 50.0 ]]], dtype = np .float32 ),
518+ )
519+ annotator = sv .VertexAnnotator (
520+ color = sv .ColorPalette .DEFAULT ,
521+ color_lookup = sv .ColorLookup .CLASS ,
522+ )
523+
524+ with pytest .raises (ValueError , match = "class_id" ):
525+ annotator .annotate (scene = scene .copy (), key_points = key_points )
526+
527+
528+ class TestEdgeAnnotatorColorLookup :
529+ """Verify EdgeAnnotator respects each ColorLookup strategy with a ColorPalette."""
530+
531+ @pytest .fixture
532+ def key_points_triangle (self ) -> sv .KeyPoints :
533+ """Single-instance, three-vertex triangle useful with explicit edges."""
534+ return sv .KeyPoints (
535+ xy = np .array (
536+ [[[10.0 , 10.0 ], [80.0 , 10.0 ], [45.0 , 80.0 ]]],
537+ dtype = np .float32 ,
538+ ),
539+ class_id = np .array ([0 ], dtype = int ),
540+ )
541+
542+ @pytest .mark .parametrize (
543+ "color_lookup" ,
544+ [
545+ pytest .param (sv .ColorLookup .INDEX , id = "index" ),
546+ pytest .param (sv .ColorLookup .CLASS , id = "class" ),
547+ pytest .param (sv .ColorLookup .KEYPOINT , id = "keypoint" ),
548+ ],
549+ )
550+ def test_annotate_with_color_palette_returns_ndarray (
551+ self , scene , key_points_triangle , color_lookup
552+ ):
553+ """ColorPalette + each ColorLookup produces a modified ndarray output."""
554+ annotator = sv .EdgeAnnotator (
555+ color = sv .ColorPalette .DEFAULT ,
556+ thickness = 2 ,
557+ edges = [(1 , 2 ), (2 , 3 ), (1 , 3 )],
558+ color_lookup = color_lookup ,
559+ )
560+ result = annotator .annotate (scene = scene .copy (), key_points = key_points_triangle )
561+
562+ assert isinstance (result , np .ndarray )
563+ assert result .shape == scene .shape
564+ assert not np .array_equal (result , scene )
565+
566+ def test_annotate_class_lookup_raises_when_class_id_none (self , scene ):
567+ """CLASS strategy raises ValueError when key_points.class_id is None."""
568+ key_points = sv .KeyPoints (
569+ xy = np .array ([[[10.0 , 10.0 ], [80.0 , 10.0 ]]], dtype = np .float32 ),
570+ )
571+ annotator = sv .EdgeAnnotator (
572+ color = sv .ColorPalette .DEFAULT ,
573+ edges = [(1 , 2 )],
574+ color_lookup = sv .ColorLookup .CLASS ,
575+ )
576+
577+ with pytest .raises (ValueError , match = "class_id" ):
578+ annotator .annotate (scene = scene .copy (), key_points = key_points )
579+
580+
581+ class TestVertexLabelAnnotatorColorLookup :
582+ """Verify VertexLabelAnnotator respects each ColorLookup strategy."""
583+
584+ @pytest .fixture
585+ def key_points_with_class (self ) -> sv .KeyPoints :
586+ """Two-instance, two-keypoint set with class_id set."""
587+ return sv .KeyPoints (
588+ xy = np .array (
589+ [[[20.0 , 20.0 ], [60.0 , 60.0 ]], [[25.0 , 25.0 ], [65.0 , 65.0 ]]],
590+ dtype = np .float32 ,
591+ ),
592+ class_id = np .array ([0 , 1 ], dtype = int ),
593+ )
594+
595+ @pytest .mark .parametrize (
596+ "color_lookup" ,
597+ [
598+ pytest .param (sv .ColorLookup .INDEX , id = "index" ),
599+ pytest .param (sv .ColorLookup .CLASS , id = "class" ),
600+ pytest .param (sv .ColorLookup .KEYPOINT , id = "keypoint" ),
601+ ],
602+ )
603+ def test_annotate_with_color_palette_returns_ndarray (
604+ self , scene , key_points_with_class , color_lookup
605+ ):
606+ """ColorPalette + each ColorLookup produces a modified ndarray output."""
607+ annotator = sv .VertexLabelAnnotator (
608+ color = sv .ColorPalette .DEFAULT ,
609+ color_lookup = color_lookup ,
610+ )
611+ result = annotator .annotate (
612+ scene = scene .copy (), key_points = key_points_with_class
613+ )
614+
615+ assert isinstance (result , np .ndarray )
616+ assert result .shape == scene .shape
617+ assert not np .array_equal (result , scene )
618+
619+ def test_annotate_class_lookup_raises_when_class_id_none (self , scene ):
620+ """CLASS strategy raises ValueError when key_points.class_id is None."""
621+ key_points = sv .KeyPoints (
622+ xy = np .array ([[[30.0 , 30.0 ], [50.0 , 50.0 ]]], dtype = np .float32 ),
623+ )
624+ annotator = sv .VertexLabelAnnotator (
625+ color = sv .ColorPalette .DEFAULT ,
626+ color_lookup = sv .ColorLookup .CLASS ,
627+ )
628+
629+ with pytest .raises (ValueError , match = "class_id" ):
630+ annotator .annotate (scene = scene .copy (), key_points = key_points )
0 commit comments