matlab calibration toolbox -- matlab標定工具的使用方法--去畸變和雙目校正

matlab calibration toolbox是相機標定以及校正用的工具箱。首先下載這個工具箱,免費下載地址:http://www.vision.caltech.edu/bouguetj/calib_doc/download/index.html。它的英文使用示例在下面這個網址上有:http://www.vision.caltech.edu/bouguetj/calib_doc/

 

        一、             對於單目標定。

       1 也就是單個相機的標定,首先是用一個相機拍攝標定板獲得一定數量的標定板照片。或者下載的一定數量的照片。如下:



上圖CMOS0是相機1拍攝的圖片序列,CMOS1是相機2拍攝的圖片序列。

 

       2將下載的toolbox文件解壓到一個目錄下,支持5.x--8.x版本的matlab。然後打開matlab軟件:file—>SetPath出現如下界面。Add Folder添加toolbox所在的路徑。

       3添加好後,就可以在MATLAB的命令欄中輸入calib_gui 或者calib,回車,運行標定程序。


       回車後出現如下界面:


 

       4選擇圖片進行角點檢測。選擇第一項“Standard(all the images are stored in memory)”,出現如下界面:



此時要保證“Current Directory”爲圖片所在的目錄:


點擊“Image Names”按鈕。Command行裏就會將此目錄下所有的照片名字讀出來,如下:


“Basename camera calibration images (without number nor suffix):”後面輸入:CMOS0_。

出現如下提示:


“Image format: ([]='r'='ras', 'b'='bmp', 't'='tif', 'p'='pgm','j'='jpg', 'm'='ppm')”後面輸入:b。

matlab就將加載所有符合條件的圖片。



之後就是檢測角點,點擊第三項:“Extract grid corners ”:


                                                 

 

回車,選擇所有照片。


兩次回車,選擇默認窗口大小。


再回車,命令行出現如下:


同時,出現圖片:


此時需要在圖片上選擇四個拐點,選擇的方法是鼠標單擊拐角位置。按照左上—右上—右下—左下的順時針順序圍一個框:



回車,檢測到角點如下圖:



         再回車,自動出現下一張圖片,直到所有圖片均被檢測完畢。


        此時出現這個文件:



        5標定並查看標定結果。點擊“Calibration”,命令行裏面就會顯示標定結果包括內參和畸變係數:

Calibration parameters afterinitialization:

 

Focal Length:          fc = [ 1086.72277   1086.72277 ]

Principal point:       cc = [ 319.50000   239.50000 ]

Skew:             alpha_c = [ 0.00000 ]   => angle of pixel = 90.00000 degrees

Distortion:            kc = [ 0.00000   0.00000  0.00000   0.00000   0.00000 ]

 

Main calibration optimization procedure -Number of images: 15

Gradient descent iterations:1...2...3...4...5...6...7...8...9...10...11...12...13...14...15...16...17...18...19...20...21...22...done

Estimation of uncertainties...done

 

 

Calibration results after optimization(with uncertainties):

 

Focal Length:          fc = [ 1146.29229   1147.83468 ] ?[ 11.51067   11.19871 ]

Principal point:       cc= [ 304.04991   233.16189 ] ?[8.23084   6.14044 ]

Skew:             alpha_c = [ 0.00000 ] ?[0.00000  ]   => angle of pixel axes = 90.00000?0.00000 degrees

Distortion:            kc = [ -0.36478   1.07508  -0.00016   -0.00147  0.00000 ] ?[ 0.04196   0.67100  0.00120   0.00095  0.00000 ]

Pixel error:          err = [ 0.54502   0.23183 ]

 

Note: The numerical errors areapproximately three times the standard deviations (for reference).

 

標定結果分爲優化前和優化後的兩個結果。

             點擊出現如下界面,從相機的視角(即保持相機的位置和方向不變)展示被標定圖像相對於相機的位置:


           點擊“Save”按鈕,在目錄中保存標定的結果,出現如下文件:


