This Python script utilizes the OpenCV library to detect arrows in a video feed captured by a webcam. It performs image processing techniques such as thresholding, contour detection, and convex hull to identify arrows and calculate their angles from the vertical axis.
- Python 3.x
- OpenCV (
cv2
), numpy (np
), and math libraries - Webcam connected to the system
- Clone or download the repository containing the script.
- Make sure you have Python and required libraries installed.
- Connect a webcam to your system.
- Run the script using a Python IDE or a command-line interface.
- Upon running the script, a window named "Adjust" will appear along with a trackbar labeled "min".
- Adjust the trackbar to set the minimum threshold value for detecting arrows based on different lighting conditions.
- The script will then capture video from the webcam and process each frame.
- Detected arrows will be outlined in red rectangles on the video feed, along with their respective angles from the vertical axis displayed on the screen.
- Press 'q' to exit the program.
- The script defines functions to calculate distance and angle between two points.
- It initializes the webcam and sets frame dimensions and brightness.
- A trackbar is created to adjust the thresholding level.
- The script continuously reads frames from the webcam and performs image processing steps.
- Arrows are detected based on contour area and the number of corners.
- The convex hull of the detected arrow is computed, and the angle from the vertical axis is calculated.
- Detected arrows are outlined with rectangles and their angles are displayed on the video feed.
- If the webcam is not detected, make sure it is properly connected and recognized by your system.
- Adjust the trackbar to optimize arrow detection in different lighting conditions.
- Ensure that the script has necessary permissions to access the webcam.
- This script is inspired by various tutorials and examples available online for OpenCV-based object detection.
- Credits to the OpenCV community for providing extensive documentation and resources.