From 9b22ecd799a3273fd544bf207215a4f792255cc2 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sat, 10 Dec 2022 16:22:14 +0200 Subject: [PATCH] Created image detector --- .../detect_traffic_light_color_image.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/detector/detect_traffic_light_color_image.py diff --git a/src/detector/detect_traffic_light_color_image.py b/src/detector/detect_traffic_light_color_image.py new file mode 100644 index 0000000..59db08e --- /dev/null +++ b/src/detector/detect_traffic_light_color_image.py @@ -0,0 +1,28 @@ +"""This program uses a trained neural network to detect the color of a traffic light in images.""" + +import logging +from pathlib import Path + +# import cv2 +# import numpy as np +from detector.object_detection import load_ssd_coco, perform_object_detection +from detector.paths import IMAGES_IN_PATH, LOGS_PATH, MODEL_PATH +from tensorflow import keras +# from tensorflow.keras.applications import imagenet_utils +# from tensorflow.keras.applications.inception_v3 import InceptionV3, preprocess_input + +# Set up logging +logger = logging.getLogger(__name__) +handler = logging.FileHandler(str(Path.joinpath(LOGS_PATH, f"{__name__}.log"))) +formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") +handler.setFormatter(formatter) +logger.addHandler(handler) + + +def detect_traffic_light_color_image() -> None: + model_traffic_lights_nn = keras.models.load_model(str(MODEL_PATH)) + + # Go through all image files, and detect the traffic light color. + for file in Path.iterdir(IMAGES_IN_PATH): + image, out, file_name = perform_object_detection(load_ssd_coco(), file, save_annotated=True, model_traffic_lights=model_traffic_lights_nn) + logger.info(f"{file} {out}")