1. 程式人生 > >機器視覺課內實驗:一種攝像機標定演算法的程式設計實現

機器視覺課內實驗:一種攝像機標定演算法的程式設計實現

機器視覺課內實驗:一種攝像機標定演算法的程式設計實現

實驗目的

掌握攝像機標定方法的原理,採用一種攝像機標定演算法,程式設計實現攝像機內部引數和外部引數的估計。

.標定原理

攝像機標定是指建立攝像機影象畫素位置與場景點位置之間的關係,其途徑是根據攝像機模型,由已知特徵點的影象座標和世界座標求解攝像機的模型引數。  

.實驗步驟及截圖

   採用張正友攝像機標定演算法,具體步驟如下:

1、採集影象:採集的影象統一命名後,拷貝到toolbox_calib目錄中。

2、在Matlab命令視窗執行calib_gui指令,然後選擇第一項

 3、閱讀圖片,點選“Image names”鍵,在Matlab命令視窗分別輸入Image和影象格式t

 4、提取網格角點。

5、主要校準步驟:點選Calibration來執行主要的攝像機校準程式。

6、點選Reproject on images將網格重新投影到原始影象上。這些投影是根據當前的內、外部引數計算的。

7、重投影誤差也以顏色編碼的十字架的形式顯示:

 8、Show Extrinsic外部引數(網格相對於照相機的相對位置)然後以3D圖的形式顯示若要從“以攝像機為中心”檢視切換到“以世界為中心”檢視,點選Switch to world-centered view

.程式程式碼

>> calib_gui

.            Image10.tif  Image13.tif  Image16.tif  Image19.tif  Image3.tif   Image6.tif   Image9.tif   
..           Image11.tif  Image14.tif  Image17.tif  Image2.tif   Image4.tif   Image7.tif   
Image1.tif   Image12.tif  Image15.tif  Image18.tif  Image20.tif  Image5.tif   Image8.tif   

Basename camera calibration images (without number nor suffix): 
.            Image10.tif  Image13.tif  Image16.tif  Image19.tif  Image3.tif   Image6.tif   Image9.tif   
..           Image11.tif  Image14.tif  Image17.tif  Image2.tif   Image4.tif   Image7.tif   
Image1.tif   Image12.tif  Image15.tif  Image18.tif  Image20.tif  Image5.tif   Image8.tif   
Basename camera calibration images (without number nor suffix): Image
Image format: ([]='r'='ras', 'b'='bmp', 't'='tif', 'p'='pgm', 'j'='jpg', 'm'='ppm') t
Loading image 1...2...3...4...5...6...7...8...9...10...11...12...13...14...15...16...17...18...19...20...
done

Extraction of the grid corners on the images
Number(s) of image(s) to process ([] = all images) = 
Window size for corner finder (wintx and winty):
wintx ([] = 5) = 
winty ([] = 5) = 
Window size = 11x11
Do you want to use the automatic square counting mechanism (0=[]=default)
  or do you always want to enter the number of squares manually (1,other)? 
Processing image 1...
Using (wintx,winty)=(5,5) - Window size = 11x11      (Note: To reset the window size, run script clearwin)
Click on the four extreme corners of the rectangular complete pattern (the first clicked corner is the origin)...
Size dX of each square along the X direction ([]=100mm) = 100
Size dY of each square along the Y direction ([]=100mm) = 100
If the guessed grid corners (red crosses on the image) are not close to the actual corners,
it is necessary to enter an initial guess for the radial distortion factor kc (useful for subpixel detection)
Need of an initial guess for distortion? ([]=no, other=yes) 
Corner extraction...
Processing image 2...

%此處省率從圖2——圖19的分析

Processing image 20...
Using (wintx,winty)=(5,5) - Window size = 11x11      (Note: To reset the window size, run script clearwin)
Click on the four extreme corners of the rectangular complete pattern (the first clicked corner is the origin)...
Size of each square along the X direction: dX=100mm
Size of each square along the Y direction: dY=100mm   (Note: To reset the size of the squares, clear the variables dX and dY)
If the guessed grid corners (red crosses on the image) are not close to the actual corners,
it is necessary to enter an initial guess for the radial distortion factor kc (useful for subpixel detection)
Need of an initial guess for distortion? ([]=no, other=yes) 
Corner extraction...
done
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 by the variable est_dist):
     Sixth order distortion not estimated (est_dist(5)=0) - (DEFAULT) .
Initialization of the principal point at the center of the image.
Initialization of the intrinsic parameters using the vanishing points of planar patterns.
Initialization of the intrinsic parameters - Number of images: 20
Calibration parameters after initialization:

Focal Length:          fc = [ 670.65485   670.65485 ]
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: 20
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...23...24...done
Estimation of uncertainties...done


Calibration results after optimization (with uncertainties):

Focal Length:          fc = [ 662.49524   664.67734 ] +/- [ 1.43401   1.54262 ]
Principal point:       cc = [ 306.51284   241.75114 ] +/- [ 2.83486   2.60830 ]
Skew:             alpha_c = [ 0.00000 ] +/- [ 0.00000  ]   => angle of pixel axes = 90.00000 +/- 0.00000 degrees
Distortion:            kc = [ -0.27907   0.32025   0.00050   0.00028  0.00000 ] +/- [ 0.01144   0.04729   0.00064   0.00067  0.00000 ]
Pixel error:          err = [ 0.59063   0.42184 ]

Note: The numerical errors are approximately three times the standard deviations (for reference).
Number(s) of image(s) to show ([]= all images)=
Invalid image format
Image format: ([]='r'='ras', 'b'='bmp', 't'='tif', 'p'='pgm', 'j'='jpg', 'm'='ppm') Number(s) of image(s) to show ([] = all images) = Number(s) of image(s) to show ([] = all images) = 
Pixel error:      err = [0.59063   0.42184] (all active images)

實驗心得

在本次實驗中我將前面課堂上所講的攝像機的標定成功的通過程式設計實現了,在本次實驗當中應用了張正友平面標定的方法去作為程式設計的演算法基礎,實驗要求通過MATLAB進行結果實現,但由於長時間沒有用過,所以在本次實驗中查資料佔據了我很多時間。在實驗之前,我查了好多關於張正友攝像機標定演算法,感覺實現這此實驗對我來說還是很不容易的。感覺理論和實踐還是相差甚遠。