From 1ad8ba81b2fac0beda05b51d47c9a6e128b4481e Mon Sep 17 00:00:00 2001 From: arpanroy18 Date: Thu, 28 Nov 2024 21:23:50 -0500 Subject: [PATCH] showing annotated images for detect target message bug fix --- .DS_Store | Bin 0 -> 8196 bytes modules/.DS_Store | Bin 0 -> 8196 bytes .../detect_target/detect_target_factory.py | 20 +++++++++++++++++- .../detect_target_ultralytics.py | 10 ++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 .DS_Store create mode 100644 modules/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6252cb041e472d99eb707649732d283220ce0275 GIT binary patch literal 8196 zcmeHM!EVz)5S?vP;wZEP38Zj9vc$E7G*p!;E@|2xDglQE!2wWk5;rlpc8Ki;R2Ah6 z|G+PB!L|(hCR1S!iU1@hV_Pp8MH#=*OLqwt#_1B21L}Z|{td!B5QusdC zTvWC{RTz-3v`M;;(CW+I!3oW@c@VKdGiL;@8_iXmb+?whO**-Yd# zmNA?}3@4F{ERqaG$kBl_r8Ats2)YowSf+S3Sj}3GRSWkWRV`z z9&OVuJ*777s@mdiM!P^RYz`<;^>{wwQ))hQz3wC!C9D139l1^r*6TmS!eU|RTG1#P zW#e^w=ug_A6-GhJ8o%UU&wStQ&iYpOxnoZ{m0R1s7g~;Ik0rqA+faG+!twh4q~%9m zKakjVe8VUirB0=KeB9XFST)z{jgwXLc(YMQ|KY~TNy)f<@4=(}&O7(e^FK@8NhC)g zEyus-?HBas>p5zVJ=gc(HFt?JS$( z=lR-KgwqTM8D>{xG-rR$8|N9UE37%#>L=pn-}YtX4UpZl(}?zNsD> z;qIDhLHZ{>X60N9xjDs^s(oUc0*huAKvl-h1@( KUk1=0HopPulTyk6 literal 0 HcmV?d00001 diff --git a/modules/.DS_Store b/modules/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1f2a1991ffbc5082cf9952e80f1a5082d71403bd GIT binary patch literal 8196 zcmeHM!EVz)5S?vH>k<`((xP4}S>jriP*A0cO98h2x5rHPOPTbmTrHhuwXGwUn3b z6->WPV0w*YFwA;|H+}@YB+l|ikU@zO{1&GZLxlue>~e}<+ET8u|MiB*m$zO}0OR-$lHSDlV9Zwzmqh;P{* z6aPoh*O?iSlkzo*0}UM-+*j-qiOWf;yO@!8701wx?3S3E)Uf?`&j1Y%vxlg>>KsU( zVT5JzqtDTf9`Ox3$_T%69Q`KuzlFVipM|Ps*C4b+eQ6| u%7ytxhKdLpNykAY9S6Pq!w`KJtSr+k=*Uovp#1xb0Q>$I;B7P42>bySSY4I? literal 0 HcmV?d00001 diff --git a/modules/detect_target/detect_target_factory.py b/modules/detect_target/detect_target_factory.py index ca37a14b..4a0fff13 100644 --- a/modules/detect_target/detect_target_factory.py +++ b/modules/detect_target/detect_target_factory.py @@ -3,6 +3,7 @@ """ import enum +import torch from . import base_detect_target from . import detect_target_ultralytics @@ -27,8 +28,25 @@ def create_detect_target( save_name: str, ) -> tuple[bool, base_detect_target.BaseDetectTarget | None]: """ - Construct detect target class at runtime. + Factory function to create a detection target object. + + Parameters: + detect_target_option: Enumeration value to specify the type of detection. + device: Target device for inference ("cpu" or CUDA device index). + model_path: Path to the model file. + override_full: Force full precision floating point calculations. + local_logger: Logger instance for logging events. + show_annotations: Whether to display annotated images. + save_name: Prefix for saving logs or annotated images. + + Returns: + Tuple containing success status and the instantiated detection object (if successful). """ + # Fall back to CPU if no GPU is available + if device != "cpu" and not torch.cuda.is_available(): + local_logger.warning("CUDA not available. Falling back to CPU.") + device = "cpu" + match detect_target_option: case DetectTargetOption.ML_ULTRALYTICS: return True, detect_target_ultralytics.DetectTargetUltralytics( diff --git a/modules/detect_target/detect_target_ultralytics.py b/modules/detect_target/detect_target_ultralytics.py index 4f9bddc1..d50c86f7 100644 --- a/modules/detect_target/detect_target_ultralytics.py +++ b/modules/detect_target/detect_target_ultralytics.py @@ -7,6 +7,7 @@ import cv2 import ultralytics + from . import base_detect_target from .. import image_and_time from .. import detections_and_time @@ -111,6 +112,13 @@ def run( self.__counter += 1 if self.__show_annotations: - cv2.imshow("Annotated", image_annotated) # type: ignore + if image_annotated is None: + self.__local_logger.error("Annotated image is invalid.") + return False, detections + + + # Display the annotated image in a named window + cv2.imshow("Annotated", image_annotated) + cv2.waitKey(1) # Short delay to process GUI events return True, detections