2021 Jan 7
see http://www.cse.cuhk.edu.hk/~khwong/www2/cmsc5711/demo_camcal_from_webcam3.py
Older:
2020 Feb 18
camera calibration demo by opencv-python
-------------------------------------------------
download (clone) files from https://github.com/opencv/opencv
download the whole \opencv-master
1) you at least need 2 python files from opencv-master\samples:
calibrate.py and common.py
2) and image data files from
opencv-master\samples\data
and /left01.jpg-->/left14.jpg
-------------------------------------
Create 2 directories, calibrate_py_demo and data, such that
keep the directory structure with the files shown below
calibrate_py_demo\calibrate.py
calibrate_py_demo\data\left01.jpg-->/left14.jpg (at lease 5 files)
then run in python
> cd calibrate_py,
> python calibrate.py
============ output -============-
you will get result
camera matrix:
[[532.79536562 0. 342.4582516 ]
[ 0. 532.91928338 233.90060514]
[ 0. 0. 1. ]]
distortion coefficients: [-2.81086258e-01 2.72581018e-02 1.21665908e-03 -1.34204275e-04
1.58514022e-01]
undistributed images are saved in ..\data\output
=====================screen output ============
runfile('D:/_tensorflow_proj/opencv_test20/calibrate_py_demo/calibrate_py/calibrate.py', wdir='D:/_tensorflow_proj/opencv_test20/calibrate_py_demo/calibrate_py')
Reloaded modules: common
camera calibration for distorted images with chess board samples
reads distorted images, calculates the calibration and write undistorted images
usage:
calibrate.py [--debug <output path>] [--square_size] [<image mask>]
default values:
--debug: ./output/
--square_size: 1.0
<image mask> defaults to ../data/left*.jpg
Run with 4 threads...
processing ../data\left01.jpg... processing ../data\left02.jpg...
processing ../data\left03.jpg...
processing ../data\left04.jpg...
../data\left04.jpg... OK
processing ../data\left05.jpg...
../data\left03.jpg... OK
processing ../data\left06.jpg... ../data\left01.jpg... OK
processing ../data\left07.jpg...
../data\left02.jpg... OK
processing ../data\left08.jpg...
../data\left05.jpg... OK
processing ../data\left09.jpg...
../data\left07.jpg... OK ../data\left08.jpg... OK
processing ../data\left11.jpg...
processing ../data\left12.jpg...
../data\left06.jpg... OK
processing ../data\left13.jpg...
../data\left09.jpg... OK
processing ../data\left14.jpg...
../data\left12.jpg... OK
../data\left11.jpg... OK
../data\left13.jpg... OK
../data\left14.jpg... OK
RMS: 0.1964379089033398
camera matrix:
[[532.79536562 0. 342.4582516 ]
[ 0. 532.91928338 233.90060514]
[ 0. 0. 1. ]]
distortion coefficients: [-2.81086258e-01 2.72581018e-02 1.21665908e-03 -1.34204275e-04
1.58514022e-01]
Undistorted image written to: ./output/left01_undistorted.png
Undistorted image written to: ./output/left02_undistorted.png
Undistorted image written to: ./output/left03_undistorted.png
Undistorted image written to: ./output/left04_undistorted.png
Undistorted image written to: ./output/left05_undistorted.png
Undistorted image written to: ./output/left06_undistorted.png
Undistorted image written to: ./output/left07_undistorted.png
Undistorted image written to: ./output/left08_undistorted.png
Undistorted image written to: ./output/left09_undistorted.png
Undistorted image written to: ./output/left11_undistorted.png
Undistorted image written to: ./output/left12_undistorted.png
Undistorted image written to: ./output/left13_undistorted.png
Undistorted image written to: ./output/left14_undistorted.png
Done