This reporsitory aims to provide some scripts for easily doing calibration for stereo camera. Here, I use endoscope calibration case as example. And the nessary steps could be found below.
Our lab's checkerboard could be found here.
cd scripts
For stereo video file, we do following.
# this script will output the information about this stereo video
python checkStereoVideo.py --file stereo_video_file
# follow the information obtained by the previous script
# do the following, and it will seperate the stereo file into left image sequence and right image sequence
python convertStereoVideo2Images.py --file stereo_video_file --save img_sequence_dir --leftroi roix roiy roiw roih --rightroi roix roiy roiw roih [--resize resw resh]
For left video and right video (left view and right view are stored in two videos respectively), we do following.
# check the black boundary of the video
python checkMonoVideo.py --file video0_file
python checkMonoVideo.py --file video1_file
# removing the black boundary and save frames as image sequence
pyhton convertStereoVideo2Images.py --file stereo_video_file --save img_sequence_dir --roi roix roiy roiw roih --rightroi roix roiy roiw roih [--resize resw resh]
There are some other useful script for us to use, like resize an image sequece or select suitable images to calibrate.
# run this for easily select the corresponding images which have the same file name with images in the seleted dir.
python selectCorrespondingStereoImages.py --ref selected_dir --fromdir source_sequence_dir --todir target_selected_dir
# For every image in the sequece, do resize operation and save them.
python resizeImageSequence.py --dir img_seq_dir --save proc_sv_dir --resize resw resh
- Open matlab find
APP/Stereo Camera Calibrator
. Add Images
, input left and right images sequences dir path. Input your checkerboard size.- Select
3 Coefficients
,Tangential Distortion
,Skew
(this option is not necessary). And printCalibrate
button. - You will see the error result in
Reprojection Errors
window. Drop the red line in this window to select the outlier which you want to delete. - Then right click on the image pair you selected, click
Remove and Recalibrate
. Please notice, sometimes, error happens and it maybe do not do recalibrate automatically. In this strange case, you can printCalibrate
button manually (by check or non-check skew, this button will reactivate). - Finally, print
Export Camera Parameters/Export to workspace
, and make sure the stereo parameters variable isstereoParams
and pressOK
. - In the workspace of matlab, make sure the workspace path is in ./scripts/matlab2OpencvYaml, run script
save2yaml
. And you will find an endoscope_calibration.yaml file in ./scripts/matlab2OpencvYaml/out.
- The camera parameters will change when you do crop or resize operation: For cropping,
cx, cy
which change, andcx, cy, fx, fy
will change basing on resize ratio in the case of resize. However,baseline
parameter will never be changed. - The unit of the camera parameters: by our
save2yaml.m
script, the unit ofcx, cy, f
is pixel. Differently, the unit ofbaseline
of stereo camera is millimeter.