Automated Target Scoring Using Python
In this blog, I'll show you how to build an automated archery scoring system using Python and the YOLOv8 object detection model. This project aims to eliminate manual scoring by accurately detecting where arrows hit the target, pinpointing their positions, and calculating scores based on proximity to the center. This guide covers everything you need, including image processing techniques, using YOLOv8 for object detection, and custom score calculations.
Scoring in archery can be slow and prone to errors when done manually. To solve this, I created a system that automatically scores by identifying where arrows hit the target and computing their scores. The system utilizes the YOLOv8 model for arrow detection and incorporates straightforward image processing techniques to ensure precise result.
Refining focus from capture to calculation, where precision meets analysis
Detect masks, identify centers with circles, and create rings of precision.
Pinpointing targets, calculating scores, and displaying winning precision.
The first important step was to find the edge of the archery target. This was needed to separate the target from the rest of the image and focus on detecting the arrows correctly. To do this, I trained the YOLOv8 model to recognize the round edges of archery targets. The model was given many labeled images of archery targets, helping it learn to spot the target edges accurately.
To get accurate scores, finding the exact center of the target was very important. Most archery targets have a yellow circle in the center. I used the HSV (Hue, Saturation, Value) color space to find this yellow area. By changing the image to HSV and applying a yellow color mask, I could accurately find the center of the target. This step was crucial because all distance calculations were based on this center point.
With the center of the target identified, the next task was to draw concentric circles (radii) from the center to the edges of the target. These circles represent different score zones on the target. Each circle corresponds to a specific score, with the innermost circle (the bullseye) having the highest score. I manually defined the radii based on the standard dimensions of an archery target. By overlaying these circles on the target image, I created a clear visual representation of the scoring zones.
Once the target border was detected, the next challenge was to identify the hit points where the arrows had struck. For this, I utilized a second YOLOv8 model trained specifically for detecting arrows. This model was designed to locate the exact positions of the arrows on the target. The process involved annotating images with arrow positions and training the model to recognize these annotations. The model's output provided the coordinates of the arrows, which were essential for the scoring calculation.
Step 5: Calculating the Distances and Scores
The last step was to calculate the distances from the center to each hit point and find the scores. Using the coordinates of the center and the hit points, I calculated the straight-line distance for each arrow. Based on these distances, I gave scores to each arrow. The closer the arrow was to the center, the higher the score it got. The total score was then found by adding up the scores of all the arrows.
Collecting a robust dataset was the cornerstone of this project. I gathered hundreds of images of archery targets from various sources. These images were annotated to mark the target borders and the positions of the arrows. Annotation tools like LabelImg were used to create XML files containing the coordinates of the target and the arrows. These annotated images were then used to train the YOLOv8 models.
Training the YOLOv8 models involved several steps. First, the annotated images were divided into training and validation sets. The YOLOv8 configuration files were adjusted to suit the specific requirements of detecting target borders and arrows. The models were then trained on high-performance GPUs to speed up the process. Multiple iterations were run to fine-tune the models and improve their accuracy. The training process also included data augmentation techniques such as rotation, scaling, and flipping to make the models more robust.
OpenCV, a powerful computer vision library, played a crucial role in the image processing pipeline. After detecting the target border and the hit points with YOLOv8, OpenCV was used to convert the image to the HSV color space and isolate the yellow center. Morphological operations like erosion and dilation were applied to refine the detection. The cv2.circle function was used to draw the concentric circles representing the score zones. OpenCV’s functions were also utilized to calculate the distances between the center and the hit points.
The scoring was done in Python using basic distance calculations. I used the Euclidean distance formula to measure how far each arrow was from the center of the target. Then, I compared these distances to set distances that corresponded to different score zones. I made a dictionary that matched distances to scores to help with this. For example, hitting within 10 pixels of the center might score 10 points, within 20 pixels could score 9 points, and so on.
Here is an example of what the system produces, showing where it found arrows, the center of the target, the circles drawn from the center to the edges, and the scores calculated. The image below displays the processed archery target with the total score shown.
This project highlights the effective use of Python and the YOLOv8 model in developing an automated archery scoring system. By combining object detection with advanced image processing techniques, we can achieve accurate and efficient scoring with minimal human intervention. This system not only speeds up the scoring process but also ensures consistency and reduces the possibility of human error.
Powered by Froala Editor