Coverage for backpack/annotation/panorama.py: 90%
21 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-30 23:12 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-30 23:12 +0000
1try:
2 import panoramasdk
3except ImportError as e:
4 raise ImportError(
5 'PanoramaMediaAnnotationDriver is supposed to be used only from a AWS Panorama SDK '
6 'application, either on a Panorama device or using the test_utility.'
7 ) from e
9from .driver import AnnotationDriverBase
11from .annotation import (
12 MarkerAnnotation, RectAnnotation, LabelAnnotation, LineAnnotation, PolyLineAnnotation
13)
15class PanoramaMediaAnnotationDriver(AnnotationDriverBase):
16 ''' Annotation driver implementation for Panorama media type images.
18 You should pass an ``panoramasdk.media`` instance as the context argument of the
19 :meth:`~backpack.annotation.AnnotationDriverBase.render()` method.
21 :class:`PanoramaMediaAnnotationDriver` currently does not support colors.
22 '''
24 MARKER_STYLE_TO_STR = {
25 MarkerAnnotation.Style.CROSS: '+',
26 MarkerAnnotation.Style.TILTED_CROSS: 'x',
27 MarkerAnnotation.Style.STAR: '*',
28 MarkerAnnotation.Style.DIAMOND: '<>',
29 MarkerAnnotation.Style.SQUARE: '||',
30 MarkerAnnotation.Style.TRIANGLE_UP: '/\\',
31 MarkerAnnotation.Style.TRIANGLE_DOWN: '\\/',
32 }
34 def add_rect(self, rect_anno: RectAnnotation, context: 'panoramasdk.media') -> None:
35 x1, y1 = rect_anno.rect.pt_min
36 x2, y2 = rect_anno.rect.pt_max
37 context.add_rect(float(x1), float(y1), float(x2), float(y2))
39 def add_label(self, label: LabelAnnotation, context: 'panoramasdk.media') -> None:
40 x, y = label.point
41 context.add_label(label.text, x, y)
43 def add_marker(self, marker: MarkerAnnotation, context: 'panoramasdk.media') -> None:
44 marker_str = PanoramaMediaAnnotationDriver.MARKER_STYLE_TO_STR.get(marker.style, '.')
45 x, y = marker.point
46 context.add_label(marker_str, x, y)
48 def add_line(self, label: LineAnnotation, context: 'panoramasdk.media') -> None:
49 print( # pragma: no cover
50 'WARNING: PanoramaMediaAnnotationDriver.add_line is not implemented'
51 )
53 def add_polyline(self, polyline: PolyLineAnnotation, context: 'panoramasdk.media') -> None:
54 print( # pragma: no cover
55 'WARNING: PanoramaMediaAnnotationDriver.add_line is not implemented'
56 )