注:Result的mat文件在雙目標定中能夠用到。將"Calib_Results.mat"改成"Calib_Results_left.mat "。

點擊就會提示選擇一張圖片計算它的外參。

         6去畸變。點擊就會提示選擇將所有標定的圖片進行去畸變,或者是選擇一張新的圖片進行去畸變。直接回車,就會將所有標定的圖片的去畸變圖片以“CMOS0__rect1.bmp”這個形式的文件名命名並保存在圖片的目錄下面如下圖。

 

CMOS0_1.bmp--原圖


CMOS0__rect1.bmp去畸變後圖

 

 

二、雙目校正。

        1用同樣的方法,對右相機拍攝的圖像進行同樣的標定。

標定結果:

Aspect ratio optimized (est_aspect_ratio =1) -> both components of fc are estimated (DEFAULT).

Principal point optimized (center_optim=1)- (DEFAULT). To reject principal point, set center_optim=0

Skew not optimized (est_alpha=0) -(DEFAULT)

Distortion not fully estimated (defined bythe variable est_dist):

    Sixth order distortion not estimated (est_dist(5)=0) - (DEFAULT) .

Initialization of the principal point atthe center of the image.

Initialization of the intrinsic parametersusing the vanishing points of planar patterns.

 

Initialization of the intrinsic parameters- Number of images: 15

 

 

Calibration parameters afterinitialization:

 

Focal Length:          fc = [ 1094.51360   1094.51360 ]

Principal point:       cc = [ 319.50000   239.50000 ]

Skew:             alpha_c = [ 0.00000 ]   => angle of pixel = 90.00000 degrees

Distortion:            kc = [ 0.00000   0.00000  0.00000   0.00000   0.00000 ]

 

Main calibration optimization procedure -Number of images: 15

Gradient descent iterations:1...2...3...4...5...6...7...8...9...10...11...12...13...14...15...16...17...18...19...20...21...22...done

Estimation of uncertainties...done

 

 

Calibration results after optimization(with uncertainties):

 

Focal Length:          fc = [ 1153.56062   1153.70663 ] ?[ 5.52064   5.37363 ]

Principal point:       cc = [ 307.59643   201.79164 ] ?[ 4.00096   2.92143 ]

Skew:             alpha_c = [ 0.00000 ] ?[0.00000  ]   => angle of pixel axes = 90.00000?0.00000 degrees

Distortion:            kc = [ -0.41467   0.77106  -0.00200   -0.00188  0.00000 ] ?[ 0.02287   0.37580  0.00051   0.00051  0.00000 ]

Pixel error:          err = [ 0.21001   0.18752 ]

 

Note: The numerical errors areapproximately three times the standard deviations (for reference).

並將標定的結果保存爲Calib_Results_right.mat

則由左右相機標定的結果爲“Calib_Results_left.mat”和“Calib_Results_right.mat”。

        2計算雙目校正的參數。在command的命令欄裏,輸入“stereo_gui.m”出現如下界面:


              將”Current Directory“設置爲圖片所在的目錄,點擊:“Load left and right calibration files”按鈕,命令欄會提示,先輸入Calib_Results_left.mat,回車,再輸入Calib_Results_right.mat,回車。如下:

Calib_Results_left.mat   calib_data_left.mat     

Calib_Results_right.mat  calib_data_right.mat    

 

Loading of the individual left and rightcamera calibration files

Name of the left camera calibration file([]=Calib_Results_left.mat): Calib_Results_left.mat

Name of the right camera calibration file([]=Calib_Results_right.mat): Calib_Results_right.mat

 

               回車,出現如下結果:

Intrinsic parameters of left camera:

 

Focal Length:          fc_left = [ 1146.29229   1147.83468 ] ?[ 11.51067   11.19871 ]

Principal point:       cc_left = [ 304.04991   233.16189 ] ?[ 8.23084   6.14044 ]

Skew:             alpha_c_left = [ 0.00000 ] ?[0.00000  ]   => angle of pixel axes = 90.00000?0.00000 degrees

