引言
因為任意旋轉(zhuǎn)矩陣僅有 3 個自由度,因此旋轉(zhuǎn)向量是旋轉(zhuǎn)矩陣的一個方便和最緊湊的表示。在全局 3D 幾何優(yōu)化中常用到旋轉(zhuǎn)矩陣和旋轉(zhuǎn)向量的相互轉(zhuǎn)換,例如相機標(biāo)定、PnP 問題的求解等。本文介紹基于 OpenCV-Python 的互轉(zhuǎn)換實現(xiàn)方法。
方法
◆ Rodrigues()
void cv::Rodrigues(InputArray src,
OutputArray dst,
OutputArray jacobian = noArray()
)
Python:
cv.Rodrigues(src[, dst[, jacobian]]) -> dst, jacobian
參數(shù)詳解:
-
src
:輸入旋轉(zhuǎn)向量(3x1 或 1x3)或旋轉(zhuǎn)矩陣(3x3); -
dst
:輸出旋轉(zhuǎn)矩陣(3x3)或旋轉(zhuǎn)向量(3x1 或 1x3); -
jacobian
:可選輸出,雅可比矩陣,3x9 或 9x3,它是輸出數(shù)組分量相對于輸入數(shù)組分量的偏導(dǎo)數(shù)矩陣。
實驗
通過 OpenCV 提供的 Rodrigues 函數(shù)即可實現(xiàn)旋轉(zhuǎn)矩陣與旋轉(zhuǎn)向量的相互轉(zhuǎn)換。文章來源:http://www.zghlxwxcb.cn/news/detail-517344.html
-
R_vec
:表示旋轉(zhuǎn)向量; -
R_mat
:表示旋轉(zhuǎn)矩陣。
旋轉(zhuǎn)向量?旋轉(zhuǎn)矩陣
>>> import numpy as np
>>> import cv2 as cv
>>> R_vec = np.array([[0.1], [0.1], [0.1]])
>>> R_mat = cv.Rodrigues(R_vec)[0]
>>> R_mat
array([[ 0.99002498, -0.09451324, 0.10448826],
[ 0.10448826, 0.99002498, -0.09451324],
[-0.09451324, 0.10448826, 0.99002498]])
旋轉(zhuǎn)矩陣?旋轉(zhuǎn)向量
>>> import numpy as np
>>> import cv2 as cv
>>> R_mat = np.array([
... [ 0.99002498, -0.09451324, 0.10448826],
... [ 0.10448826, 0.99002498, -0.09451324],
... [-0.09451324, 0.10448826, 0.99002498]])
>>> R_vec = cv.Rodrigues(R_mat)[0]
>>> R_vec
array([[0.1],
[0.1],
[0.1]])
參考
OpenCV: Camera Calibration and 3D Recongtruction文章來源地址http://www.zghlxwxcb.cn/news/detail-517344.html
到了這里,關(guān)于【Python】旋轉(zhuǎn)矩陣與旋轉(zhuǎn)向量的相互轉(zhuǎn)換(OpenCV)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!