DetectionProcessor
class¶
DetectionProcessor
¶
A class for processing detection results and transforming them using available utility methods. This class takes the output from an object detection model (e.g., YOLOv8) and provides functionality to separate, process, and visualize detected color checker cards and their patches.
Source code in color_correction/processor/detection.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 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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
Functions¶
get_each_class_box
staticmethod
¶
Separates detection boxes into card boxes and patch boxes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prediction
|
DetectionResult
|
The detection output that includes bounding boxes and class IDs. |
required |
Returns:
Type | Description |
---|---|
tuple[list[BoundingBox], list[BoundingBox]]
|
A tuple containing:
|
Source code in color_correction/processor/detection.py
print_summary
staticmethod
¶
Prints a summary of the detected cards and patches.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prediction
|
DetectionResult
|
The detection result to summarize. |
required |
Source code in color_correction/processor/detection.py
process_patches
staticmethod
¶
process_patches(input_image: ImageBGR, ordered_patches: list[tuple[BoundingBox, tuple[int, int]] | None]) -> tuple[list[ColorPatchType], ImageBGR]
Processes each detected patch by extracting its region from the image, computing its mean BGR color, and building a visualization grid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_image
|
ImageBGR
|
The original image containing detected patches. |
required |
ordered_patches
|
list[tuple[BoundingBox, tuple[int, int]] | None]
|
The list of ordered patch coordinates paired with their center points, possibly with missing entries as None. |
required |
Returns:
Type | Description |
---|---|
tuple[list[ColorPatchType], ImageBGR]
|
a tuple containing:
|
Source code in color_correction/processor/detection.py
extract_color_patches
staticmethod
¶
extract_color_patches(input_image: ImageBGR, prediction: DetectionResult, draw_processed_image: bool = False) -> tuple[list[ColorPatchType], ImageBGR, ImageBGR | None]
Extracts and processes color patches from detected color checker cards, transforming the detection results with available methods.
The method first separates detected cards and patches, generates an expected patch grid, and then matches the detected patches with this grid. If patches are missing, it attempts to auto-fill them with suggested coordinates. Finally, it computes the mean color for each patch and builds a visualization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_image
|
ImageBGR
|
The original image containing the color checker card. |
required |
prediction
|
DetectionResult
|
The detection result output from the model. |
required |
draw_processed_image
|
bool
|
If True, returns an additional image with visualized detections. Otherwise, only patch processing is performed. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
tuple[list[ColorPatchType], ImageBGR, ImageBGR | None]
|
a tuple containing:
|
Raises:
Type | Description |
---|---|
ValueError
|
If no cards or patches are detected. |
Source code in color_correction/processor/detection.py
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 220 |
|
draw_preprocess
staticmethod
¶
draw_preprocess(image: ImageBGR, expected_boxes: list[BoundingBox], prediction: DetectionResult, ls_ordered_patch_bbox: list[BoundingBox | None], suggested_patches: dict[int, BoundingBox] | None = None) -> ImageBGR
Draws visualizations on the input image to compare the detected patches with the expected positions. It overlays expected boxes, connects detected patches to their corresponding expected boxes, and highlights individual patch detections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
ImageBGR
|
The original image to draw on. |
required |
expected_boxes
|
list[BoundingBox]
|
List of expected bounding boxes for patches. |
required |
prediction
|
DetectionResult
|
The detection results containing predicted bounding boxes. |
required |
ls_ordered_patch_bbox
|
list[BoundingBox | None]
|
The list of ordered patch bounding boxes. |
required |
suggested_patches
|
dict[int, BoundingBox]
|
Dictionary of suggested patch coordinates for missing patches. |
None
|
Returns:
Type | Description |
---|---|
ImageBGR
|
The image with drawn detection and patch visualizations. |
Source code in color_correction/processor/detection.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|