@@ -26,7 +26,8 @@ def visualize_results_usual_yolo_inference(
26
26
random_object_colors = False ,
27
27
show_confidences = False ,
28
28
axis_off = True ,
29
- show_classes_list = []
29
+ show_classes_list = [],
30
+ return_image_array = False
30
31
):
31
32
"""
32
33
Visualizes the results of usual YOLOv8 or YOLOv8-seg inference on an image
@@ -53,6 +54,8 @@ def visualize_results_usual_yolo_inference(
53
54
show_confidences (bool): If True and show_class=True, confidences near class are visualized.
54
55
axis_off (bool): If True, axis is turned off in the final visualization.
55
56
show_classes_list (list): If empty, visualize all classes. Otherwise, visualize only classes in the list.
57
+ return_image_array (bool): If True, the function returns the image bgr array instead of displaying it.
58
+ Default is False.
56
59
57
60
Returns:
58
61
None
@@ -153,6 +156,9 @@ def visualize_results_usual_yolo_inference(
153
156
thickness = thickness ,
154
157
)
155
158
159
+ if return_image_array :
160
+ return labeled_image
161
+ else :
156
162
# Display the final image with overlaid masks and labels
157
163
plt .figure (figsize = (8 , 8 ), dpi = dpi )
158
164
labeled_image = cv2 .cvtColor (labeled_image , cv2 .COLOR_BGR2RGB )
@@ -273,7 +279,8 @@ def visualize_results(
273
279
random_object_colors = False ,
274
280
show_confidences = False ,
275
281
axis_off = True ,
276
- show_classes_list = []
282
+ show_classes_list = [],
283
+ return_image_array = False
277
284
):
278
285
"""
279
286
Visualizes custom results of object detection or segmentation on an image.
@@ -301,7 +308,9 @@ def visualize_results(
301
308
show_confidences (bool): If true and show_class=True, confidences near class are visualized. Default is False.
302
309
axis_off (bool): If true, axis is turned off in the final visualization. Default is True.
303
310
show_classes_list (list): If empty, visualize all classes. Otherwise, visualize only classes in the list.
304
-
311
+ return_image_array (bool): If True, the function returns the image bgr array instead of displaying it.
312
+ Default is False.
313
+
305
314
Returns:
306
315
None
307
316
"""
@@ -378,10 +387,13 @@ def visualize_results(
378
387
thickness = thickness ,
379
388
)
380
389
381
- # Display the final image with overlaid masks and labels
382
- plt .figure (figsize = (8 , 8 ), dpi = dpi )
383
- labeled_image = cv2 .cvtColor (labeled_image , cv2 .COLOR_BGR2RGB )
384
- plt .imshow (labeled_image )
385
- if axis_off :
386
- plt .axis ('off' )
387
- plt .show ()
390
+ if return_image_array :
391
+ return labeled_image
392
+ else :
393
+ # Display the final image with overlaid masks and labels
394
+ plt .figure (figsize = (8 , 8 ), dpi = dpi )
395
+ labeled_image = cv2 .cvtColor (labeled_image , cv2 .COLOR_BGR2RGB )
396
+ plt .imshow (labeled_image )
397
+ if axis_off :
398
+ plt .axis ('off' )
399
+ plt .show ()
0 commit comments