Skip to content

Commit 3cc2b73

Browse files
committed
new params in visualization
1 parent 04267c4 commit 3cc2b73

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ Possible arguments of the ```visualize_results``` function:
172172
| random_object_colors | bool | False | If true, colors for each object are selected randomly. |
173173
| show_confidences | bool | False | If true and show_class=True, confidences near class are visualized. |
174174
| axis_off | bool | True | If true, axis is turned off in the final visualization. |
175-
| show_classes_list | list | [] | If empty, visualize all classes. Otherwise, visualize only classes in the list. |
175+
| show_classes_list | list | [] | If empty, visualize all classes. Otherwise, visualize only classes in the list. |
176+
| list_of_class_colors | list | None | A list of tuples representing the colors for each class in BGR format. If provided, these colors will be used for displaying the classes instead of random colors. |
176177
| return_image_array | bool | False | If True, the function returns the image (BGR np.array) instead of displaying it. |
177178

178179

patched_yolo_infer/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ The library also provides a sleek customization of the visualization of the infe
77
**Model Support**: The library offers support for multiple ultralytics deep learning [models](https://docs.ultralytics.com/models/), such as YOLOv8, YOLOv8-seg, YOLOv9, YOLOv9-seg, YOLOv10, FastSAM, and RTDETR. Users can select from pre-trained options or utilize custom-trained models to best meet their task requirements.
88

99

10+
__Explanation of how Patch-Based-Inference works:__
11+
12+
<p align="center">
13+
<img width="600" alt="patched_inf_explanation" src="https://github.com/Koldim2001/YOLO-Patch-Based-Inference/blob/main/readme_content/patched_inf_explanation.gif?raw=true">
14+
</p>
15+
1016
## Installation
1117
You can install the library via pip:
1218

@@ -141,6 +147,7 @@ Visualizes custom results of object detection or segmentation on an image.
141147
- **show_confidences** (*bool*): If true and show_class=True, confidences near class are visualized. Default is False.
142148
- **axis_off** (*bool*): If true, axis is turned off in the final visualization. Default is True.
143149
- **show_classes_list** (*list*): If empty, visualize all classes. Otherwise, visualize only classes in the list.
150+
- **list_of_class_colors** (*list*) A list of tuples representing the colors for each class in BGR format. If provided, these colors will be used for displaying the classes instead of random colors.
144151
- **return_image_array** (*bool*): If True, the function returns the image (BGR np.array) instead of displaying it. Default is False.
145152

146153

patched_yolo_infer/functions_extra.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def visualize_results_usual_yolo_inference(
2727
show_confidences=False,
2828
axis_off=True,
2929
show_classes_list=[],
30+
list_of_class_colors=None,
3031
return_image_array=False,
3132
inference_extra_args=None,
3233
):
@@ -44,8 +45,8 @@ def visualize_results_usual_yolo_inference(
4445
show_class (bool): Whether to show class labels. Default is True.
4546
fill_mask (bool): Whether to fill the segmented regions with color. Default is False.
4647
alpha (float): The transparency of filled masks. Default is 0.3.
47-
color_class_background (tuple): The background bgr color for class labels. Default is (0, 0, 255) (red).
48-
color_class_text (tuple): The text color for class labels. Default is (255, 255, 255) (white).
48+
color_class_background (tuple): The background BGR color for class labels. Default is (0, 0, 255) (red).
49+
color_class_text (tuple): The text BGR color for class labels. Default is (255, 255, 255) (white).
4950
thickness (int): The thickness of bounding box and text. Default is 4.
5051
font: The font type for class labels. Default is cv2.FONT_HERSHEY_SIMPLEX.
5152
font_scale (float): The scale factor for font size. Default is 1.5.
@@ -56,6 +57,9 @@ def visualize_results_usual_yolo_inference(
5657
axis_off (bool): If True, axis is turned off in the final visualization.
5758
show_classes_list (list): If empty, visualize all classes. Otherwise, visualize only classes in the list.
5859
inference_extra_args (dict/None): Dictionary with extra ultralytics inference parameters.
60+
list_of_class_colors (list/None): A list of tuples representing the colors for each class in BGR format. If provided,
61+
these colors will be used for displaying the classes instead of random colors. The number of tuples
62+
in the list must match the number of possible classes in the network.
5963
return_image_array (bool): If True, the function returns the image bgr array instead of displaying it.
6064
Default is False.
6165
@@ -278,6 +282,7 @@ def visualize_results(
278282
show_confidences=False,
279283
axis_off=True,
280284
show_classes_list=[],
285+
list_of_class_colors=None,
281286
return_image_array=False
282287
):
283288
"""
@@ -295,8 +300,8 @@ def visualize_results(
295300
show_class (bool): Whether to show class labels. Default is True.
296301
fill_mask (bool): Whether to fill the segmented regions with color. Default is False.
297302
alpha (float): The transparency of filled masks. Default is 0.3.
298-
color_class_background (tuple): The background bgr color for class labels. Default is (0, 0, 255) (red).
299-
color_class_text (tuple): The text color for class labels. Default is (255, 255, 255) (white).
303+
color_class_background (tuple): The background BGR color for class labels. Default is (0, 0, 255) (red).
304+
color_class_text (tuple): The text BGR color for class labels. Default is (255, 255, 255) (white).
300305
thickness (int): The thickness of bounding box and text. Default is 4.
301306
font: The font type for class labels. Default is cv2.FONT_HERSHEY_SIMPLEX.
302307
font_scale (float): The scale factor for font size. Default is 1.5.
@@ -306,8 +311,10 @@ def visualize_results(
306311
show_confidences (bool): If true and show_class=True, confidences near class are visualized. Default is False.
307312
axis_off (bool): If true, axis is turned off in the final visualization. Default is True.
308313
show_classes_list (list): If empty, visualize all classes. Otherwise, visualize only classes in the list.
309-
return_image_array (bool): If True, the function returns the image bgr array instead of displaying it.
310-
Default is False.
314+
list_of_class_colors (list/None): A list of tuples representing the colors for each class in BGR format. If provided,
315+
these colors will be used for displaying the classes instead of random colors. The number of tuples
316+
in the list must match the number of possible classes in the network.
317+
return_image_array (bool): If True, the function returns the image bgr array instead of displaying it. Default is False.
311318
312319
Returns:
313320
None/np.array

0 commit comments

Comments
 (0)