This repository provides a sourcecode to calibrate projector-camera system using chessboard and structured light (graycode pattern).
- Python
- Python 3 is recommended
- OpenCV
python -m pip install opencv-python opencv-contrib-python
- Printed chessboard
- You can find PDF here
Open terminal and type the following command.
python gen_graycode_imgs.py <projector_pixel_height> <projector_pixel_width> [-graycode_step <graycode_step(default=1)>]
# example
python gen_graycode_imgs.py 768 1024 -graycode_step 1
Generated pattern images will be saved in ./graycode_pattern/
.
graycode_step
is an option to specify pixel size of a bit in the graycode.
If you get moire pattern in captured images, increase this number.
Setup your system and place the chessboard in front of the projector and the camera. Then, project the graycode pattern images from projector on it and capture it from the camera.
Although minimum required shot is one, it is recommended to capture more than 5 times with different attitude of the chessboard to improve calibration accuracy.
Captured images must be saved as ./capture_*/graycode_*.(png/jpg)
.
After saving captured images, run the following command.
python calibrate.py <projector_pixel_height> <projector_pixel_width> <num_chess_corners_vert> <num_chess_corners_hori> <chess_block_size> <graycode_step> [-black_thr <black_thr(default=40)>] [-white_thr <white_thr(default=5)>]
# example (you can test this command in the sample_data directory)
python ../calibrate.py 768 1024 9 7 75 1 -black_thr 40 -white_thr 5
chess_block_size
means length (mm/cm/m) of a block on the chessboard.
Result of the translation vector will be calculated with the length unit specified here.
black_threashold
is a threashold to determine whether a camera pixel captures projected area or not.
white_threashold
is a threashold to specify robustness of graycode decoding.
To avoid decoding error, increase these numbers.
Calibration result will be saved as ./calibration_result.xml
(cv::FileStorage format).
This software calculates local homographies at around chessboard corners to estimate corresponding projector pixels with subpixel accuracy. This algorithm is based on the following paper.
MORENO, Daniel; TAUBIN, Gabriel. Simple, accurate, and robust projector-camera calibration. In: 3D Imaging, Modeling, Processing, Visualization and Transmission (3DIMPVT), 2012 Second International Conference on. IEEE, 2012. p. 464-471.