Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/piflyer/opencv-video-undistorter
Undistort a video using checkerboard calibration and openCV
https://github.com/piflyer/opencv-video-undistorter
camera-calibration camera-distortion opencv-python video-processing
Last synced: about 2 months ago
JSON representation
Undistort a video using checkerboard calibration and openCV
- Host: GitHub
- URL: https://github.com/piflyer/opencv-video-undistorter
- Owner: Piflyer
- License: mit
- Created: 2022-12-08T22:17:44.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-07T02:20:34.000Z (about 1 year ago)
- Last Synced: 2024-10-12T16:50:49.944Z (3 months ago)
- Topics: camera-calibration, camera-distortion, opencv-python, video-processing
- Language: Python
- Homepage: https://videoundistort.streamlit.app/
- Size: 69.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OpenCV Video Undistorter
This is a simple tool to undistort videos using OpenCV. The program first calibrates the camera using a set of images of a checkerboard to find the intrinsic matrix and distortion parameters. It breaks down each video frame by frame and undistorts each frame using the calibration parameters. The undistorted video is saved to a new file.This project is based on this [OpenCV Calibration Guide.](https://docs.opencv.org/4.x/dc/dbb/tutorial_py_calibration.html) The project is also available on [Streamlit.](https://videoundistort.streamlit.app/).
## Installation
### Prerequisites:* Python 3.9+
* Checkerboard calibration1) Clone the repository
``git clone https://github.com/Piflyer/opencv-video-undistorter``
2) Install the requirements
``pip install -r requirements.txt``
## Usage
### Calibrate and Perform Video Undistortion
``python3 extractandcalib.py --all CB_FOLDER CB_X CB_Y OUTPUT VIDEO``* ``CB_FOLDER``: Folder containing checkerboard images that will be used to compute the camera calibration parameters. The path must end with a wildcard ex. ``/path/to/folder/*``.
* ``CB_X``: Number of inner corners plus one in the checkerboard pattern in the x direction.
* ``CB_Y``: Number of inner corners plus one in the checkerboard pattern in the y direction.
* ``OUTPUT``: Output folder for undistorted images and video.
* ``VIDEO``: Video to be undistorted.
* ``CROP``: Crop the video so that the distorted bounds are non visible. Accepts ``True`` or ``False``.This will perform camera calibration, undistort the video, and save the undistorted video to a new file in the ``OUTPUT`` folder.
### Calibrate Camera
``python3 extractandcalib.py --calibrate CB_FOLDER CB_X CB_Y OUTPUT``
* ``CB_FOLDER``: Folder containing checkerboard images that will be used to compute the camera calibration parameters. The path must end with a wildcard ex. ``/path/to/folder/*``.
* ``CB_X``: Number of inner corners plus one in the checkerboard pattern in the x direction.
* ``CB_Y``: Number of inner corners plus one in the checkerboard pattern in the y direction.
* ``OUTPUT``: Output folder for intrinsic matrix and distortion parameters.This will only perform camera calibration on the checkerboard images and save the intrinsic matrix and distortion parameters to a file in the ``OUTPUT`` folder. These parameters can then be used to undistort videos using the ``--undistort`` option.
### Undistort Video
``python3 extractandcalib.py --videoprocessing VIDEO OUTPUT NAME CROP``
* ``VIDEO``: Video to be undistorted.
* ``OUTPUT``: Output folder for undistorted video.
* ``NAME``: Name of the new video.
* ``CROP``: Crop the video so that the distorted bounds are non visible. Accepts ``True`` or ``False``.This will only undistort the video using the intrinsic matrix and distortion parameters in the ``OUTPUT`` folder. The video will be saved to a new file in the ``OUTPUT`` folder.
### Frames to Video
``python3 extractandcalib.py --frames2video FRAMES_PATH FPS NAME``
* ``FRAMES_PATH``: Path to folder containing undistorted frames. Ideally should be numbered in an increasing sequence.
* ``FPS``: Frames per second of the video.
* ``NAME``: Name of the video file.This will convert the undistorted frames to a video and save it to a new file in the ``OUTPUT`` folder.
## License
[MIT](LICENSE)