This program (outfield_estimation.py) reads a ballpark image ("image-mode") or downloads it via Google Maps API ("map-mode"), and computes distances from home plate to the outfield wall at 91 evenly spaced angles between the foul lines.
To obtain historical images (if current Google Maps imagery for a certain ballpark is insufficient, e.g. park is roofed), see this short instructional video. Between Steps 2 and 3, select the clock icon at the top to select the year you want the image from.
- Python 3
- Google Maps Static API key
pip install opencv-python numpy matplotlib requestsThese are bare-minimum execution commands: review Optional Arguments for further customization.
Image-Mode:
python outfield_estimation.py --image-path <YOUR_IMAGE_PATH>
Map-Mode:
python outfield_estimation.py --latitude <BALLPARK_LATITUDE> --longitude <BALLPARK_LONGITUDE> --api-key <GOOGLE_MAPS_API_KEY> --image-path <IMAGE_SAVE_PATH>
(Whether program runs in image-mode or map-mode depends simply on whether coordinates (and API-Key) are provided).
--image-path: If (--latitude, --longitude, --api-key) specified, downloads image via API to this path; otherwise, assumes user has image already downloaded, and reads from this path
--latitude: latitude of desired ballpark
--longitude: longitude of desired ballpark
--api-key: Google Maps API Key
--csv-path: Filename to which to save computed distances (NONE if no save desired, default distances.csv)
--vis-path: Filename to which to save distance visualization (NONE if no save desired, default distances_vis.png)
--graph-path: Filename to which to save angle/distance graph (NONE if no save desired, default distances_graph.png)
--field-type: Field type (MLB, MiLB, Olympic), defines warning track length (default MLB)
--min-distance-feet: Minimum distance (in feet) to consider (default 275)
--smooth-level : Maximum allowed jump (in feet) between consecutive measurements (0 if no smoothing desired, default 5)
--zoom: Google Maps zoom level (default 19)
--size: Google Maps image size (default 600)
- Distance CSV File:
- Angle (deg): Angle from center field (-45° to +45°)
- Distance (ft): Distance to outfield wall in feet
- Distance Visualization Rays:
- Green: Success: wall detection with distance measurement
- Yellow: Warning: field edge detected, but wall not found
- Red: Failure: no boundary detected
If measurements seem suboptimal:
- Verify ballpark field clearly visible in image
- Increase / decrease
--smooth-levelto reweigh data vs smoothness - Modify Google Maps
--zoomand--sizefor better resolution - Decrease
--min-distance-feetfor small parks
- Requires clear satellite imagery with visible field boundaries
- Works best on professional/well-defined baseball fields
- Accuracy depends on image resolution and zoom level
- May struggle with obscured boundaries or unusual field layouts