手眼标定笔记
文章目錄
- 基本介紹:
- 坐標(biāo)系變換運(yùn)算規(guī)則:
- 關(guān)系運(yùn)算說明:
- 坐標(biāo)系運(yùn)算規(guī)則一:
- 坐標(biāo)系運(yùn)算規(guī)則二:
- 齊次坐標(biāo)系:
- 齊次坐標(biāo)系下的坐標(biāo)變換:
- 眼在手外:
- 眼在手內(nèi):
- 解方程:
- - Tais方法
- 使用opencv完成手眼標(biāo)定
- 歐拉角變換為旋轉(zhuǎn)矩陣:
- 旋轉(zhuǎn)矩陣變成歐拉角:
- 易錯點(diǎn):
基本介紹:
-
眼在手外(eye to hand):
相機(jī)固定在機(jī)械臂以外的地方,主要標(biāo)定相機(jī)和基底坐標(biāo)系的轉(zhuǎn)換矩陣。
-
眼在手上(eye in hand):
相機(jī)固定在機(jī)械臂末端,主要標(biāo)定相機(jī)和機(jī)械臂末端的轉(zhuǎn)換矩陣。
坐標(biāo)系變換運(yùn)算規(guī)則:
endbaseR_{end}^{base}Rendbase?R:機(jī)械臂末端坐標(biāo)系到機(jī)械臂基底坐標(biāo)系的旋轉(zhuǎn)矩陣
endbaseT_{end}^{base}Tendbase?T:機(jī)械臂末端坐標(biāo)系到機(jī)械臂基底坐標(biāo)系的平移矩陣
endbaseM=[endbaseRendbaseT01]_{end}^{base}M = \begin{bmatrix} _{end}^{base}R & _{end}^{base}T \\ 0 & 1 \end{bmatrix}endbase?M=[endbase?R0?endbase?T1?]:機(jī)械臂末端坐標(biāo)系到機(jī)械臂基底坐標(biāo)系變換矩陣
以上等價于:機(jī)械臂末端坐標(biāo)系在基底坐標(biāo)系下的描述
關(guān)系運(yùn)算說明:
endbaseR=baseendR?1endbaseM=baseendM?1endbaseT={=?baseendTifendbaseR=baseendR=I≠?baseendTifendbaseR≠baseendR≠I_{end}^{base}R = ^{end}_{base}R^{-1} \\ _{end}^{base}M = ^{end}_{base}M^{-1} \\ _{end}^{base}T=\left\{ \begin{aligned} = & -^{end}_{base}T\quad if \quad_{end}^{base}R = ^{end}_{base}R = I \\ \neq & -^{end}_{base}T\quad if \quad _{end}^{base}R \neq ^{end}_{base}R \neq I \end{aligned} \right. endbase?R=baseend?R?1endbase?M=baseend?M?1endbase?T={=?=??baseend?Tifendbase?R=baseend?R=I?baseend?Tifendbase?R?=baseend?R?=I?
由于R是正交矩陣,正交矩陣的逆=正交矩陣的轉(zhuǎn)置,所以有時候也會寫為endbaseR=baseendRT^{base}_{end}R = ^{end}_{base}R^Tendbase?R=baseend?RT
坐標(biāo)系運(yùn)算規(guī)則一:
假設(shè)有兩個坐標(biāo)系A(chǔ),B,其中坐標(biāo)系B中的點(diǎn)b是由坐標(biāo)系A(chǔ)中的點(diǎn)a轉(zhuǎn)換來的,則點(diǎn)a和點(diǎn)b之間有如下等式
a=BAR?b+BATb=ABR?a+ABTa = {^A_B}R * b + {^A_B}T \\ b = {^B_A}R * a + {^B_A}T a=BA?R?b+BA?Tb=AB?R?a+AB?T
由以上等式可以看出:
a=ABR?1(b?ABT)=ABR?1b?ABR?1ABT=ABR?1b+BATBAT=?ABR?1ABTa = {^B_A}R^{-1}(b-{^B_A}T) \\ \quad\quad\;\,= {^B_A}R^{-1}b-{^B_A}R^{-1}{^B_A}T\\ \,= {^B_A}R^{-1}b+{^A_B}T \\ {^A_B}T = -{^B_A}R^{-1}{^B_A}T a=AB?R?1(b?AB?T)=AB?R?1b?AB?R?1AB?T=AB?R?1b+BA?TBA?T=?AB?R?1AB?T
坐標(biāo)系運(yùn)算規(guī)則二:
假設(shè)由三個坐標(biāo)系A(chǔ),B,C,已知如下關(guān)系:BAR,BAT,CBR,CBT{^A_B}R,{^A_B}T,{^B_C}R,{^B_C}TBA?R,BA?T,CB?R,CB?T,求CAR,CAT{^A_C}R,{^A_C}TCA?R,CA?T
對于旋轉(zhuǎn)矩陣RRR: CAR=BAR?CBR{^A_C}R = {^A_B}R*{^B_C}RCA?R=BA?R?CB?R
對于平移矩陣TTT:CAT=BAT+BARCBT{^A_C}T = {^A_B}T+{^A_B}R\;{^B_C}TCA?T=BA?T+BA?RCB?T 形式麻煩!
齊次坐標(biāo)系:
齊次坐標(biāo)系下的坐標(biāo)變換:
a=BAM?bb=CBM?ca=BAM?CBM?ca = {^A_B}M * b\\ b = {^B_C}M * c\\ a = {^A_B}M * {^B_C}M *c a=BA?M?bb=CB?M?ca=BA?M?CB?M?c
眼在手外:
求解目標(biāo):機(jī)械臂基底坐標(biāo)系到相機(jī)坐標(biāo)系的變換矩陣basecameraM^{camera}_{base}Mbasecamera?M
手眼標(biāo)定坐標(biāo)系表示:
- 機(jī)械臂基底坐標(biāo)系 – base
- 機(jī)械臂末端坐標(biāo)系 – end
- 相機(jī)坐標(biāo)系 – camera
- 標(biāo)定板坐標(biāo)系 – board
實(shí)現(xiàn)方法:
則對每張圖片可知:basecameraM=boardcameraM?endboardM?baseendM^{camera}_{base}M = \;^{camera}_{board}M * \; ^{board}_{end}M * \;^{end}_{base}Mbasecamera?M=boardcamera?M?endboard?M?baseend?M
變形得:
? endboardM=boardcameraM?1?basecameraM?baseendM?1^{board}_{end}M = \;^{camera}_{board}M^{-1} * \;^{camera}_{base}M * \;^{end}_{base}M^{-1}endboard?M=boardcamera?M?1?basecamera?M?baseend?M?1
其中:
? boardcameraM:^{camera}_{board}M:boardcamera?M: 可由通過拍攝的標(biāo)定板圖片直接求解
? baseendM:^{end}_{base}M:baseend?M: 可由機(jī)械臂末端位姿參數(shù)求得
? endboardM:^{board}_{end}M:endboard?M: 未知量,由于標(biāo)定板固定在機(jī)械臂末端,所以對每組圖片,該轉(zhuǎn)換矩陣都相同
已知對每張圖片:
endboardM=boardcameraM?1?basecameraM?baseendM?1^{board}_{end}M = \;^{camera}_{board}M^{-1} * \;^{camera}_{base}M * \;^{end}_{base}M^{-1} endboard?M=boardcamera?M?1?basecamera?M?baseend?M?1
**則可以得到如下等式:**左乘boardcameraM2^{camera}_{board}M_2boardcamera?M2? 右乘baseendM1^{end}_{base}M_1baseend?M1?
眼在手內(nèi):
求解目標(biāo):機(jī)械臂末端坐標(biāo)系到相機(jī)坐標(biāo)系的變換矩陣endcameraM^{camera}_{end}Mendcamera?M
手眼標(biāo)定坐標(biāo)系表示:
- 機(jī)械臂基底坐標(biāo)系 – base
- 機(jī)械臂末端坐標(biāo)系 – end
- 相機(jī)坐標(biāo)系 – camera
- 標(biāo)定板坐標(biāo)系 – board
實(shí)現(xiàn)方法:
則對每張圖片可知:endcameraM=boardcameraM?baseboardM?endbaseM^{camera}_{end}M = \;^{camera}_{board}M * \; ^{board}_{base}M * \;^{base}_{end}Mendcamera?M=boardcamera?M?baseboard?M?endbase?M
變形得:
? baseboardM=boardcameraM?1?endcameraM?endbaseM?1^{board}_{base}M = \;^{camera}_{board}M^{-1} * \;^{camera}_{end}M * \;^{base}_{end}M^{-1}baseboard?M=boardcamera?M?1?endcamera?M?endbase?M?1
其中:
? boardcameraM:^{camera}_{board}M:boardcamera?M: 可由通過拍攝的標(biāo)定板圖片直接求解
? baseendM:^{end}_{base}M:baseend?M: 可由機(jī)械臂末端位姿參數(shù)求得
? baseboardM:^{board}_{base}M:baseboard?M: 未知量,由于標(biāo)定板全程固定在一個位置不動,所以對每組圖片,該轉(zhuǎn)換矩陣都相同
已知對每張圖片:
baseboardM=boardcameraM?1?endcameraM?endbaseM?1^{board}_{base}M = \;^{camera}_{board}M^{-1} * \;^{camera}_{end}M * \;^{base}_{end}M^{-1} baseboard?M=boardcamera?M?1?endcamera?M?endbase?M?1
**則可以得到如下等式:**左乘boardcameraM2^{camera}_{board}M_2boardcamera?M2? 右乘endbaseM1^{base}_{end}M_1endbase?M1?
解方程:
? 無論是眼在手外還是眼在手內(nèi),都可以得到一個經(jīng)典的方程組AX=XBAX=XBAX=XB,這個方程組有n-1個方程 (n是拍攝的圖片數(shù)量)
? 其中X是我們要求得的手眼矩陣,里面有6個線性無關(guān)的變量,其中旋轉(zhuǎn)3個自由度,平移3個自由度。
- Tais方法
**形式變換:**由于A,B,X均為變換矩陣
A=[RATA01]B=[RBTB01]X=[RXTX01]A = \begin{bmatrix} R_A & T_A \\ 0 & 1 \end{bmatrix} \qquad B = \begin{bmatrix} R_B & T_B \\ 0 & 1 \end{bmatrix} \qquad X = \begin{bmatrix} R_X & T_X \\ 0 & 1 \end{bmatrix} A=[RA?0?TA?1?]B=[RB?0?TB?1?]X=[RX?0?TX?1?]
則AX=XBAX=XBAX=XB可以拆解成如下兩個等式
{RARX=RXRB(RA?1)TX=RXTB?TA\left\{ \begin{aligned} R_AR_X & =R_XR_B \\ (R_A-1)T_X & =R_XT_B-T_A \\ \end{aligned} \right. {RA?RX?(RA??1)TX??=RX?RB?=RX?TB??TA??
Tais方法:先求解Rx,再求解Tx
旋轉(zhuǎn)的表示:
? **旋轉(zhuǎn)矩陣:**3*3矩陣R=RzRyRxR = R_zR_yR_xR=Rz?Ry?Rx?
? 旋轉(zhuǎn)向量:r=(xyz)θ=norm(r)r = (x\;y\;z) \quad \theta = norm(r)r=(xyz)θ=norm(r)
? 剛體繞旋轉(zhuǎn)軸旋轉(zhuǎn),rrr表示的是旋轉(zhuǎn)軸的方向,rrr的長度表示剛體繞旋轉(zhuǎn)軸的角度
? 旋轉(zhuǎn)角:θ=(θxθyθz)\theta = (\theta_x \; \theta_y \; \theta_z)θ=(θx?θy?θz?)
? 旋轉(zhuǎn)角又稱歐拉角,一般情況下旋轉(zhuǎn)角指的是坐標(biāo)系繞x軸旋轉(zhuǎn)后,再繞y軸旋轉(zhuǎn)后,再繞z軸旋轉(zhuǎn)分別的角度
使用opencv完成手眼標(biāo)定
歐拉角變換為旋轉(zhuǎn)矩陣:
Rx(θx)=[1000cosθx?sinθx0sinθxcosθx]Ry(θy)=[cosθy0sinθy010?sinθy0cosθy]Rz(θz)=[cosθz?sinθz0sinθzcosθz0001]R=RzRyRxR_x(\theta_x) = \begin{bmatrix} 1 & 0 & 0 \\ 0 & cos\theta_x & -sin\theta_x \\ 0 & sin\theta_x & cos\theta_x\end{bmatrix} \\R_y(\theta_y) = \begin{bmatrix} cos\theta_y & 0 & sin\theta_y \\ 0 & 1 & 0 \\ -sin\theta_y & 0 & cos\theta_y\end{bmatrix} \\ R_z(\theta_z) = \begin{bmatrix} cos\theta_z & -sin\theta_z & 0 \\ sin\theta_z & cos\theta_z & 0 \\ 0 & 0 & 1\end{bmatrix}\\R = R_zR_yR_xRx?(θx?)=???100?0cosθx?sinθx??0?sinθx?cosθx?????Ry?(θy?)=???cosθy?0?sinθy??010?sinθy?0cosθy?????Rz?(θz?)=???cosθz?sinθz?0??sinθz?cosθz?0?001????R=Rz?Ry?Rx?
旋轉(zhuǎn)矩陣變成歐拉角:
R=[r11r12r13r21r22r23r31r32r33]R = \begin{bmatrix} r_{11} & r_{12} & r_{13} \\ r_{21} & r_{22} & r_{23} \\ r_{31} & r_{32} & r_{33}\end{bmatrix}R=???r11?r21?r31??r12?r22?r32??r13?r23?r33?????
θZ=atan2(r21,r11)θY=atan2(?r31,r312+r332)θX=atan2(r32,r33)\theta_Z = atan2(r_{21},r_{11}) \\ \theta_Y = atan2(-r_{31},\sqrt{r^2_{31}+r^2_{33}}) \\ \theta_X = atan2(r_{32},r_{33})θZ?=atan2(r21?,r11?)θY?=atan2(?r31?,r312?+r332??)θX?=atan2(r32?,r33?)
solvePnP()
bool cv::solvePnP(InputArray objectPoints,InputArray imagePoints,InputArray cameraMatrix, // 相機(jī)內(nèi)參InputArray distCoeffs, // 相機(jī)畸變系數(shù)OutputArray rvec, // ROutputArray objectPoints, // Tbool useExtrinsicGuess = false,int flags = SOLVEPNP_ITERATIVE)易錯點(diǎn):
1. 利用calibrateCamera函數(shù)中計算的R、T,來作為標(biāo)定板坐標(biāo)系到相機(jī)坐標(biāo)系的輸入
? 問題分析:對手眼標(biāo)定來說,這個R、T沒有問題。但是由于后續(xù)的抓取來說,使用的物體三維坐標(biāo)是相機(jī)重建的點(diǎn)云,即相機(jī)之前標(biāo)定的內(nèi)參下的點(diǎn)云。此時手眼標(biāo)定的相機(jī)坐標(biāo)系和實(shí)際抓取使用的相機(jī)坐標(biāo)系輕微的不一致,導(dǎo)致抓取總是有輕微誤差。
2. 識別標(biāo)定板角點(diǎn)方向反了!
? 由于在建立棋盤格上的三維坐標(biāo)系的時候,我們默認(rèn)是從棋盤格左上角到右下角建立的,如果識別反了,則會有個別圖片棋盤格識別的角點(diǎn)和輸入的棋盤格三維坐標(biāo)對應(yīng)不上!
本篇為觀看b站視頻的筆記
在此附上原視頻地址:
手眼標(biāo)定–原理與實(shí)戰(zhàn)
總結(jié)
- 上一篇: Halcon之单相机标定
- 下一篇: Ubuntu 磁盘管理 命令行工具