This is a high-performance, real-time multi-camera panoramic stitching system designed for RTSP surveillance and monitoring applications. The system captures synchronized video streams from three fisheye cameras and creates seamless panoramic videos using CUDA-accelerated processing.
- π Executables Usage Guide - Detailed command-line usage and examples
- π§ Source Code Architecture Guide - Internal implementation details
- π Ai generated documentation - Component-specific documentation for a "simplier" approach to understand the project source code
- π― Sample Images - Test data and calibration examples
- Real-time RTSP capture from 3 cameras with hardware timestamping
- CUDA-accelerated processing for fisheye correction and panoramic stitching
- Two-phase architecture separating capture from processing for reliability
- Advanced frame synchronization handling network jitter and frame drops
- Multiple blending modes (max, average, feathering) for optimal visual quality
- Calibration-driven workflow supporting fisheye camera models
- GUI and command-line interfaces for different use cases
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Camera 1 βββββΆβ Synchronized βββββΆβ CUDA Stitching β
β (RTSP Feed) β β Capture System β β Pipeline β
βββββββββββββββββββ€ βββββββββββββββββββ€ βββββββββββββββββββ€
β Camera 2 βββββΆβ β’ Timestamping βββββΆβ β’ Rectification β
β (RTSP Feed) β β β’ Frame Sync β β β’ Warping β
βββββββββββββββββββ€ β β’ Metadata β β β’ Blending β
β Camera 3 βββββΆβ β’ Async I/O βββββΆβ β’ Auto-cropping β
β (RTSP Feed) β βββββββββββββββββββ βββββββββββββββββββ
βββββββββββββββββββ β
βΌ
βββββββββββββββββββ
β Panoramic Video β
β Output β
βββββββββββββββββββ
stitchmrsl/
βββ README.md # This file - main project documentation
βββ EXECUTABLES_GUIDE.md # Detailed usage guide for built executables
βββ CMakeLists.txt # Build configuration and dependencies
βββ .gitignore # Git ignore patterns
βββ .gitmodules # Git submodules configuration
βββ intrinsic.json # Camera calibration parameters
βββ extrinsic.json # Camera positioning and transformations
βββ stitch.py # Python offline stitching and calibration
βββ imgui.ini # GUI layout and preferences
βββ raw_video_gen.sh # Shell script for test video generation
βββ cpp.jpg # C++ workflow demonstration image
βββ python.jpg # Python workflow demonstration image
src/
βββ main.cc # Main GUI application entry point
βββ app.cc # Application state and coordination
βββ gui.cc # Dear ImGui interface implementation
βββ stitching.cc # Core CPU stitching algorithms
β
βββ rtsp_stitcher.cc # π― RTSP capture and processing executable
βββ video_rectifier.cc # π― Single camera rectification tool
β
βββ synchronized_capture.cc # Multi-threaded RTSP capture system
βββ frame_synchronizer.cc # Intelligent frame alignment algorithms
βββ async_frame_writer.cc # High-performance frame I/O
βββ cuda_stitching_pipeline.cc # CUDA-accelerated stitching engine
βββ error_handler.cc # Error management and recovery
β
βββ cuda_stitching_pipeline_old.cc # Legacy CUDA implementation
βββ rtsp_stitcher_old.cc # Legacy RTSP implementation
include/
βββ app.hh # Application state management
βββ gui.hh # GUI interface definitions
βββ stitching.hh # Core stitching algorithms
β
βββ synchronized_capture.hh # RTSP capture system interface
βββ frame_synchronizer.hh # Frame synchronization algorithms
βββ async_frame_writer.hh # Asynchronous I/O operations
βββ cuda_stitching.hh # CUDA processing pipeline
βββ error_handler.hh # Error handling utilities
docs/
βββ index.md # Documentation index
βββ 01_offline_stitching___calibration_script__python__.md # Python calibration guide
βββ 02_applicationstate__gui__.md # GUI application documentation
βββ 03_stitchingpipeline__c____.md # C++ stitching pipeline
βββ 04_synchronizedcapture_.md # Capture system details
βββ 05_framemetadata_.md # Metadata structure
βββ 06_framesynchronizer_.md # Synchronization algorithms
βββ 07_cuda_stitching_pipeline_.md # CUDA implementation
libs/
βββ imgui/ # Dear ImGui library for GUI
β βββ imgui.cpp # Core ImGui implementation
β βββ imgui_demo.cpp # Example and demo code
β βββ imgui_draw.cpp # Rendering backend
β βββ imgui_tables.cpp # Table widgets
β βββ imgui_widgets.cpp # UI widgets
β βββ backends/ # Platform-specific backends
β βββ imgui_impl_glfw.cpp # GLFW window management
β βββ imgui_impl_opengl3.cpp # OpenGL rendering
β
βββ gl3w/ # OpenGL extension loader
βββ include/GL/gl3w.h # Header file
βββ src/gl3w.c # Implementation
imgs/
βββ central.jpg # Sample center camera image
βββ central2.jpg # Additional center camera sample
βββ derecha.jpg # Sample right camera image
βββ derecha2.jpg # Additional right camera sample
βββ izquierda.jpg # Sample left camera image
βββ izquierda2.jpg # Additional left camera sample
β
βββ central/ # Center camera image sequence
β βββ image01.jpg - image07.jpg
βββ derecha/ # Right camera image sequence
β βββ image01.jpg - image07.jpg
βββ izquierda/ # Left camera image sequence
βββ image01.jpg - image07.jpg
After building with CMake, you'll have these main executables:
- Purpose: Visual interface for camera calibration and live stitching adjustments
- Features: Real-time preview, calibration adjustment, parameter tuning
- Usage:
./stitchmrsl
- Purpose: Production-ready RTSP capture and stitching
- Modes: Capture, Process, Full Pipeline
- Usage:
./rtsp_stitcher <mode> <parameters>
- Purpose: Fisheye distortion correction for pre-recorded videos
- Features: CUDA-accelerated batch processing
- Usage:
./video_rectifier <input_video> <camera_name> [output_video]
# Clone repository
git clone <repository_url>
cd stitchmrsl
# Update submodules
git submodule update --init --recursive
# Build
mkdir build && cd build
cmake ..
make -j$(nproc)
- Place camera calibration in
intrinsic.json
- Place camera positioning in
extrinsic.json
- Use Python script
stitch.py
for initial calibration
# Interactive GUI
./stitchmrsl
# RTSP Processing
./rtsp_stitcher capture rtsp://cam1 rtsp://cam2 rtsp://cam3
# Video Rectification
./video_rectifier input.mp4 central output.mp4
Contains fisheye camera calibration data for each camera:
{
"cameras": {
"izquierda": { // Left camera
"K": [[fx, 0, cx], [0, fy, cy], [0, 0, 1]], // Camera matrix
"dist": [[k1], [k2], [k3], [k4]], // Distortion coefficients
"image_size": [width, height], // Image dimensions
"model": "fisheye" // Camera model type
},
"central": { /* Center camera parameters */ },
"derecha": { /* Right camera parameters */ }
}
}
Defines transformation matrices between cameras:
{
"best_transforms": {
"AB_similarity": [[r11, r12, tx], [r21, r22, ty], [0, 0, 1]], // Left to Center
"BC_similarity": [[r11, r12, tx], [r21, r22, ty], [0, 0, 1]] // Right to Center
}
}
- GPU: NVIDIA with CUDA Compute Capability 6.1+
- GPU Memory: 4GB minimum for 1080p, 8GB recommended for 4K
- System RAM: 8GB minimum, 16GB recommended
- Storage: SSD recommended for real-time capture
- Network: Gigabit Ethernet for multiple RTSP streams
- CUDA Toolkit: 11.0 or later
- OpenCV: 4.5+ with CUDA support enabled
- CMake: 3.12 or later
- Compiler: GCC 7+ with C++17 support
- Libraries: nlohmann/json, GLFW3, OpenGL
-
Separation of Concerns:
src/
contains implementation logicinclude/
contains public interfaces- GUI and command-line tools are separate executables
-
CUDA Integration:
- GPU-accelerated processing in
cuda_stitching_pipeline.cc
- CPU fallback algorithms in
stitching.cc
- Memory management and error handling
- GPU-accelerated processing in
-
Asynchronous Design:
- Multi-threaded capture system
- Non-blocking I/O operations
- Real-time processing pipeline
.cc
files: C++ implementation.hh
files: C++ headers.py
files: Python scripts for calibration and testing.json
files: Configuration and calibration data.md
files: Documentation and guides.sh
files: Shell scripts for automation
synchronized_capture.cc + synchronized_capture.hh
βββ Multi-threaded camera capture
βββ Hardware timestamping
βββ Asynchronous frame writing
βββ Memory management
βββ Statistical monitoring
frame_synchronizer.cc + frame_synchronizer.hh
βββ Timestamp-based alignment
βββ Network jitter compensation
βββ Quality-based frame selection
βββ Configurable sync windows
βββ Performance optimization
cuda_stitching_pipeline.cc + cuda_stitching.hh
βββ GPU memory management
βββ Fisheye rectification
βββ Perspective warping
βββ Multi-mode blending
βββ Auto-cropping
gui.cc + gui.hh + main.cc + app.cc
βββ Dear ImGui implementation
βββ Real-time parameter adjustment
βββ Live preview and monitoring
βββ Calibration workflow
βββ Performance visualization
- Use
stitch.py
for initial camera calibration - Test with sample images in
imgs/
directory - Use GUI application for parameter tuning
- Validate with
video_rectifier
for single cameras
- Use
rtsp_stitcher
for automated processing - Monitor performance with built-in statistics
- Implement error handling and recovery
- Scale with multiple GPU systems
- Capture calibration images with fisheye patterns
- Run Python calibration script:
python3 stitch.py
- Generate
intrinsic.json
andextrinsic.json
- Validate calibration with GUI preview
- Fine-tune parameters for optimal stitching
- π Executables Guide: Detailed usage instructions for command-line tools
- π Documentation: Technical documentation for each component
- π― Sample Data: Test images and configurations in
imgs/
directory - π§ Build Scripts: CMake configuration for cross-platform builds
This project follows standard C++ and Python development practices:
- Code Style: Follow existing formatting and naming conventions
- Documentation: Update relevant
.md
files for new features - Testing: Validate changes with sample data in
imgs/
- Performance: Monitor GPU memory usage and processing times
π
- CMake 3.12+
- C++17 compatible compiler
- Stable network connection to RTSP cameras
- Recommended: Gigabit Ethernet for 3x 1080p streams
intrinsic.json
- Camera intrinsic parameters (fisheye model)extrinsic.json
- Camera extrinsic parameters and transformations
// Frame synchronization settings
synchronizer.SetSyncWindow(std::chrono::milliseconds(50)); // 50ms sync window
synchronizer.SetMinSyncQuality(100.0); // 100ms max deviation
synchronizer.SetMaxFrameAge(std::chrono::milliseconds(200)); // 200ms max frame age
// GPU memory and processing settings
pipeline.SetBlendingMode(0); // 0=max, 1=average, 2=weighted
pipeline.SetOutputSize(cv::Size(3840, 1080)); // Custom output resolution
- Input: 3x 1080p RTSP streams @ 30 FPS
- Capture Rate: ~150 FPS per camera (I/O bound)
- Memory Usage: ~100MB circular buffers + frame queue
- Storage Rate: ~2.5GB/minute raw frames (PNG compressed)
- CUDA Pipeline: ~30-60 FPS synchronized triplets
- Memory Usage: ~2GB GPU memory for 1080p processing
- CPU Usage: ~20% (mostly I/O and synchronization)
- GPU Usage: ~80-90% during processing phase
π High-Performance Multi-Camera Panoramic Stitching with CUDA Acceleration
Eduardo Hernandez eduarch42@protonmail.com
David Soni sonidavid46@gmail.com