Skip to content

Commit

Permalink
Fix constant ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhp1 committed Nov 30, 2024
1 parent e0e07a2 commit e0013e9
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 6 deletions.
72 changes: 72 additions & 0 deletions modules/detect_target/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""
Run bright spot detection on multiple images.
"""

import pathlib
import cv2
from modules.detect_target import detect_target_brightspot
from modules import image_and_time
from modules.common.modules.logger import logger

# Paths
IMAGE_DIR = pathlib.Path("tests/brightspot_example")
IMAGE_FILES = [
"ir1.png",
"ir2.png",
"ir3.png",
"ir4.png",
"ir5.png",
"ir6.png",
"ir7.png",
] # List of image files
SAVE_DIR = pathlib.Path("output")


def main() -> None:
"""
Run bright spot detection on multiple images.
"""
# Initialize logger
result, local_logger = logger.Logger.create("brightspot_logger", False)
if not result or local_logger is None:
print("Failed to create logger.")
return

# Ensure the save directory exists
SAVE_DIR.mkdir(parents=True, exist_ok=True)

for image_file in IMAGE_FILES:
image_path = IMAGE_DIR / image_file

# Initialize the detector
detector = detect_target_brightspot.DetectTargetBrightspot(
local_logger=local_logger,
show_annotations=True,
save_name=image_file,
)

# Load the image
image = cv2.imread(str(image_path))
if image is None:
print(f"Failed to load image from {image_path}")
continue

# Create ImageAndTime object
result, image_data = image_and_time.ImageAndTime.create(image)
if not result or image_data is None:
print(f"Failed to create ImageAndTime object for {image_path}")
continue

# Run the detector
success, detections = detector.run(image_data)
if not success or detections is None:
print(f"Detection failed or returned no detections for {image_path}")
continue

print(f"Detection successful for {image_path}. Detections:")
for detection in detections.detections:
print(f"Label: {detection.label}, Confidence: {detection.confidence}")


if __name__ == "__main__":
main()
15 changes: 9 additions & 6 deletions tests/unit/test_detect_target_brightspot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@
from modules.detect_target import detect_target_brightspot


NUMBER_OF_IMAGES_DETECTIONS = 5
NUMBER_OF_IMAGES_NO_DETECTIONS = 2
TEST_PATH = pathlib.Path("tests", "brightspot_example")

NUMBER_OF_IMAGES_DETECTIONS = 5
IMAGE_DETECTIONS_FILES = [
pathlib.Path(f"ir_detections_{i}.png") for i in range(0, NUMBER_OF_IMAGES_DETECTIONS)
]
IMAGE_NO_DETECTIONS_FILES = [
pathlib.Path(f"ir_no_detections_{i}.png") for i in range(0, NUMBER_OF_IMAGES_NO_DETECTIONS)
]
EXPECTED_DETECTIONS_PATHS = [
pathlib.Path(TEST_PATH, f"bounding_box_ir_detections_{i}.txt")
for i in range(0, NUMBER_OF_IMAGES_DETECTIONS)
]
DETECTION_TEST_CASES = list(zip(IMAGE_DETECTIONS_FILES, EXPECTED_DETECTIONS_PATHS))

NUMBER_OF_IMAGES_NO_DETECTIONS = 2
IMAGE_NO_DETECTIONS_FILES = [
pathlib.Path(f"ir_no_detections_{i}.png") for i in range(0, NUMBER_OF_IMAGES_NO_DETECTIONS)
]
NO_DETECTION_TEST_CASES = IMAGE_NO_DETECTIONS_FILES

BOUNDING_BOX_PRECISION_TOLERANCE = 3
CONFIDENCE_PRECISION_TOLERANCE = 6

Expand Down Expand Up @@ -143,7 +146,7 @@ def image_ir_detections(request: pytest.FixtureRequest) -> tuple[image_and_time.
yield ir_image, detections # type: ignore


@pytest.fixture(params=IMAGE_NO_DETECTIONS_FILES)
@pytest.fixture(params=NO_DETECTION_TEST_CASES)
def image_ir_no_detections(request: pytest.FixtureRequest) -> image_and_time.ImageAndTime: # type: ignore
"""
Load image with no detections.
Expand Down

0 comments on commit e0013e9

Please sign in to comment.