Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

showing annotated images for detect target message bug fix #230

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
arpanroy18 marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Binary file added modules/.DS_Store
arpanroy18 marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
20 changes: 19 additions & 1 deletion modules/detect_target/detect_target_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import enum
import torch

from . import base_detect_target
from . import detect_target_ultralytics
Expand All @@ -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).
arpanroy18 marked this conversation as resolved.
Show resolved Hide resolved
"""
arpanroy18 marked this conversation as resolved.
Show resolved Hide resolved
# 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"
arpanroy18 marked this conversation as resolved.
Show resolved Hide resolved

arpanroy18 marked this conversation as resolved.
Show resolved Hide resolved
match detect_target_option:
case DetectTargetOption.ML_ULTRALYTICS:
return True, detect_target_ultralytics.DetectTargetUltralytics(
Expand Down
8 changes: 7 additions & 1 deletion modules/detect_target/detect_target_ultralytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ 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
Xierumeng marked this conversation as resolved.
Show resolved Hide resolved

return True, detections