Companion code for Image Alignment with ECC in OpenCV: C++ and Python.
image_alignment_simple_example.py/.cppaligns a moving image to a template and reports the ECC correlation, warp matrix, and before/after error.image_alignment.py/.cppreconstructs a color image from vertically stacked monochrome plates by aligning the blue and green channels to red.
Both paths support translation, Euclidean, affine, and homography motion models.
- Python 3.10+ with NumPy and OpenCV 4.10+ or OpenCV 5.x
- CMake 3.16+ and a C++17 compiler for the C++ examples
python -m pip install -r requirements.txt
python image_alignment_simple_example.py --no-display --validate
python image_alignment.py --no-display --validateOutputs are written to output/.
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
./build/image_alignment_simple --no-display --validate
./build/image_alignment --no-display --validateUse --help to see the input, motion-model, convergence, output, display, and validation options.
The update removes Python 2 syntax, fixes the missing C++ sample-image path, initializes each channel warp independently, and adds robust size handling plus saved outputs. Both Python and C++ paths are tested with OpenCV 4.x and OpenCV 5.0.
ImageAlignment/
├── CMakeLists.txt
├── ecc_utils.py
├── image_alignment.cpp
├── image_alignment.py
├── image_alignment_simple_example.cpp
├── image_alignment_simple_example.py
├── images/
├── requirements.txt
├── test_ecc.py
└── readme-images/
LearnOpenCV is maintained by BigVision.AI, a computer vision and AI consulting company. We help organizations design, build, optimize, and deploy production-ready AI solutions. Our team has deep expertise in computer vision, deep learning, multimodal AI, and edge deployment, with experience solving complex technical challenges across industries.
Have a project in mind? Talk with our expert AI solution builders.
