https://github.com/diyer22/calibrating
Calibrate camera's intrinsic/extristric, and build stereo depth camera with OpenCV python.
https://github.com/diyer22/calibrating
calibration camera-calibration stereo stereo-calibration
Last synced: 11 months ago
JSON representation
Calibrate camera's intrinsic/extristric, and build stereo depth camera with OpenCV python.
- Host: GitHub
- URL: https://github.com/diyer22/calibrating
- Owner: DIYer22
- Created: 2021-08-22T14:56:56.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-04T13:30:27.000Z (over 2 years ago)
- Last Synced: 2024-08-08T03:09:39.979Z (almost 2 years ago)
- Topics: calibration, camera-calibration, stereo, stereo-calibration
- Language: Python
- Homepage:
- Size: 554 KB
- Stars: 32
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `calibrating`: A Python Library for Camera Calibration
Calibrate camera's intrinsic/extristric, and build stereo depth camera with OpenCV python.
[](https://yl-data.github.io/2108.calibrating-vis/stereo/index.html)

## ▮ Features
- High-level API that simplifies calibration steps
- Object-oriented Pythonic code style
- Rich visualization to verify the calibration effect. e.g. [stereo-rectify-vis](https://yl-data.github.io/2108.calibrating-vis/stereo/index.html), [reproject-depth-vis](https://yl-data.github.io/2108.calibrating-vis/project-depth/index.html)
- Very easy to install and run the example with [example images](https://github.com/yl-data/calibrating_example_data)
- Mature [stereo module](calibrating/stereo_camera.py) for correctly converting disparity to depth map that aligned with the left camera
- Provide camera internal and external parameters standard, which can be exported as `.yaml`
- Decoupling the feature extraction and calibration process, support both checkboard and markers(`cv2.aruco`)
- Support [occluded markers](example/test_occlude_marker.py) like [ArUco](https://docs.opencv.org/4.x/d5/dae/tutorial_aruco_detection.html) and [ChArUco](https://docs.opencv.org/4.6.0/df/d4a/tutorial_charuco_detection.html), and multiple calibration boards in one image
- Draw various calibration board images
- Automatically ignore non-compliant images or markers
- Convert to NeRF format json for 3D reconstruction
- LiDAR-camera extrinsic calibration without chessboard, see [lidar2cam_by_PnP example](example/calibrate_lidar2cam_by_PnP)
## ▮ Install
```bash
pip3 install calibrating
```
## ▮ Run Example
[Example images](https://github.com/yl-data/calibrating_example_data) are captured by paired_stereo_and_depth_cams:
[](https://github.com/yl-data/calibrating_example_data/raw/master/paired_stereo_and_depth_cams.jpg?raw=true)
```bash
pip3 install calibrating
# Prepare example data(100MB): checkboard images of paired stereo and depth cameras
git clone https://github.com/yl-data/calibrating_example_data
# Prepare example code
git clone https://github.com/DIYer22/calibrating
# Run checkboard example
python3 calibrating/example/checkboard_example.py
```
Finally, your browser will open [stereo-rectify-vis](https://yl-data.github.io/2108.calibrating-vis/stereo/index.html), [reproject-depth-vis](https://yl-data.github.io/2108.calibrating-vis/project-depth/index.html)
Detailed example code with comments: [example/checkboard_example.py](example/checkboard_example.py)
Or Chinese Version: [example/checkboard_example_cn.py (中文注释)](example/checkboard_example_cn.py)
## ▮ Stereo
**Run [stereo example](calibrating/stereo_camera.py):**
```bash
python3 calibrating/calibrating/stereo_camera.py
```
After a while, your browser will open:
- [stereo-rectify-vis](https://yl-data.github.io/2108.calibrating-vis/stereo/index.html)
- [StereoSGBM-depth-vis](https://yl-data.github.io/2108.calibrating-vis/stereo_sgbm_vis/): Which shows `undistort_img1`, `unrectify_depth`. The example disparity is computed by `cv2.StereoSGBM`.
**Another stereo depth example:**
```
python3 calibrating/example/test_depth_accuracy.py
```
your browser will pop up a visual web page like this

**[Mermaid](https://mermaid.live/) flowchart of `calbrating.Stereo.get_depth(img1, img2)`**
```mermaid
flowchart
subgraph "Stereo.get_depth(img1, img2)"
input(Input: \nimg1\nimg2)--> undistort
undistort-->rectify
undistort --> stereo_re
subgraph StereoMatching
end
rectify --> StereoMatching
StereoMatching --disparity--> disp_to_depth
disp_to_depth --depth--> unrectify
unrectify --> stereo_re("Output: \n undistort_img1 \n unrectify_depth")
end
```
## ▮ 3D reconstruction
Convert to NeRF format json for 3D reconstruction.
Usage:
```python
# Convert Cam object's intrinsic/extristric to NeRF fromat json
# Note:
# - When collecting images for reconstruction
# - should fix the calibration board and object, and move the camera
cam.convert_to_nerf_json("transforms.json")
```
Example of converting [ChArUco images](https://github.com/yl-data/calibrating_example_data/tree/master/reconstruction_with_marker_board) to NeRF's transforms.json:
```bash
python calibrating/reconstruction_with_board.py
```
*Reconstruction effect of [instat-ngp](https://github.com/NVlabs/instant-ngp) using ChArUco boards*
## ▮ Multiple Boards
Multiple calibration boards in one image, run [example code](calibrating/multi_boards.py):
```bash
python calibrating/multi_boards.py
```
*visualization example of multiple boards*