This project is a computer vision application for detecting "No Entry" signs in images. It utilizes a combination of three different techniques to achieve this:
- Viola-Jones Algorithm: A robust object detection method that uses a cascade of classifiers trained on positive and negative image samples.
- Hough Transform for Circles: A feature extraction technique used to identify circular shapes within an image.
- Template Matching: A method for finding small parts of an image that match a template image.
The system can be run on a single image or a directory of images. It evaluates its performance using the True Positive Rate (TPR) and F1 Score metrics.
The shape_detection.py script is the main entry point of the application. It performs the following steps:
- Image Loading: Loads the input image(s) from the specified path or the
./No_entry/directory. - Viola-Jones Detection: Applies the pre-trained Viola-Jones classifier (
NoEntrycascade/cascade.xml) to detect potential sign regions. - Hough Circle Transform: Detects circles in the image using the Hough Transform.
- Template Matching: Matches a template of the "No Entry" sign (
no_entry.jpg) against the image. - Candidate Fusion: Combines the results from the different detectors and uses non-maximum suppression to eliminate duplicate detections.
- Colour Filtering: Filters the detected regions based on the presence of red, a dominant colour in "No Entry" signs.
- Evaluation: Compares the final detections against the ground truth data in
groundtruth.txtand calculates the TPR and F1 Score. - Output: Saves the images with the detected signs in the
./Output/directory.
shape_detection.py: The main script that orchestrates the detection process.violaJones.py: Implements the Viola-Jones object detection.houghSpace.py: Implements the Hough Transform for circle detection.centralController.py: A helper class for calculating evaluation metrics like IoU, TPR, and F1-score.groundtruth.txt: Contains the ground truth bounding boxes for the images in theNo_entrydirectory.NoEntrycascade/cascade.xml: The pre-trained cascade classifier for the Viola-Jones algorithm.no_entry.jpg: The template image used for template matching.negatives/: A directory containing negative samples used for training the classifier.No_entry/: A directory containing the test images with "No Entry" signs.Output/: The directory where the output images with detected signs are saved.
To run the detection on the default set of images in the ./No_entry/ directory, simply execute the shape_detection.py script:
python shape_detection.pyTo run the detection on a specific image, use the --image argument:
python shape_detection.py --image /path/to/your/image.jpgThis project requires the following Python libraries:
- OpenCV:
pip install opencv-python - NumPy:
pip install numpy - Matplotlib:
pip install matplotlib