No description
Find a file
2026-05-12 21:58:43 +02:00
.gitignore ignore testdata 2026-05-12 00:43:59 +02:00
go.mod Initial Prototype 2025-11-29 21:55:02 +01:00
go.sum Initial Prototype 2025-11-29 21:55:02 +01:00
main.go takeoff detection and gravity sync 2026-05-12 21:58:43 +02:00
README.md select best frame bast on sharpness in a sliding window 2026-05-12 00:43:49 +02:00
todo.md todo 2026-05-12 01:50:52 +02:00

Go Drone Cam GPS

Automatically select the sharpest frames from a drone video and geotag them using ArduPilot flight logs for use in photogrammetry software like WebODM.

This tool automates the tedious process of manually selecting clear frames from a video. Instead of extracting frames at a fixed interval (e.g., one every 4 seconds), it analyzes the video to find the frame with the least motion blur within each time window, leading to higher quality map and 3D model generation.

Features

  • Blur Detection: Uses FFmpeg's Laplacian filter to calculate a sharpness score for every frame.
  • Intelligent Frame Selection: Finds the single sharpest frame within configurable time windows (default is 3 seconds).
  • Automatic Geotagging: Parses ArduPilot JSON logs to find the flight's takeoff time and GPS coordinates.
  • EXIF Data Injection: Uses exiftool to write GPS latitude, longitude, and altitude to the selected image frames.
  • Simplified Workflow: Replaces a multi-step manual process with a single command.

Requirements

  • Go: The programming language the tool is written in.
  • FFmpeg: For video analysis (sharpness) and frame extraction.
  • ExifTool: For writing GPS metadata to the final images.
  • mavlogdump.py (from pymavlink): To convert the binary ArduPilot dataflash log (.bin) into a JSON format the tool can read.

Usage

Step 1: Convert ArduPilot Log to JSON

First, convert your drone's binary dataflash log file (.bin) into the required JSON format.

mavlogdump.py --format json your-flight-log.bin > log.json

Step 2: Combine and Prepare Your Video (If Necessary)

If your drone records video in multiple files, you should combine them into a single video file first.

# This example command safely concatenates all .MP4 files in the current directory
ffmpeg -f concat -safe 0 -i <(for f in ./*.MP4; do echo "file '$PWD/$f'"; done) -c copy combined.mp4

Step 3: Run the Go Program

Execute the main program, providing the path to your combined video and the JSON log file. The program will create an images directory and populate it with the sharpest, geotagged frames.

go run main.go -v combined.mp4 -l log.json -t 3

Command-line Flags:

  • -v: Path to the video file (required).
  • -l: Path to the JSON log file (required).
  • -t: Time step in seconds between selected frames (optional, default: 3).

The program will:

  1. Analyze combined.mp4 for frame sharpness (this may take some time).
  2. Read log.json to determine the flight path and timing.
  3. Select the best frames.
  4. Create an images directory.
  5. Extract the selected frames into images/output_xxxx.png.
  6. Write GPS coordinates to each image.

Step 4: Upload to Photogrammetry Software

Upload the resulting images from the images directory to your photogrammetry software (e.g., WebODM).