Unveiling the Hidden World: Real-World Camera Calibration and Uncertainty Analysis
This repository contains the Python notebook and associated files for a computer vision project focused on calibrating real-world cameras. The core of this project is to determine a camera's precise 3D geographic location (latitude, longitude, altitude) and intrinsic properties (calibration matrix K) from 2D image data.
A key differentiator of this project is its two-part structure: first, a rigorous uncertainty analysis using synthetic data, and second, a practical application to find the location of live webcams.
For a detailed narrative, insights into the methodology, and a full discussion of the project's challenges and findings, please read the companion article on Medium:
Unveiling the Hidden World: Calibrating Real-World Cameras and Understanding Their...
- Core Objectives
- Tools & Technologies
- Project Methodology
- How to Use This Repository
- Expected Outputs
- Estimate Camera Pose: Determine the camera's 3D position (latitude, longitude, altitude), orientation, and its intrinsic calibration matrix (K).
- Uncertainty Analysis: Quantify the reliability and robustness of the camera parameter estimations using statistical methods.
- Real-World Application: Apply these calibration techniques to determine the 3D locations of live webcams.
- Python Libraries:
pandas,matplotlib,pyproj,pymap3d,numpy,cv2(OpenCV). - Geospatial Software: Google Earth Pro (for manual 3D coordinate extraction from real-world scenes).
This project is divided into two main parts:
This section uses a pre-provided dataset of 3D-to-2D point correspondences to perform an in-depth uncertainty analysis and validate the model's stability.
-
1a) Leave-One-Out (LOO) Analysis:
- Objective: To assess the sensitivity of the estimated camera location to individual data points.
- Method: The calibration is run 'N' times, each time excluding one of the 'N' data points.
- Output: A 3D scatter plot of the 'N' recovered camera locations, visually illustrating the estimation's stability.
-
1b) Noise Analysis:
- Objective: To evaluate the robustness of the camera parameters (location and focal length) under simulated real-world noise.
- Method: The calibration is run 100 times. In each iteration, Gaussian zero-mean noise is added to both the 3D coordinates (std dev 1m) and 2D pixel locations (std dev 1px).
- Output: A 3D scatter plot of the 100 recovered camera locations and a histogram of the estimated focal lengths.
This section applies the validated methodology to determine the 3D geographic locations of live webcams.
- Methodology:
- Select Webcams: Identify live streams (e.g., YouTube, NPS webcams).
- Landmark Identification: Find distinct, static features visible in the webcam and on satellite imagery.
- 3D Coordinate Extraction: Use Google Earth Pro to find the precise latitude, longitude, and absolute altitude of these landmarks.
- 2D Coordinate Extraction: Record the corresponding (x, y) pixel coordinates for each landmark from the webcam image.
- Data Compilation: Aggregate the 3D and 2D points into a structured CSV file (e.g.,
bostonharbor.csv). - Calibration & Validation: Run the Python calibration script on the real-world data and generate a Reprojection Plot to visually validate the accuracy by projecting the 3D points back onto the image.
- Refinement: Iteratively refine landmark selection based on the reprojection error.
- Clone the repository:
git clone [https://github.com/Anaswara23/OpenCV-Camera-Calibration]
- Install dependencies:
pip install pandas matplotlib pyproj pymap3d numpy opencv-python
- Run the notebook:
- Open
calibrate.ipynb(or your notebook's name) in a Jupyter environment or Google Colab.
- Open
- Part 1 (Uncertainty Analysis):
- Ensure the synthetic data CSV is present.
- Run the cells in the "Part 1" section to generate the LOO and noise analysis plots.
- Part 2 (Real-World Calibration):
- Follow the methodology in "Part 2" to create your own CSV file.
- Update the notebook to load your CSV file.
- Run the calibration and validation cells to find the camera's location and see the reprojection plot.
- A 3D point cloud visualizing the Leave-One-Out (LOO) analysis.
- A 3D point cloud and histogram for the Noise Analysis.
- For Part 2, a table of collected 3D/2D coordinates, the final recovered 3D GPS location (lat, long, alt) for the webcam, and a reprojection plot showing the calibration accuracy.