Distortion:            kc_left = [ -0.36478   1.07508  -0.00016   -0.00147  0.00000 ] ?[ 0.04196   0.67100  0.00120   0.00095  0.00000 ]

 

 

Intrinsic parameters of right camera:

 

Focal Length:          fc_right = [ 1153.56062   1153.70663 ] ?[ 5.52064   5.37363 ]

Principal point:       cc_right = [ 307.59643   201.79164 ] ?[ 4.00096   2.92143 ]

Skew:             alpha_c_right = [ 0.00000 ] ?[0.00000  ]   => angle of pixel axes = 90.00000?0.00000 degrees

Distortion:            kc_right = [ -0.41467   0.77106  -0.00200   -0.00188  0.00000 ] ?[ 0.02287   0.37580  0.00051   0.00051  0.00000 ]

 

 

Extrinsic parameters (position of rightcamera wrt left camera):

 

Rotation vector:             om = [ 0.02179   -0.01185 0.01145 ]

Translation vector:           T = [ 288.71955   -4.79691 8.65882 ]

                 點擊按鈕,得到優化的結果:

Recomputation of the intrinsic parametersof the left camera (recompute_intrinsic_left = 1)

 

Recomputation of the intrinsic parametersof the right camera (recompute_intrinsic_right = 1)

 

Main stereo calibration optimizationprocedure - Number of pairs of images: 15

Gradient descent iterations: 1...done

Estimation of uncertainties...done

 

 

 

Stereo calibration parameters afteroptimization:

 

 

Intrinsic parameters of left camera:

 

Focal Length:          fc_left = [ 1148.55963   1149.64262 ] ?[ 7.45634   7.30037 ]

Principal point:       cc_left = [ 310.26705   238.04925 ] ?[ 7.04971   5.09296 ]

Skew:             alpha_c_left = [ 0.00000 ] ?[0.00000  ]   => angle of pixel axes = 90.00000?0.00000 degrees

Distortion:            kc_left = [ -0.34370   0.76402  -0.00169   -0.00056  0.00000 ] ?[ 0.03451   0.53433  0.00090   0.00077  0.00000 ]

 

 

Intrinsic parameters of right camera:

 

Focal Length:          fc_right = [ 1150.39567   1150.10073 ] ?[ 7.17569   6.99235 ]

Principal point:       cc_right = [ 302.34812   193.42732 ] ?[ 7.17158   4.95445 ]

Skew:             alpha_c_right = [ 0.00000 ] ?[0.00000  ]   => angle of pixel axes = 90.00000?0.00000 degrees

Distortion:            kc_right = [ -0.41255   0.86324  -0.00104   -0.00290  0.00000 ] ?[ 0.03845   0.60909  0.00084   0.00082  0.00000 ]

 

 

Extrinsic parameters (position of rightcamera wrt left camera):

 

Rotation vector:             om = [ 0.01223   0.00022 0.01149 ] ?[ 0.00584   0.00846  0.00023 ]

Translation vector:           T = [ 278.99648   3.79371 -16.83653 ] ?[ 2.50669  2.11662  17.55917 ]

 

 

Note: The numerical errors areapproximately three times the standard deviations (for reference).

 

        3進行雙目校正即平行校正。點擊按鈕:command行中出現如下

校正的圖片就在圖片所在的目錄下如下:

以“CMOS0__rectified1.bmp”和“CMOS1__rectified1.bmp”爲命名成對出現的。如:


 CMOS0__rectified2.bmp左圖校正後


CMOS1__rectified2右圖校正後

             這樣就進行完立體校正了。這兩幅圖像就是平行的了。

            Matlab將上述左右兩幅圖像放在一起對比平行如下圖:


            這兩幅圖片對應的原始圖像如下:


CMOS0_2.bmp左原圖



 CMOS1_2.bmp右原圖


             當然還有很多其他按鈕以及對應的功能,大家都可以親自試一試。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章