Implementation of the 8-point algorithm to estimate relative camera pose (rotation and translation) from image pairs using fundamental and essential matrix decomposition.
This project implements multiple methods for camera pose estimation from a sequence of images:
- 8-Point Algorithm (least squares)
- RANSAC-based fundamental matrix estimation
- OpenCV implementation for comparison
- Camera trajectory reconstruction (iterative and non-iterative)
- Feature detection and matching using SIFT/ORB
- Fundamental matrix computation (normalized 8-point, RANSAC)
- Essential matrix recovery from intrinsic calibration
- Rotation and translation disambiguation using triangulation
- 3D camera trajectory visualization
Image before camera translation:
Image after camera translation:
Corresponding features detected and matched between the two images using SIFT descriptors:
Core Components:
EightPoint.py- Main implementation with 4 methods:getRotationTranslationFromImagesRANSAC()- RANSAC-based fundamental matrixgetRotationTranslationFromImagesLS()- Least squares fundamental matrixgetRotationTranslationFromImages8Point()- Classic 8-point algorithmgetRotationTranslationFromImagesOpenCV()- OpenCV's implementation
processSequence.py- Batch processing for image sequencestest.py- Example usage and visualization
Methods:
- Extract keypoints and descriptors (SIFT/ORB)
- Match features between image pairs
- Compute fundamental matrix F (8-point or RANSAC)
- Recover essential matrix E = K^T F K
- Decompose E into 4 candidate (R, t) solutions
- Disambiguate using point triangulation (cheirality check)
from EightPoint import EightPoint
import cv2
import numpy as np
# Initialize
eight_point = EightPoint()
# Load images
img1 = cv2.cvtColor(cv2.imread('image1.png'), cv2.COLOR_BGR2GRAY)
img2 = cv2.cvtColor(cv2.imread('image2.png'), cv2.COLOR_BGR2GRAY)
# Camera intrinsic matrix
K = np.array([[focal_x, 0, cx],
[0, focal_y, cy],
[0, 0, 1]])
# Estimate pose
R, t, scale = eight_point.getRotationTranslationFromImagesRANSAC(img1, img2, K)See requirements.txt for the full list of dependencies. The requirements file is auto-generated and contains the core packages used by this project.
Install dependencies with:
pip install -r requirements.txtThe implementation was tested on synthetic rendered sequences with known ground truth. Results show:
- RANSAC provides robust estimation in the presence of outliers
- Iterative pose estimation accumulates drift over long sequences
- Direct estimation relative to first frame reduces accumulation error
See /Test1/ directory for detailed CSV results comparing different methods.


