-
Notifications
You must be signed in to change notification settings - Fork 37
fixed detect target image not showing #255
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| import time | ||
|
|
||
| import cv2 | ||
| import torch | ||
| import ultralytics | ||
|
|
||
| from . import base_detect_target | ||
|
|
@@ -18,6 +19,8 @@ class DetectTargetUltralyticsConfig: | |
| Configuration for DetectTargetUltralytics. | ||
| """ | ||
|
|
||
| CPU_DEVICE = "cpu" | ||
|
|
||
| def __init__( | ||
| self, | ||
| device: "str | int", | ||
|
|
@@ -55,13 +58,19 @@ def __init__( | |
| show_annotations: Display annotated images. | ||
| save_name: filename prefix for logging detections and annotated images. | ||
| """ | ||
| self.__local_logger = local_logger | ||
| self.__device = config.device | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add empty line above this line. |
||
| self.__enable_half_precision = not self.__device == "cpu" | ||
| if ( | ||
| self.__device != DetectTargetUltralyticsConfig.CPU_DEVICE | ||
| and not torch.cuda.is_available() | ||
| ): | ||
| self.__local_logger.warning("CUDA not available. Falling back to CPU.") | ||
| self.__device = DetectTargetUltralyticsConfig.CPU_DEVICE | ||
| self.__enable_half_precision = self.__device != DetectTargetUltralyticsConfig.CPU_DEVICE | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add empty line above this line. |
||
| self.__model = ultralytics.YOLO(config.model_path) | ||
| if config.override_full: | ||
| self.__enable_half_precision = False | ||
|
Comment on lines
71
to
72
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this closer to the enable half precision declaration. |
||
| self.__counter = 0 | ||
| self.__local_logger = local_logger | ||
| self.__show_annotations = show_annotations | ||
| self.__filename_prefix = "" | ||
| if save_name != "": | ||
|
|
@@ -127,11 +136,16 @@ def run( | |
| filename = self.__filename_prefix + str(self.__counter) | ||
|
|
||
| # Annotated image | ||
| cv2.imwrite(filename + ".png", image_annotated) # type: ignore | ||
| cv2.imwrite(filename + ".png", image_annotated) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Save the image using the logger. |
||
|
|
||
| self.__counter += 1 | ||
|
|
||
| if self.__show_annotations: | ||
| cv2.imshow("Annotated", image_annotated) # type: ignore | ||
| if image_annotated is not None: | ||
| # Display the annotated image in a named window | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comment.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this line. |
||
| cv2.imshow("Annotated", image_annotated) | ||
| cv2.waitKey(1) # Short delay to process GUI events | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay to leave comment. |
||
| else: | ||
| self.__local_logger.warning("Annotated image is invalid.") | ||
|
|
||
| return True, detections | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a detect target object.