This program detects the direction an arrow is pointing in an image using OpenCV in Python.
- Capture video frame and convert to grayscale.
- Apply Canny edge detection to find edges.
- Find contours and filter for large contours that are likely the arrow.
- Approximate the arrow contour to get vertex points.
- Calculate the midpoint of the vertices.
- Use the vector between midpoint and the first vertex to determine direction.
- Check the angle of the direction vector to determine which direction the arrow is pointing:
- Right: -45 to 45 degrees
- Left: 135 to 180 or -180 to -135 degrees
- Draw vertices, midpoint, and direction text on the original frame.
- Display video with detected arrow direction.
- Run the Python script to display the video feed with arrow detection.
- Point an arrow towards the camera, and the direction will be printed and drawn on the frame.
- Press 'q' to quit.
- Tweak the Canny threshold values to better detect arrow edges.
- Adjust the contour area filter as needed for arrow size.
- Modify angle ranges for direction detection as desired.
- Change midpoint and vertex circle colors and sizes.
- OpenCV
- NumPy
- Math