Usage Guide
This guide walks you through the complete workflow for using the 3D-Cam system.
Step 1: Capture Video
On Raspberry Pi:
./capture_raspi.sh
# Or manually: python apps/capture_raspi.py
- UVC cameras are tested and supported
- PiCamera support coming soon
On Windows:
capture_windows.bat
# Or manually: python apps/capture_windows.py
Procedure:
- Open the capture application
- Select your camera
- Position a ruler or calibration target with known millimeter markings on the mirror surface
- Capture a single frame image with the scale visible
- Record video(s) of objects moving at constant Z heights (different heights for calibration)
- Note: Any number of objects can be in each video, as long as they all move at the same constant Z height for that video
- When clicking “Record”, a dialog will prompt for an optional filename prefix:
- Enter a prefix (e.g., “experiment1”) to create custom filenames like
experiment1_YYYYMMDD_HHMMSS.mp4 - Leave blank or cancel to use auto-generated names like
video_1920x1080_30fps_YYYYMMDD_HHMMSS.mp4
- Enter a prefix (e.g., “experiment1”) to create custom filenames like
Output: Videos saved to inputs_outputs/{prefix}_YYYYMMDD_HHMMSS/ or inputs_outputs/video_[W]x[H]_[FPS]fps_YYYYMMDD_HHMMSS/ directory
Step 2: Image Calibration (Scale Calibration)
# Linux/Raspberry Pi:
./calibrate_scale_raspi.sh
# Windows:
calibrate_scale_windows.bat
Purpose: Determine the pixels-per-millimeter (px/mm) scale and working distance.
Procedure:
- Load the captured frame image with the millimeter scale
- Click two points that correspond to a known distance (e.g., 34 mm between two ruler marks)
- Enter the measurement in millimeters
- Enter camera parameters:
- Focal length (mm)
- Pixel size (microns)
- Sensor dimensions (mm)
- Click “Calculate” to compute:
pixels_per_mm: Scale factor for converting pixel measurements to millimetersworking_distance_mm: Distance from camera to the reflection surface
Output: Calibration JSON file saved to calibrations/{image_name}_image_calibration_YYYYMMDD_HHMMSS.json
Step 3: Pair Detection
Recommended: Standard Blob Detection
# Linux/Raspberry Pi:
./detect_pairs.sh
# Windows:
detect_pairs.bat
Alternative: Watershed Detection (for overlapping particles)
# Linux/Raspberry Pi:
./detect_pairs_watershed.sh
# Windows:
python apps/detect_pairs_watershed.py
Purpose: Detect particle pairs (direct view + mirror reflection) and track them through the video.
Procedure:
- Select a video folder (automatically detects the base video file)
- Set the optical center (where particles align along radial lines from the mirror edge):
- Initial estimate: Click in the preview window to set a rough optical center
- Optimize: Click “Optimize Optical Center” button to analyze all frames and find the optimal center
- Iterate: Repeat the optimization step until the center position stops changing
- Tune detection parameters:
- Threshold: Binary threshold for particle detection (0-255)
- Blur: Gaussian blur kernel size to reduce noise
- Invert Threshold: Checkbox to enable inverted threshold mode
- Min/Max Area: Size constraints for valid particles (px²)
- Adjust pairing weights and choose pairing algorithm (Hungarian recommended)
- Export the processed video with tracked pairs
Output: All files saved in the same folder as the input video:
- Grayscale video with overlays:
{video_name}-grayscale.mp4 - Binary video with overlays:
{video_name}-binary.mp4 - CSV file with all pair data:
{video_name}-paired-tracked.csv - Preset file:
detect_pairs_preset.json
Step 4: Video Calibration (Z-Height Calibration)
# Linux/Raspberry Pi:
./calibrate_video.sh
# Windows:
calibrate_video.bat
Purpose: Calibrate the Z-height measurement by using videos of objects at known heights. You need at least 2 videos at different Z heights to perform linear regression.
Procedure:
- Enter the global working distance (mm) - should match the value from image calibration
- For each calibration CSV:
- Browse to select a CSV file from pair detection
- Enter the known Z height (mm) above the reflection surface for that CSV
- Click “Calculate” to determine:
magic_constant: Linear scaling factormagic_offset: Offset in millimeters
- Calibration is automatically saved to the
calibrationsfolder
Output: Calibration JSON file automatically saved to calibrations/{csv1}_{csv2}_{...}_video_calibration_YYYYMMDD_HHMMSS.json
Step 5: Track Smoothing (Optional)
# Linux/Raspberry Pi:
./smooth_tracks.sh
# Windows:
smooth_tracks.bat
Purpose: Smooth trajectories and remove noise spikes from tracking data.
Procedure:
- Load a CSV file from your pair detection results
- Adjust smoothing parameters:
- Window Size: Moving average window (larger = more smoothing)
- Spike Threshold: Statistical outlier threshold
- Velocity Threshold: Maximum allowed velocity jump
- Toggle display options and view smoothness metrics
- Export cleaned CSV data
Output: Smoothed CSV saved as {csv_name}-smoothed.csv in the same folder as the CSV
Step 6: 3D Visualization
# Linux/Raspberry Pi:
./visualize_3d.sh
# Windows:
visualize_3d.bat
Purpose: Interactively visualize 3D trajectories from processed pair data.
Procedure:
- Load a CSV file from your pair detection results
- Use time slider to scrub through frames
- Toggle trail visualization and adjust trail length
- Select specific tracks to display
- Rotate/zoom/pan the 3D view
- Export animated video of the 3D trajectories
Output: 3D plot video saved as {csv_name}-3dplot.mp4 in the same folder as the CSV
Step 7: Z Height Histogram Analysis
# Linux/Raspberry Pi:
./plot_z_histogram.sh
# Windows:
plot_z_histogram.bat
Purpose: Analyze and visualize the distribution of Z heights in your tracked data.
Procedure:
- Load a CSV file (automatically loads latest from inputs_outputs, or manually browse)
- View the histogram showing Z height distribution
- Adjust histogram settings (bins, log scale)
- View statistics panel (mean, median, standard deviation, min/max)
- Export histogram as PNG image
Output: Histogram image saved as {csv_name}-histogram.png in the same folder as the CSV
Complete Workflow Summary
- Capture → Record video with calibration frame
- Image Calibration → Determine pixels-per-millimeter scale
- Pair Detection → Detect and track particle pairs
- Video Calibration → Calibrate Z-height measurements
- Track Smoothing (Optional) → Clean trajectories
- 3D Visualization → View 3D trajectories
- Z Height Analysis → Analyze height distribution
For more detailed information, see the main README in the repository.