A Python tool that analyzes motion in videos by comparing consecutive frames and extracting motion angles using 8-directional search with recursive subdivision.
- 8-Directional Motion Detection: Searches in N, NE, E, SE, S, SW, W, NW directions
- Configurable Grid Subdivision: Divide frames into customizable grid sections
- Recursive Analysis: Subdivide sections with significant motion for finer detail
- Color-Coded Visualization: Motion angles displayed using HSV color mapping
- Real-time Processing: View results while processing (or save to file)
- Flexible Configuration: Easily adjust all parameters
- Install required packages:
pip install -r requirements.txtpython main.py input_video.mp4python main.py input_video.mp4 -o output_with_motion.mp4python main.py input_video.mp4 --grid-size 8 8 --step-size 10 --max-depth 3--grid-size ROWS COLS: Grid subdivision (default: 16x16)--step-size PIXELS: Search step size in pixels (default: 5)--max-depth DEPTH: Maximum recursive depth (default: 2)--motion-threshold THRESHOLD: Motion threshold for recursion (default: 0.1)
- Frame Processing: Extracts consecutive frames and converts to grayscale
- Grid Creation: Divides each frame into a configurable grid
- Motion Search: For each grid section, searches in 8 directions to find best match
- Recursive Subdivision: Sections with high motion are subdivided for finer analysis
- Visualization: Results displayed with color-coded motion angles
- Color Coding: Hue represents motion angle (0-360°), saturation represents motion strength
- Motion Vectors: Yellow arrows show motion direction and magnitude
- Grid Lines: White lines show section boundaries
- Legend: Color wheel on the right shows angle-to-color mapping
Edit config.py to customize:
GRID_ROWS = 16 # Grid height
GRID_COLS = 16 # Grid width
SEARCH_STEP_SIZE = 5 # Pixel step for directional search
MAX_RECURSIVE_DEPTH = 2 # Levels of subdivision
MOTION_THRESHOLD = 0.1 # Minimum motion for recursion- Press 'q' to quit during playback
- Window shows real-time analysis results
- Live visualization window with motion analysis
- Optional output video file with embedded analysis
- Console progress updates