Plot Module
Plot
Class for plotting detections on images.
Source code in devices\raspberry_pi_5\src\plot\__init__.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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
denormalize_and_remove_padding(box, size, padding_length, input_height, input_width)
staticmethod
Denormalize bounding box coordinates and remove padding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
box
|
List
|
Normalized bounding box coordinates. |
required |
size
|
int
|
Size to scale the coordinates. |
required |
padding_length
|
int
|
Length of padding to remove. |
required |
input_height
|
int
|
Height of the input image. |
required |
input_width
|
int
|
Width of the input image. |
required |
Returns:
List: Denormalized bounding box coordinates with padding removed.
Source code in devices\raspberry_pi_5\src\plot\__init__.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
display_detections(class_names, preprocessed_image, image_bounding_boxes, draw_labels_name=False, font=FONT, font_x_diff=0, font_y_diff=-10, font_scale=0.9, thickness=2, rgb_colors=None)
staticmethod
Function to display the preprocessed image and the image with detections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_names
|
Dict[int, str]
|
Dictionary mapping class numbers to class names. |
required |
preprocessed_image
|
List[ndarray]
|
Preprocessed image in CHW format. |
required |
image_bounding_boxes
|
ImageBoundingBoxes
|
Object containing bounding boxes, classes, and scores. |
required |
draw_labels_name
|
bool
|
Whether to draw class names instead of class numbers. Defaults to False. |
False
|
font
|
int
|
Font type for text. Defaults to FONT. |
FONT
|
font_x_diff
|
int
|
Horizontal offset for text placement. Defaults to 0. |
0
|
font_y_diff
|
int
|
Vertical offset for text placement. Defaults to -10. |
-10
|
font_scale
|
float
|
Scale factor for text size. Defaults to 0.9. |
0.9
|
thickness
|
int
|
Thickness of bounding box and text. Defaults to 2. |
2
|
rgb_colors
|
tuple[tuple[int, int, int]]
|
Tuple mapping class indices to RGB colors. Defaults to None. |
None
|
Returns:
None: Displays the preprocessed image and the image with detections using matplotlib.
Source code in devices\raspberry_pi_5\src\plot\__init__.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
draw_detection(image, box, class_name, score, color, scale_factor)
staticmethod
Draw box and label for one detection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
ndarray
|
Image to draw on. |
required |
box
|
List
|
Bounding box coordinates. |
required |
class_name
|
str
|
Class label of the detection. |
required |
score
|
float
|
Detection score. |
required |
color
|
tuple
|
Color for the bounding box. |
required |
scale_factor
|
float
|
Scale factor for coordinates. |
required |
Source code in devices\raspberry_pi_5\src\plot\__init__.py
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 |
|
draw_detections(colors, image_bounding_boxes, image, min_score=0.45, scale_factor=1)
classmethod
Draw detections on the image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
colors
|
Dict[int, tuple[int, int, int]
|
Dictionary mapping class names to RGB colors. |
required |
image_bounding_boxes
|
ImageBoundingBoxes
|
Object containing bounding boxes, classes, and scores. |
required |
image
|
ndarray
|
Image to draw on. |
required |
min_score
|
float
|
Minimum score threshold. Defaults to 0.45. |
0.45
|
scale_factor
|
float
|
Scale factor for coordinates. Defaults to 1. |
1
|
Returns:
np.ndarray: Image with detections drawn.
Source code in devices\raspberry_pi_5\src\plot\__init__.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|