IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
painter.py
Go to the documentation of this file.
1from typing import Union
2
3from ids_peak_icv.exceptions import NotSupportedException
4from ids_peak_icv.painting.color import Color, ColorConstant, ColorPalette, ColorPaletteConstant
5from ids_peak_icv.painting.drawable import IDrawable
6from ids_peak_icv.painting.drawing_options import DrawingOptions
7from ids_peak_icv.painting.opacity import Opacity
8from ids_peak_icv.datatypes.image import Image, _check_and_get_icv_image
9from ids_peak_ipl import ids_peak_ipl
10
11
12class Painter:
13 """!
14 @brief
15 Class for painting simple things (e.g. a region) on images.
16
17 With the Painter, objects derived from IDrawable can be drawn in order to visualize them.
18 It is possible to configure the drawing style, including color and opacity settings, for customized results.
19
20 The Painter is initialized with the image onto which the object is to be painted. It must be of type RGB8, BGR8,
21 RGBa8 or BGRa8.
22 Optionally, you can configure the painter by setting the color and opacity; if omitted, default values from
23 DrawingOptions are used.
24 Once configured, the object to be rendered can be passed to the draw method, which paints it onto the image.
25 ::
26 painter = Painter(image)
27 painter.color = ColorConstant.BLUE
28 painter.opacity = Opacity(50)
29 painter.draw(region)
30
31 @ingroup ids_peak_icv_python_painting
32 @since ids_peak_icv 1.1
33 """
34
35 def __init__(self, image: Union[Image, ids_peak_ipl.Image]) -> None:
36 """!
37 @brief
38 Creates a Painter object.
39
40 @param image: The image all painting operations are performed on.
41
42 @since ids_peak_icv 1.1
43 """
44 self._image = _check_and_get_icv_image(image)
46
47 @property
48 def color(self) -> Color:
49 """!
50 @brief
51 Get the current color for painting.
52
53 @return Color: The current color.
54
55 @since ids_peak_icv 1.1
56 """
57 return self._drawing_options.color
58
59 @color.setter
60 def color(self, color: Union[Color, ColorConstant, ColorPalette, ColorPaletteConstant]) -> None:
61 """!
62 @brief
63 Set the color for painting an object into the image.
64
65 If the draw method is called several times, there are two options:
66 - the same color is used for each call,
67 - the color changes with each call.
68
69 For the first option a Color or a ColorConstant must be passed, for the second a ColorPalette or a
70 ColorPaletteConstant.
71
72 @param color: The color to set.
73
74 @exception NotSupportedException: If color is not a Color or ColorConstant.
75
76 @since ids_peak_icv 1.1
77 """
78 num_bits_per_pixel = self._image._pixel_format.storage_bits_per_channel
79 if isinstance(color, ColorConstant):
80 self._drawing_options.color = Color.create_from_constant(color, num_bits_per_pixel)
81 elif isinstance(color, ColorPaletteConstant):
82 self._drawing_options.color = ColorPalette.create_from_palette_constant(color, num_bits_per_pixel)
83 elif isinstance(color, Color) or isinstance(color, ColorPalette):
84 self._drawing_options.color = color
85 else:
86 raise NotSupportedException("Invalid variable given. ColorConstant or Color expected.")
87
88 @property
89 def opacity(self) -> Opacity:
90 """!
91 @brief
92 Get the current opacity for painting.
93
94 @return Opacity: The current opacity.
95
96 @since ids_peak_icv 1.1
97 """
98 return self._drawing_options.opacity
99
100 @opacity.setter
101 def opacity(self, opacity: Opacity) -> None:
102 """!
103 @brief
104 Set the Opacity for painting.
105
106 @param opacity: The opacity to set.
107
108 @since ids_peak_icv 1.1
109 """
110 self._drawing_options.opacity = opacity
111
112 def draw(self, drawable: IDrawable) -> None:
113 """!
114 @brief
115 Draws the ``drawable`` onto the image, the painter was initialized with.
116
117 For more info, please see the documentation of the specific object that shall be drawn.
118
119 The following objects can be drawn:
120 - Region
121
122 @param drawable: The object to be drawn.
123
124 @since ids_peak_icv 1.1
125 """
126 drawable._draw(self._image, self._drawing_options)
Occurs when a requested operation is not implemented or supported (e.g., exporting to an unsupported ...
Definition exceptions.py:60
Class for painting simple things (e.g.
Definition painter.py:12
None draw(self, IDrawable drawable)
Draws the drawable onto the image, the painter was initialized with.
Definition painter.py:112
None __init__(self, Union[Image, ids_peak_ipl.Image] image)
Creates a Painter object.
Definition painter.py:35