OpenCV 5.0.0
Open Source Computer Vision
読み込み中...
検索中...
見つかりません
🤖 AIによる機械翻訳(非公式) — これは OpenCV 5.0.0 公式リファレンス(英語)を AI (Claude) で自動翻訳したものです。訳に誤りを含む場合があります。正確な情報は 公式英語版(原文) を参照してください。
3Dビジョン機能

詳細説明

本節のほとんどの関数は、いわゆるピンホールカメラモデルを使用する。シーンのビューは、シーンの3D点 \(P_w\) を透視変換によって画像平面に投影し、対応するピクセル \(p\) を形成することで得られる。\(P_w\) と \(p\) はいずれも同次座標、すなわちそれぞれ3Dおよび2Dの同次ベクトルとして表される。射影幾何学、同次ベクトル、同次変換についての簡単な導入は、本節の導入の末尾にある。より簡潔な表記のため、しばしば「同次」を省略し、同次ベクトルを単にベクトルと呼ぶ。

ピンホールカメラモデルによって与えられる歪みのない射影変換を以下に示す。

\[s \; p = A \begin{bmatrix} R|t \end{bmatrix} P_w,\]

ここで \(P_w\) はワールド座標系に対して表現された3D点、\(p\) は画像平面上の2Dピクセル、\(A\) はカメラ内部行列、\(R\) と \(t\) はワールド座標系からカメラ座標系(またはカメラフレーム)への座標変換を表す回転と並進であり、\(s\) は射影変換の任意のスケーリングであってカメラモデルの一部ではない。

カメラ内部行列 \(A\) ([328] と同じ表記で、一般には \(K\) とも表記される) は、カメラ座標系で与えられた3D点を2Dピクセル座標へ投影する。すなわち、

\[p = A P_c.\]

カメラ内部行列 \(A\) は、ピクセル単位で表される焦点距離 \(f_x\) と \(f_y\)、および通常は画像中心に近い主点 \((c_x, c_y)\) で構成される:

\[A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1},\]

したがって

\[s \vecthree{u}{v}{1} = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1} \vecthree{X_c}{Y_c}{Z_c}.\]

内部パラメータの行列は、見ているシーンに依存しない。そのため、いったん推定すれば、(ズームレンズの場合)焦点距離が固定されている限り再利用できる。したがって、カメラからの画像がある係数でスケールされた場合、これらのパラメータはすべて同じ係数でスケール(それぞれ乗算/除算)する必要がある。

回転・並進を結合した行列 \([R|t]\) は、射影変換と同次変換の行列積である。3行4列の射影変換は、カメラ座標系で表現された3D点を画像平面上の2D点に写像し、正規化カメラ座標 \(x' = X_c / Z_c\) および \(y' = Y_c / Z_c\) で表す。

\[Z_c \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix} \begin{bmatrix} X_c \\ Y_c \\ Z_c \\ 1 \end{bmatrix}.\]

同次変換は外部パラメータ \(R\) と \(t\) によって表され、ワールド座標系 \(w\) からカメラ座標系 \(c\) への基底変換を表す。したがって、ワールド座標における点 \(P\) の表現 \(P_w\) が与えられると、カメラ座標系における \(P\) の表現 \(P_c\) は次のように得られる。

\[P_c = \begin{bmatrix} R & t \\ 0 & 1 \end{bmatrix} P_w,\]

この同次変換は、3行3列の回転行列 \(R\) と、3行1列の並進ベクトル \(t\) から構成される。

\[\begin{bmatrix} R & t \\ 0 & 1 \end{bmatrix} = \begin{bmatrix} r_{11} & r_{12} & r_{13} & t_x \\ r_{21} & r_{22} & r_{23} & t_y \\ r_{31} & r_{32} & r_{33} & t_z \\ 0 & 0 & 0 & 1 \end{bmatrix}, \]

したがって

\[\begin{bmatrix} X_c \\ Y_c \\ Z_c \\ 1 \end{bmatrix} = \begin{bmatrix} r_{11} & r_{12} & r_{13} & t_x \\ r_{21} & r_{22} & r_{23} & t_y \\ r_{31} & r_{32} & r_{33} & t_z \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} X_w \\ Y_w \\ Z_w \\ 1 \end{bmatrix}.\]

射影変換と同次変換を組み合わせると、ワールド座標における3D点を画像平面上の2D点へ正規化カメラ座標で写像する射影変換が得られる。

\[Z_c \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} R|t \end{bmatrix} \begin{bmatrix} X_w \\ Y_w \\ Z_w \\ 1 \end{bmatrix} = \begin{bmatrix} r_{11} & r_{12} & r_{13} & t_x \\ r_{21} & r_{22} & r_{23} & t_y \\ r_{31} & r_{32} & r_{33} & t_z \end{bmatrix} \begin{bmatrix} X_w \\ Y_w \\ Z_w \\ 1 \end{bmatrix},\]

ただし \(x' = X_c / Z_c\) および \(y' = Y_c / Z_c\) である。内部パラメータと外部パラメータの式をまとめると、\(s \; p = A \begin{bmatrix} R|t \end{bmatrix} P_w\) を次のように書き下せる。

\[s \vecthree{u}{v}{1} = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1} \begin{bmatrix} r_{11} & r_{12} & r_{13} & t_x \\ r_{21} & r_{22} & r_{23} & t_y \\ r_{31} & r_{32} & r_{33} & t_z \end{bmatrix} \begin{bmatrix} X_w \\ Y_w \\ Z_w \\ 1 \end{bmatrix}.\]

\(Z_c \ne 0\) のとき、上記の変換は次の式と等価である。

\[\begin{bmatrix} u \\ v \end{bmatrix} = \begin{bmatrix} f_x X_c/Z_c + c_x \\ f_y Y_c/Z_c + c_y \end{bmatrix}\]

ただし

\[\vecthree{X_c}{Y_c}{Z_c} = \begin{bmatrix} R|t \end{bmatrix} \begin{bmatrix} X_w \\ Y_w \\ Z_w \\ 1 \end{bmatrix}.\]

次の図はピンホールカメラモデルを示している。

Pinhole camera model

実際のレンズには通常、何らかの歪みがあり、その大半は放射状歪みで、わずかに接線方向の歪みも生じる。そこで、上記のモデルは次のように拡張される。

\[\begin{bmatrix} u \\ v \end{bmatrix} = \begin{bmatrix} f_x x'' + c_x \\ f_y y'' + c_y \end{bmatrix}\]

ここで

\[\begin{bmatrix} x'' \\ y'' \end{bmatrix} = \begin{bmatrix} x' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} + 2 p_1 x' y' + p_2(r^2 + 2 x'^2) + s_1 r^2 + s_2 r^4 \\ y' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} + p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' + s_3 r^2 + s_4 r^4 \\ \end{bmatrix}\]

ただし

\[r^2 = x'^2 + y'^2\]

および

\[\begin{bmatrix} x'\\ y' \end{bmatrix} = \begin{bmatrix} X_c/Z_c \\ Y_c/Z_c \end{bmatrix},\]

ただし \(Z_c \ne 0\) のとき。

歪みパラメータのうち、放射状の係数は \(k_1\)、\(k_2\)、\(k_3\)、\(k_4\)、\(k_5\)、\(k_6\) であり、\(p_1\) と \(p_2\) は接線方向歪み係数、\(s_1\)、\(s_2\)、\(s_3\)、\(s_4\) は薄プリズム歪み係数である。OpenCVではより高次の係数は考慮しない。

次の図は、放射状歪みの代表的な2種類を示している。すなわち、樽型歪み(\( 1 + k_1 r^2 + k_2 r^4 + k_3 r^6 \) が単調減少)と糸巻き型歪み(\( 1 + k_1 r^2 + k_2 r^4 + k_3 r^6 \) が単調増加)である。実際のレンズでは放射状歪みは常に単調であり、推定器が非単調な結果を生成した場合は、キャリブレーションの失敗とみなすべきである。より一般には、放射状歪みは単調でなければならず、歪み関数は全単射でなければならない。失敗した推定結果は画像中心付近では一見良好に見えることがあるが、たとえばAR/SFMアプリケーションでは正しく機能しない。OpenCVのカメラキャリブレーションで用いられる最適化手法は、必要な整数計画法や多項式不等式をフレームワークがサポートしていないため、これらの制約を含んでいない。詳細は issue #15992 を参照のこと。

場合によっては、カメラ前方の斜めの面に焦点を合わせるためにイメージセンサが傾けられることがある(シャインプルーフの原理)。これは粒子画像流速測定(PIV)やレーザーファンによる三角測量に有用である。この傾きは \(x''\) と \(y''\) に透視歪みを生じさせる。この歪みは次のようにモデル化できる。たとえば [177] を参照のこと。

\[\begin{bmatrix} u \\ v \end{bmatrix} = \begin{bmatrix} f_x x''' + c_x \\ f_y y''' + c_y \end{bmatrix},\]

ここで

\[s\vecthree{x'''}{y'''}{1} = \vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}(\tau_x, \tau_y)} {0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)} {0}{0}{1} R(\tau_x, \tau_y) \vecthree{x''}{y''}{1}\]

また行列 \(R(\tau_x, \tau_y)\) は、それぞれ角度パラメータ \(\tau_x\) と \(\tau_y\) による2つの回転によって定義される。

\[ R(\tau_x, \tau_y) = \vecthreethree{\cos(\tau_y)}{0}{-\sin(\tau_y)}{0}{1}{0}{\sin(\tau_y)}{0}{\cos(\tau_y)} \vecthreethree{1}{0}{0}{0}{\cos(\tau_x)}{\sin(\tau_x)}{0}{-\sin(\tau_x)}{\cos(\tau_x)} = \vecthreethree{\cos(\tau_y)}{\sin(\tau_y)\sin(\tau_x)}{-\sin(\tau_y)\cos(\tau_x)} {0}{\cos(\tau_x)}{\sin(\tau_x)} {\sin(\tau_y)}{-\cos(\tau_y)\sin(\tau_x)}{\cos(\tau_y)\cos(\tau_x)}. \]

以下の関数では、係数は次のように渡される、あるいは返される。

\[(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\]

というベクトルである。つまり、ベクトルが4つの要素を含む場合、\(k_3=0\) を意味する。歪み係数は撮影されるシーンに依存しない。したがって、これらもカメラの内部パラメータに属する。そして、撮影される画像の解像度にかかわらず同じ値のままである。たとえば、あるカメラが320×240解像度の画像でキャリブレーションされた場合、まったく同じ歪み係数を同じカメラの640×480画像に使用できる。ただし \(f_x\)、\(f_y\)、\(c_x\)、\(c_y\) は適切にスケーリングする必要がある。

以下の関数は、上記のモデルを用いて次の処理を行う。

同次座標
同次座標は射影幾何学で用いられる座標系である。これを用いることで、無限遠点を有限の座標で表現でき、デカルト座標に比べて式が簡潔になる。たとえば、アフィン変換を線形な同次変換として表現できるという利点がある。

n次元のデカルトベクトル \(P\) の末尾に1を付加することで、同次ベクトル \(P_h\) が得られる。たとえば3次元のデカルトベクトルの場合、写像 \(P \rightarrow P_h\) は次のとおりである。

\[\begin{bmatrix} X \\ Y \\ Z \end{bmatrix} \rightarrow \begin{bmatrix} X \\ Y \\ Z \\ 1 \end{bmatrix}.\]

逆写像 \(P_h \rightarrow P\) では、同次ベクトルのすべての要素をその最後の要素で割る。たとえば3次元の同次ベクトルの場合、その2次元デカルト座標表現は次のように得られる。

\[\begin{bmatrix} X \\ Y \\ W \end{bmatrix} \rightarrow \begin{bmatrix} X / W \\ Y / W \end{bmatrix},\]

ただし \(W \ne 0\) のとき。

この写像により、ある同次点のすべての定数倍 \(k P_h\)(\(k \ne 0\))は、同じ点 \(P_h\) を表す。この性質を直感的に理解すると、射影変換のもとでは \(P_h\) のすべての定数倍が同じ点に写像される、ということである。これはピンホールカメラに対して観察される物理的な事実であり、カメラのピンホールを通る光線上のすべての点が同じ画像点に投影される。たとえば、上記のピンホールカメラモデルの図における赤い光線上のすべての点は、同じ画像座標に写像される。この性質は、ピンホールカメラモデルの式におけるスケールの不定性 s の原因でもある。

前述のとおり、同次座標を用いることで、\(R\) と \(t\) でパラメータ化される任意の基底変換を線形変換として表現できる。たとえば、座標系0から座標系1への基底変換は次のようになる。

\[P_1 = R P_0 + t \rightarrow P_{h_1} = \begin{bmatrix} R & t \\ 0 & 1 \end{bmatrix} P_{h_0}.\]

覚え書き
  • このモジュールの多くの関数は、カメラ内部行列を入力パラメータとして受け取る。すべての関数がこのパラメータについて同じ構造を仮定しているが、関数によって名前が異なる場合がある。ただし、パラメータの説明には、上記に示した構造のカメラ内部行列が必要であることが明確に記されている。
  • 水平方向に配置した3台のカメラのキャリブレーションサンプルは opencv_source_code/samples/cpp/3calibration.cpp にある
  • 画像列に基づくキャリブレーションサンプルは opencv_source_code/samples/cpp/calibration.cpp にある
  • 3D再構成を行うためのキャリブレーションサンプルは opencv_source_code/samples/cpp/build3dmodel.cpp にある
  • ステレオキャリブレーションのキャリブレーション例は opencv_source_code/samples/cpp/stereo_calib.cpp にある
  • ステレオマッチングのキャリブレーション例は opencv_source_code/samples/cpp/stereo_match.cpp にある
  • (Python)カメラキャリブレーションのサンプルは opencv_source_code/samples/python/calibrate.py にある

名前空間

namespace  cv::fisheye
 この名前空間のメソッドは、いわゆる魚眼カメラモデルを用いる。
 

クラス

class  cv::LevMarq
 Levenberg-Marquadtソルバー。 続きを読む...
 
struct  cv::UsacParams
 

列挙型

enum  {
  cv::LMEDS = 4 ,
  cv::RANSAC = 8 ,
  cv::RHO = 16 ,
  cv::USAC_DEFAULT = 32 ,
  cv::USAC_PARALLEL = 33 ,
  cv::USAC_FM_8PTS = 34 ,
  cv::USAC_FAST = 35 ,
  cv::USAC_ACCURATE = 36 ,
  cv::USAC_PROSAC = 37 ,
  cv::USAC_MAGSAC = 38
}
 ロバスト推定アルゴリズムの種類。 続きを読む...
 
enum  {
  cv::FM_7POINT = 1 ,
  cv::FM_8POINT = 2 ,
  cv::FM_LMEDS = 4 ,
  cv::FM_RANSAC = 8
}
 基礎行列を求めるためのアルゴリズム。 続きを読む...
 
enum  cv::LocalOptimMethod {
  cv::LOCAL_OPTIM_NULL =0 ,
  cv::LOCAL_OPTIM_INNER_LO =1 ,
  cv::LOCAL_OPTIM_INNER_AND_ITER_LO =2 ,
  cv::LOCAL_OPTIM_GC =3 ,
  cv::LOCAL_OPTIM_SIGMA =4
}
 
enum class  cv::MatrixType {
  cv::MatrixType::AUTO = 0 ,
  cv::MatrixType::DENSE = 1 ,
  cv::MatrixType::SPARSE = 2
}
 LevMarqソルバーで使用される行列の種類。 続きを読む...
 
enum  cv::NeighborSearchMethod {
  cv::NEIGH_FLANN_KNN =0 ,
  cv::NEIGH_GRID =1 ,
  cv::NEIGH_FLANN_RADIUS =2
}
 
enum  cv::PolishingMethod {
  cv::NONE_POLISHER =0 ,
  cv::LSQ_POLISHER =1 ,
  cv::MAGSAC =2 ,
  cv::COV_POLISHER =3
}
 
enum  cv::SamplingMethod {
  cv::SAMPLING_UNIFORM =0 ,
  cv::SAMPLING_PROGRESSIVE_NAPSAC =1 ,
  cv::SAMPLING_NAPSAC =2 ,
  cv::SAMPLING_PROSAC =3
}
 
enum  cv::ScoreMethod {
  cv::SCORE_METHOD_RANSAC =0 ,
  cv::SCORE_METHOD_MSAC =1 ,
  cv::SCORE_METHOD_MAGSAC =2 ,
  cv::SCORE_METHOD_LMEDS =3
}
 
enum  cv::SolvePnPMethod {
  cv::SOLVEPNP_ITERATIVE = 0 ,
  cv::SOLVEPNP_EPNP = 1 ,
  cv::SOLVEPNP_P3P = 2 ,
  cv::SOLVEPNP_AP3P = 3 ,
  cv::SOLVEPNP_IPPE = 4 ,
  cv::SOLVEPNP_IPPE_SQUARE = 5 ,
  cv::SOLVEPNP_SQPNP = 6
}
 
enum class  cv::VariableType {
  cv::VariableType::LINEAR = 0 ,
  cv::VariableType::SO3 = 1 ,
  cv::VariableType::SE3 = 2
}
 LevMarqソルバーで使用される変数の種類。 続きを読む...
 

関数

void cv::calibrationMatrixValues (InputArray cameraMatrix, Size imageSize, double apertureWidth, double apertureHeight, double &fovx, double &fovy, double &focalLength, Point2d &principalPoint, double &aspectRatio)
 カメラの内部行列から有用なカメラ特性を計算する。
 
void cv::composeRT (InputArray rvec1, InputArray tvec1, InputArray rvec2, InputArray tvec2, OutputArray rvec3, OutputArray tvec3, OutputArray dr3dr1=noArray(), OutputArray dr3dt1=noArray(), OutputArray dr3dr2=noArray(), OutputArray dr3dt2=noArray(), OutputArray dt3dr1=noArray(), OutputArray dt3dt1=noArray(), OutputArray dt3dr2=noArray(), OutputArray dt3dt2=noArray())
 2つの回転・並進変換を合成する。
 
void cv::computeCorrespondEpilines (InputArray points, int whichImage, InputArray F, OutputArray lines)
 ステレオペアの一方の画像中の点について、もう一方の画像における対応するエピポーラ線を計算する。
 
void cv::convertPointsFromHomogeneous (InputArray src, OutputArray dst, int dtype=-1)
 点を同次座標からユークリッド空間へ変換する。
 
void cv::convertPointsHomogeneous (InputArray src, OutputArray dst)
 点を同次座標に対して相互に変換する。
 
void cv::convertPointsToHomogeneous (InputArray src, OutputArray dst, int dtype=-1)
 点をユークリッド空間から同次座標空間へ変換する。
 
void cv::correctMatches (InputArray F, InputArray points1, InputArray points2, OutputArray newPoints1, OutputArray newPoints2)
 対応する点の座標を精緻化する。
 
void cv::decomposeEssentialMat (InputArray E, OutputArray R1, OutputArray R2, OutputArray t)
 基本行列を、取り得る回転と並進に分解する。
 
int cv::decomposeHomographyMat (InputArray H, InputArray K, OutputArrayOfArrays rotations, OutputArrayOfArrays translations, OutputArrayOfArrays normals)
 ホモグラフィ行列を、回転・並進・平面法線に分解する。
 
void cv::decomposeProjectionMatrix (InputArray projMatrix, OutputArray cameraMatrix, OutputArray rotMatrix, OutputArray transVect, OutputArray rotMatrixX=noArray(), OutputArray rotMatrixY=noArray(), OutputArray rotMatrixZ=noArray(), OutputArray eulerAngles=noArray())
 射影行列を回転行列とカメラ内部行列に分解する。
 
Mat cv::estimateAffine2D (InputArray from, InputArray to, OutputArray inliers=noArray(), int method=RANSAC, double ransacReprojThreshold=3, size_t maxIters=2000, double confidence=0.99, size_t refineIters=10)
 2つの2D点群の間で最適なアフィン変換を計算する。
 
Mat cv::estimateAffine2D (InputArray pts1, InputArray pts2, OutputArray inliers, const UsacParams &params)
 
cv::Mat cv::estimateAffine3D (InputArray src, InputArray dst, double *scale=nullptr, bool force_rotation=true)
 2つの3D点群の間で最適なアフィン変換を計算する。
 
bool cv::estimateAffine3D (InputArray src, InputArray dst, OutputArray out, OutputArray inliers, double ransacThreshold=3, double confidence=0.99)
 2つの3D点群の間で最適なアフィン変換を計算する。
 
cv::Mat cv::estimateAffinePartial2D (InputArray from, InputArray to, OutputArray inliers=noArray(), int method=RANSAC, double ransacReprojThreshold=3, size_t maxIters=2000, double confidence=0.99, size_t refineIters=10)
 2つの2D点群の間で、4自由度の最適な制限付きアフィン変換を計算する。
 
cv::Vec2d cv::estimateTranslation2D (InputArray from, InputArray to, OutputArray inliers=noArray(), int method=RANSAC, double ransacReprojThreshold=3, size_t maxIters=2000, double confidence=0.99, size_t refineIters=0)
 2つの2D点群の間の純粋な2D並進を計算する。
 
bool cv::estimateTranslation3D (InputArray src, InputArray dst, OutputArray out, OutputArray inliers, double ransacThreshold=3, double confidence=0.99)
 2つの3D点群の間で最適な並進を計算する。
 
void cv::filterHomographyDecompByVisibleRefpoints (InputArrayOfArrays rotations, InputArrayOfArrays normals, InputArray beforePoints, InputArray afterPoints, OutputArray possibleSolutions, InputArray pointsMask=noArray())
 追加情報に基づいてホモグラフィ分解の結果を絞り込む。
 
Mat cv::findEssentialMat (InputArray points1, InputArray points2, double focal=1.0, Point2d pp=Point2d(0, 0), int method=RANSAC, double prob=0.999, double threshold=1.0, int maxIters=1000, OutputArray mask=noArray())
 
Mat cv::findEssentialMat (InputArray points1, InputArray points2, InputArray cameraMatrix, int method=RANSAC, double prob=0.999, double threshold=1.0, int maxIters=1000, OutputArray mask=noArray())
 2枚の画像中の対応点から基本行列を計算する。
 
Mat cv::findEssentialMat (InputArray points1, InputArray points2, InputArray cameraMatrix1, InputArray cameraMatrix2, InputArray dist_coeff1, InputArray dist_coeff2, OutputArray mask, const UsacParams &params)
 
Mat cv::findEssentialMat (InputArray points1, InputArray points2, InputArray cameraMatrix1, InputArray distCoeffs1, InputArray cameraMatrix2, InputArray distCoeffs2, int method=RANSAC, double prob=0.999, double threshold=1.0, OutputArray mask=noArray())
 場合によっては異なる2台のカメラからの2枚の画像中の対応点から基本行列を計算する。
 
Mat cv::findFundamentalMat (InputArray points1, InputArray points2, int method, double ransacReprojThreshold, double confidence, int maxIters, OutputArray mask=noArray())
 2枚の画像中の対応点から基礎行列を計算する。
 
Mat cv::findFundamentalMat (InputArray points1, InputArray points2, int method=FM_RANSAC, double ransacReprojThreshold=3., double confidence=0.99, OutputArray mask=noArray())
 
Mat cv::findFundamentalMat (InputArray points1, InputArray points2, OutputArray mask, const UsacParams &params)
 
Mat cv::findFundamentalMat (InputArray points1, InputArray points2, OutputArray mask, int method=FM_RANSAC, double ransacReprojThreshold=3., double confidence=0.99)
 
Mat cv::findHomography (InputArray srcPoints, InputArray dstPoints, int method=0, double ransacReprojThreshold=3, OutputArray mask=noArray(), const int maxIters=2000, const double confidence=0.995)
 2つの平面の間の透視変換を求める。
 
Mat cv::findHomography (InputArray srcPoints, InputArray dstPoints, OutputArray mask, const UsacParams &params)
 
Mat cv::findHomography (InputArray srcPoints, InputArray dstPoints, OutputArray mask, int method=0, double ransacReprojThreshold=3)
 
Mat cv::getDefaultNewCameraMatrix (InputArray cameraMatrix, Size imgsize=Size(), bool centerPrincipalPoint=false)
 デフォルトの新しいカメラ行列を返す。
 
Mat cv::getOptimalNewCameraMatrix (InputArray cameraMatrix, InputArray distCoeffs, Size imageSize, double alpha, Size newImgSize=Size(), Rect *validPixROI=0, bool centerPrincipalPoint=false)
 自由スケーリングパラメータに基づく新しいカメラ内部行列を返す。
 
void cv::getUndistortRectangles (InputArray cameraMatrix, InputArray distCoeffs, InputArray R, InputArray newCameraMatrix, Size imgSize, Rect_< double > &inner, Rect_< double > &outer)
 "歪み補正された"画像平面に対する内接矩形とバウンディング矩形を返す。
 
void cv::matMulDeriv (InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB)
 乗算される各行列について、行列積の偏微分を計算する。
 
void cv::projectPoints (InputArray objectPoints, InputArray rvec, InputArray tvec, InputArray cameraMatrix, InputArray distCoeffs, OutputArray imagePoints, OutputArray dpdr, OutputArray dpdt, OutputArray dpdf=noArray(), OutputArray dpdc=noArray(), OutputArray dpdk=noArray(), OutputArray dpdo=noArray(), double aspectRatio=0.)
 
void cv::projectPoints (InputArray objectPoints, InputArray rvec, InputArray tvec, InputArray cameraMatrix, InputArray distCoeffs, OutputArray imagePoints, OutputArray jacobian=noArray(), double aspectRatio=0)
 3D点を画像平面へ射影する。
 
int cv::recoverPose (InputArray E, InputArray points1, InputArray points2, InputArray cameraMatrix, OutputArray R, OutputArray t, double distanceThresh, InputOutputArray mask=noArray(), OutputArray triangulatedPoints=noArray())
 
int cv::recoverPose (InputArray E, InputArray points1, InputArray points2, InputArray cameraMatrix, OutputArray R, OutputArray t, InputOutputArray mask=noArray())
 推定された基本行列と2枚の画像中の対応点から、相対的なカメラ回転と並進を、カイラリティチェックを用いて復元する。チェックを通過したインライアの数を返す。
 
int cv::recoverPose (InputArray E, InputArray points1, InputArray points2, OutputArray R, OutputArray t, double focal=1.0, Point2d pp=Point2d(0, 0), InputOutputArray mask=noArray())
 
int cv::recoverPose (InputArray points1, InputArray points2, InputArray cameraMatrix1, InputArray distCoeffs1, InputArray cameraMatrix2, InputArray distCoeffs2, OutputArray E, OutputArray R, OutputArray t, int method=cv::RANSAC, double prob=0.999, double threshold=1.0, InputOutputArray mask=noArray())
 異なる2台のカメラで撮影した2枚の画像中の対応点から、相対的なカメラの回転と並進を、チラリティチェックを用いて復元する。チェックを通過したインライアの数を返す。
 
void cv::Rodrigues (InputArray src, OutputArray dst, OutputArray jacobian=noArray())
 回転行列を回転ベクトルへ、あるいはその逆へ変換する。
 
Vec3d cv::RQDecomp3x3 (InputArray src, OutputArray mtxR, OutputArray mtxQ, OutputArray Qx=noArray(), OutputArray Qy=noArray(), OutputArray Qz=noArray())
 3x3 行列の RQ 分解を計算する。
 
double cv::sampsonDistance (InputArray pt1, InputArray pt2, InputArray F)
 2点間の Sampson 距離を計算する。
 
int cv::solveP3P (InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags)
 3 組の 3D-2D 点対応から物体姿勢 \( {}^{c}\mathbf{T}_o \) を求める。
 
bool cv::solvePnP (InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false, int flags=SOLVEPNP_ITERATIVE)
 3D-2D 点対応から物体姿勢 \( {}^{c}\mathbf{T}_o \) を求める:
 
int cv::solvePnPGeneric (InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, bool useExtrinsicGuess=false, int flags=SOLVEPNP_ITERATIVE, InputArray rvec=noArray(), InputArray tvec=noArray(), OutputArray reprojectionError=noArray())
 3D-2D 点対応から物体姿勢 \( {}^{c}\mathbf{T}_o \) を求める。
 
bool cv::solvePnPRansac (InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false, int iterationsCount=100, float reprojectionError=8.0, double confidence=0.99, OutputArray inliers=noArray(), int flags=SOLVEPNP_ITERATIVE)
 RANSAC 方式を用いて誤マッチを処理しながら、3D-2D 点対応から物体姿勢 \( {}^{c}\mathbf{T}_o \) を求める。
 
bool cv::solvePnPRansac (InputArray objectPoints, InputArray imagePoints, InputOutputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, OutputArray inliers, const UsacParams &params=UsacParams())
 
void cv::solvePnPRefineLM (InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, InputOutputArray rvec, InputOutputArray tvec, TermCriteria criteria=TermCriteria(TermCriteria::EPS+TermCriteria::COUNT, 20, FLT_EPSILON))
 3D-2D 点対応から、初期解を出発点として姿勢(物体座標系で表された3D点をカメラ座標系へ変換する並進と回転)を精緻化する。
 
void cv::solvePnPRefineVVS (InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, InputOutputArray rvec, InputOutputArray tvec, TermCriteria criteria=TermCriteria(TermCriteria::EPS+TermCriteria::COUNT, 20, FLT_EPSILON), double VVSlambda=1)
 3D-2D 点対応から、初期解を出発点として姿勢(物体座標系で表された3D点をカメラ座標系へ変換する並進と回転)を精緻化する。
 
void cv::triangulatePoints (InputArray projMatr1, InputArray projMatr2, InputArray projPoints1, InputArray projPoints2, OutputArray points4D)
 この関数は、ステレオカメラによる観測値を用いて3次元点(同次座標)を再構成する。
 
void cv::undistortImagePoints (InputArray src, OutputArray dst, InputArray cameraMatrix, InputArray distCoeffs, TermCriteria=TermCriteria(TermCriteria::MAX_ITER, 5, 0.01))
 歪み補正後の画像点の位置を計算する。
 
void cv::undistortPoints (InputArray src, OutputArray dst, InputArray cameraMatrix, InputArray distCoeffs, InputArray R=noArray(), InputArray P=noArray(), TermCriteria criteria=TermCriteria(TermCriteria::MAX_ITER, 5, 0.01))
 観測された点座標から理想的な点座標を計算する。
 

列挙型詳解

◆ anonymous enum

anonymous enum

#include <opencv2/geometry/3d.hpp>

ロバスト推定アルゴリズムの種類

列挙値
LMEDS 
Python: cv.LMEDS

最小メジアン二乗法アルゴリズム

RANSAC 
Python: cv.RANSAC

RANSAC アルゴリズム。

RHO 
Python: cv.RHO

RHO アルゴリズム。

USAC_DEFAULT 
Python: cv.USAC_DEFAULT

USAC アルゴリズム、デフォルト設定。

USAC_PARALLEL 
Python: cv.USAC_PARALLEL

USAC、並列版。

USAC_FM_8PTS 
Python: cv.USAC_FM_8PTS

USAC、基礎行列8点法。

USAC_FAST 
Python: cv.USAC_FAST

USAC、高速設定。

USAC_ACCURATE 
Python: cv.USAC_ACCURATE

USAC、高精度設定。

USAC_PROSAC 
Python: cv.USAC_PROSAC

USAC、ソート済みの点、PROSAC を実行。

USAC_MAGSAC 
Python: cv.USAC_MAGSAC

USAC、MAGSAC++ を実行。

◆ anonymous enum

anonymous enum

#include <opencv2/geometry/3d.hpp>

基礎行列を求めるアルゴリズム

列挙値
FM_7POINT 
Python: cv.FM_7POINT

7点法

FM_8POINT 
Python: cv.FM_8POINT

8点法

FM_LMEDS 
Python: cv.FM_LMEDS

最小メジアン法。7点法が使用される。

FM_RANSAC 
Python: cv.FM_RANSAC

RANSAC アルゴリズム。少なくとも15点が必要。7点法が使用される。

◆ LocalOptimMethod

#include <opencv2/geometry/3d.hpp>

列挙値
LOCAL_OPTIM_NULL 
Python: cv.LOCAL_OPTIM_NULL
LOCAL_OPTIM_INNER_LO 
Python: cv.LOCAL_OPTIM_INNER_LO
LOCAL_OPTIM_INNER_AND_ITER_LO 
Python: cv.LOCAL_OPTIM_INNER_AND_ITER_LO
LOCAL_OPTIM_GC 
Python: cv.LOCAL_OPTIM_GC
LOCAL_OPTIM_SIGMA 
Python: cv.LOCAL_OPTIM_SIGMA

◆ MatrixType

enum class cv::MatrixType
strong

#include <opencv2/geometry/3d.hpp>

LevMarqソルバーで使用される行列の種類。

行列の種類は、密(dense)、疎(sparse)、または行列サイズ・性能上の考慮・バックエンドの利用可否に基づいて自動的に選択できる。

注意: 現在は密行列のみがサポートされている。

列挙値
AUTO 
DENSE 
SPARSE 

◆ NeighborSearchMethod

#include <opencv2/geometry/3d.hpp>

列挙値
NEIGH_FLANN_KNN 
Python: cv.NEIGH_FLANN_KNN
NEIGH_GRID 
Python: cv.NEIGH_GRID
NEIGH_FLANN_RADIUS 
Python: cv.NEIGH_FLANN_RADIUS

◆ PolishingMethod

#include <opencv2/geometry/3d.hpp>

列挙値
NONE_POLISHER 
Python: cv.NONE_POLISHER
LSQ_POLISHER 
Python: cv.LSQ_POLISHER
MAGSAC 
Python: cv.MAGSAC
COV_POLISHER 
Python: cv.COV_POLISHER

◆ SamplingMethod

#include <opencv2/geometry/3d.hpp>

列挙値
SAMPLING_UNIFORM 
Python: cv.SAMPLING_UNIFORM
SAMPLING_PROGRESSIVE_NAPSAC 
Python: cv.SAMPLING_PROGRESSIVE_NAPSAC
SAMPLING_NAPSAC 
Python: cv.SAMPLING_NAPSAC
SAMPLING_PROSAC 
Python: cv.SAMPLING_PROSAC

◆ ScoreMethod

#include <opencv2/geometry/3d.hpp>

列挙値
SCORE_METHOD_RANSAC 
Python: cv.SCORE_METHOD_RANSAC
SCORE_METHOD_MSAC 
Python: cv.SCORE_METHOD_MSAC
SCORE_METHOD_MAGSAC 
Python: cv.SCORE_METHOD_MAGSAC
SCORE_METHOD_LMEDS 
Python: cv.SCORE_METHOD_LMEDS

◆ SolvePnPMethod

#include <opencv2/geometry/3d.hpp>

列挙値
SOLVEPNP_ITERATIVE 
Python: cv.SOLVEPNP_ITERATIVE

非線形のLevenberg-Marquardt最小化法 [185] [81] を用いた姿勢の精緻化。
平面でない"objectPoints"の初期解には少なくとも6点が必要で、DLTアルゴリズムを用いる。
平面の"objectPoints"の初期解には少なくとも4点が必要で、ホモグラフィ分解による姿勢を用いる。

SOLVEPNP_EPNP 
Python: cv.SOLVEPNP_EPNP

EPnP: Efficient Perspective-n-Point Camera Pose Estimation [162].

SOLVEPNP_P3P 
Python: cv.SOLVEPNP_P3P

P3P 問題の再検討 [73]

SOLVEPNP_AP3P 
Python: cv.SOLVEPNP_AP3P

An Efficient Algebraic Solution to the Perspective-Three-Point Problem [149].

SOLVEPNP_IPPE 
Python: cv.SOLVEPNP_IPPE

微小平面ベースの姿勢推定 [64]
オブジェクト点は同一平面上になければならない。

SOLVEPNP_IPPE_SQUARE 
Python: cv.SOLVEPNP_IPPE_SQUARE

微小平面ベースの姿勢推定 [64]
これはマーカー姿勢推定に適した特殊なケースである。
4つの同一平面上のオブジェクト点を次の順序で定義しなければならない:

  • 点 0: [-squareLength / 2, squareLength / 2, 0]
  • 点 1: [ squareLength / 2, squareLength / 2, 0]
  • 点 2: [ squareLength / 2, -squareLength / 2, 0]
  • 点 3: [-squareLength / 2, -squareLength / 2, 0]
SOLVEPNP_SQPNP 
Python: cv.SOLVEPNP_SQPNP

SQPnP: A Consistently Fast and Globally OptimalSolution to the Perspective-n-Point Problem [277].

◆ VariableType

enum class cv::VariableType
strong

#include <opencv2/geometry/3d.hpp>

LevMarqソルバーで使用される変数の種類。

変数は、線形、回転(SO(3)群)、または剛体変換(SE(3)群)のいずれかであり、対応するヤコビアンと指数写像による更新を持つ。

注意: 現在は線形変数のみがサポートされている。

列挙値
LINEAR 
SO3 
SE3 

関数詳解

◆ calibrationMatrixValues()

void cv::calibrationMatrixValues ( InputArray cameraMatrix,
Size imageSize,
double apertureWidth,
double apertureHeight,
double & fovx,
double & fovy,
double & focalLength,
Point2d & principalPoint,
double & aspectRatio )
Python:
cv.calibrationMatrixValues(cameraMatrix, imageSize, apertureWidth, apertureHeight) -> fovx, fovy, focalLength, principalPoint, aspectRatio

#include <opencv2/geometry/3d.hpp>

カメラ内部行列から有用なカメラ特性を計算する。

引数
cameraMatrixcalibrateCamera または stereoCalibrate で推定可能な入力カメラ内部行列。
imageSize入力画像のサイズ(ピクセル単位)。
apertureWidthセンサの物理的な幅(mm 単位)。
apertureHeightセンサの物理的な高さ(mm 単位)。
fovxセンサの水平軸に沿った視野角の出力(度単位)。
fovyセンサの垂直軸に沿った視野角の出力(度単位)。
focalLengthレンズの焦点距離(mm 単位)。
principalPoint主点(mm 単位)。
aspectRatio\(f_y/f_x\)

この関数は、あらかじめ推定されたカメラ行列からさまざまな有用なカメラ特性を計算する。

覚え書き
単位 'mm' は、チェスボードのピッチに選んだ任意の計測単位を表すものであることに留意せよ(したがって任意の値を取り得る)。

◆ composeRT()

void cv::composeRT ( InputArray rvec1,
InputArray tvec1,
InputArray rvec2,
InputArray tvec2,
OutputArray rvec3,
OutputArray tvec3,
OutputArray dr3dr1 = noArray(),
OutputArray dr3dt1 = noArray(),
OutputArray dr3dr2 = noArray(),
OutputArray dr3dt2 = noArray(),
OutputArray dt3dr1 = noArray(),
OutputArray dt3dt1 = noArray(),
OutputArray dt3dr2 = noArray(),
OutputArray dt3dt2 = noArray() )
Python:
cv.composeRT(rvec1, tvec1, rvec2, tvec2[, rvec3[, tvec3[, dr3dr1[, dr3dt1[, dr3dr2[, dr3dt2[, dt3dr1[, dt3dt1[, dt3dr2[, dt3dt2]]]]]]]]]]) -> rvec3, tvec3, dr3dr1, dr3dt1, dr3dr2, dr3dt2, dt3dr1, dt3dt1, dt3dr2, dt3dt2

#include <opencv2/geometry/3d.hpp>

2つの回転・並進変換を合成する。

引数
rvec11番目の回転ベクトル。
tvec11番目の並進ベクトル。
rvec22番目の回転ベクトル。
tvec22番目の並進ベクトル。
rvec3重ね合わせの出力回転ベクトル。
tvec3重ね合わせの出力並進ベクトル。
dr3dr1rvec1 に関する rvec3 の微分の出力(省略可能)
dr3dt1tvec1 に関する rvec3 の微分の出力(省略可能)
dr3dr2rvec2 に関する rvec3 の微分の出力(省略可能)
dr3dt2tvec2 に関する rvec3 の微分の出力(省略可能)
dt3dr1rvec1 に関する tvec3 の微分の出力(省略可能)
dt3dt1tvec1 に関する tvec3 の微分の出力(省略可能)
dt3dr2rvec2 に関する tvec3 の微分の出力(省略可能)
dt3dt2tvec2 に関する tvec3 の微分の出力(省略可能)

これらの関数は次を計算する:

\[\begin{array}{l} \texttt{rvec3} = \mathrm{rodrigues} ^{-1} \left ( \mathrm{rodrigues} ( \texttt{rvec2} ) \cdot \mathrm{rodrigues} ( \texttt{rvec1} ) \right ) \\ \texttt{tvec3} = \mathrm{rodrigues} ( \texttt{rvec2} ) \cdot \texttt{tvec1} + \texttt{tvec2} \end{array} ,\]

ここで \(\mathrm{rodrigues}\) は回転ベクトルから回転行列への変換を表し、\(\mathrm{rodrigues}^{-1}\) はその逆変換を表す。詳細は Rodrigues を参照。

また、これらの関数は入力ベクトルに対する出力ベクトルの導関数を計算できる(matMulDeriv を参照)。これらの関数はstereoCalibrateの内部で使われるが、行列の乗算を含む関数を最適化するためにLevenberg-Marquardtや他の勾配ベースのソルバーを用いる独自のコードでも使用できる。

◆ computeCorrespondEpilines()

void cv::computeCorrespondEpilines ( InputArray points,
int whichImage,
InputArray F,
OutputArray lines )
Python:
cv.computeCorrespondEpilines(points, whichImage, F[, lines]) -> lines

#include <opencv2/geometry/3d.hpp>

ステレオペアの一方の画像中の点に対して、もう一方の画像中の対応するエピポーラ線を計算する。

引数
points入力点。型 CV_32FC2 の \(N \times 1\) もしくは \(1 \times N\) 行列、または vector<Point2f> 。
whichImage点を含む画像のインデックス(1 または 2)。
FfindFundamentalMat または stereoRectify を使って推定できる基礎行列。
linesもう一方の画像中の点に対応するエピポーラ線の出力ベクトル。各直線 \(ax + by + c=0\) は3つの数値 \((a, b, c)\) で表される。

ステレオペアの2枚の画像の一方の各点について、この関数はもう一方の画像中の対応するエピポーラ線の方程式を求める。

基礎行列の定義(findFundamentalMat を参照)より、第1画像中の点 \(p^{(1)}_i\) に対する第2画像中の線 \(l^{(2)}_i\) は(whichImage=1 の場合)次のように計算される:

\[l^{(2)}_i = F p^{(1)}_i\]

逆に、whichImage=2 の場合、\(l^{(1)}_i\) は \(p^{(2)}_i\) から次のように計算される:

\[l^{(1)}_i = F^T p^{(2)}_i\]

線の係数はスケール倍まで定まる。それらは \(a_i^2+b_i^2=1\) となるように正規化される。

◆ convertPointsFromHomogeneous()

void cv::convertPointsFromHomogeneous ( InputArray src,
OutputArray dst,
int dtype = -1 )
Python:
cv.convertPointsFromHomogeneous(src[, dst[, dtype]]) -> dst

#include <opencv2/geometry/3d.hpp>

点を同次空間からユークリッド空間に変換する。

引数
srcN次元点の入力ベクトル。
dstN-1次元点の出力ベクトル。
dtype希望する出力配列のビット深度(現在サポートされているのは CV_32F または CV_64F のいずれか)。-1の場合は、入力のビット深度に応じて CV_32F または CV_64F に自動設定される。

この関数は、透視投影を用いて点を同次空間からユークリッド空間に変換する。すなわち、各点 (x1, x2, ... x(n-1), xn) は (x1/xn, x2/xn, ..., x(n-1)/xn) に変換される。xn=0 の場合、出力点の座標は (0,0,0,...) となる。

◆ convertPointsHomogeneous()

void cv::convertPointsHomogeneous ( InputArray src,
OutputArray dst )

#include <opencv2/geometry/3d.hpp>

点を同次座標との間で変換する。

引数
src2次元、3次元、または4次元の点の入力配列またはベクトル。
dst2次元、3次元、または4次元の点の出力ベクトル。

この関数は、convertPointsToHomogeneousまたはconvertPointsFromHomogeneousのいずれかを呼び出すことで、2Dまたは3Dの点を同次座標との間で変換する。

覚え書き
この関数は廃止された。代わりに前述の2つの関数のいずれかを使用すること。

◆ convertPointsToHomogeneous()

void cv::convertPointsToHomogeneous ( InputArray src,
OutputArray dst,
int dtype = -1 )
Python:
cv.convertPointsToHomogeneous(src[, dst[, dtype]]) -> dst

#include <opencv2/geometry/3d.hpp>

点をユークリッド空間から同次空間に変換する。

引数
srcN次元点の入力ベクトル。
dstN+1次元点の出力ベクトル。
dtype希望する出力配列のビット深度(現在サポートされているのは CV_32F または CV_64F のいずれか)。-1の場合は、入力のビット深度に応じて CV_32F または CV_64F に自動設定される。

この関数は、点の座標タプルに1を付加することで、点をユークリッド空間から同次空間に変換する。すなわち、各点 (x1, x2, ..., xn) は (x1, x2, ..., xn, 1) に変換される。

◆ correctMatches()

void cv::correctMatches ( InputArray F,
InputArray points1,
InputArray points2,
OutputArray newPoints1,
OutputArray newPoints2 )
Python:
cv.correctMatches(F, points1, points2[, newPoints1[, newPoints2]]) -> newPoints1, newPoints2

#include <opencv2/geometry/3d.hpp>

対応する点の座標を精緻化する。

引数
F3x3 の基礎行列。
points11番目の点群を含む 1xN 配列。
points22番目の点群を含む 1xN 配列。
newPoints1最適化された points1。
newPoints2最適化された points2。

この関数は最適三角測量法(Optimal Triangulation Method)を実装している(詳細はMultiple View Geometry [121] を参照)。与えられた各点対応 points1[i] <-> points2[i] と基礎行列Fに対して、エピポーラ拘束 \(newPoints2^T \cdot F \cdot newPoints1 = 0\) を満たしつつ、幾何的誤差 \(d(points1[i], newPoints1[i])^2 + d(points2[i],newPoints2[i])^2\) (ここで \(d(a,b)\) は点 \(a\) と \(b\) の間の幾何的距離)を最小化する補正後の対応点 newPoints1[i] <-> newPoints2[i] を計算する。

◆ decomposeEssentialMat()

void cv::decomposeEssentialMat ( InputArray E,
OutputArray R1,
OutputArray R2,
OutputArray t )
Python:
cv.decomposeEssentialMat(E[, R1[, R2[, t]]]) -> R1, R2, t

#include <opencv2/geometry/3d.hpp>

基本行列を可能な回転と並進に分解する。

引数
E入力の基本行列。
R1考えられる回転行列の1つ。
R2考えられるもう1つの回転行列。
t考えられる並進の1つ。

この関数は、SVD分解 [121] を用いて基本行列Eを分解する。一般に、Eの分解には4通りの姿勢が存在し得る。それらは \([R_1, t]\), \([R_1, -t]\), \([R_2, t]\), \([R_2, -t]\) である。

E が第1画像中の画像点 \(p_1\) と第2画像中の \(p_2\) の間のエピポーラ拘束 \([p_2; 1]^T A^{-T} E A^{-1} [p_1; 1] = 0\) を与える場合、タプル \([R_1, t]\)、\([R_1, -t]\)、\([R_2, t]\)、\([R_2, -t]\) のいずれかが第1カメラの座標系から第2カメラの座標系への基底変換となる。ただし、E を分解することで得られるのは並進の方向のみである。このため、並進 t は単位長さで返される。

◆ decomposeHomographyMat()

int cv::decomposeHomographyMat ( InputArray H,
InputArray K,
OutputArrayOfArrays rotations,
OutputArrayOfArrays translations,
OutputArrayOfArrays normals )
Python:
cv.decomposeHomographyMat(H, K[, rotations[, translations[, normals]]]) -> retval, rotations, translations, normals

#include <opencv2/geometry/3d.hpp>

ホモグラフィ行列を回転、並進、および平面法線に分解する。

引数
H2枚の画像間の入力ホモグラフィ行列。
K入力のカメラ内部行列。
rotations回転行列の配列。
translations並進行列の配列。
normals平面法線行列の配列。

この関数は、平面物体の2つのビュー間の相対的なカメラ運動を抽出し、回転・並進・平面法線からなる最大4組の数学的解を返す。ホモグラフィ行列Hの分解については [187] で詳しく説明されている。

平面によって誘導されるホモグラフィ H が次の拘束を与える場合

\[s_i \vecthree{x'_i}{y'_i}{1} \sim H \vecthree{x_i}{y_i}{1}\]

ソース画像点 \(p_i\) と対象画像点 \(p'_i\) について、タプル rotations[k] と translations[k] はソースカメラの座標系から対象カメラの座標系への基底変換である。ただし、H を分解することで得られるのは、シーンの(一般に未知の)奥行きで正規化された並進、すなわちその方向だけであり、長さは正規化されている。

点の対応が利用可能であれば、正の奥行き拘束、すなわちすべての点がカメラの前方になければならないという拘束を適用することで、少なくとも2つの解をさらに無効化できる。

◆ decomposeProjectionMatrix()

void cv::decomposeProjectionMatrix ( InputArray projMatrix,
OutputArray cameraMatrix,
OutputArray rotMatrix,
OutputArray transVect,
OutputArray rotMatrixX = noArray(),
OutputArray rotMatrixY = noArray(),
OutputArray rotMatrixZ = noArray(),
OutputArray eulerAngles = noArray() )
Python:
cv.decomposeProjectionMatrix(projMatrix[, cameraMatrix[, rotMatrix[, transVect[, rotMatrixX[, rotMatrixY[, rotMatrixZ[, eulerAngles]]]]]]]) -> cameraMatrix, rotMatrix, transVect, rotMatrixX, rotMatrixY, rotMatrixZ, eulerAngles

#include <opencv2/geometry/3d.hpp>

射影行列を回転行列とカメラ内部行列に分解する。

引数
projMatrix3x4 の入力射影行列 P。
cameraMatrix出力の 3x3 カメラ内部行列 \(\cameramatrix{A}\)。
rotMatrix出力の 3x3 外部回転行列 R。
transVect出力の 4x1 並進ベクトル T。
rotMatrixXx軸まわりの 3x3 回転行列(省略可能)。
rotMatrixYy軸まわりの 3x3 回転行列(省略可能)。
rotMatrixZz軸まわりの 3x3 回転行列(省略可能)。
eulerAngles回転の3つのオイラー角(度単位)を含む3要素ベクトル(省略可能)。

この関数は、射影行列をキャリブレーション行列、回転行列、およびカメラの位置に分解する。

オプションで、各軸に対応する3つの回転行列と、OpenGLで使用できる3つのオイラー角を返す。なお、ある物体の同じ姿勢をもたらす3つの主軸まわりの回転の列は、常に複数存在することに注意する(例えば [257] を参照)。返される3つの回転行列と対応する3つのオイラー角は、あり得る解の1つにすぎない。

この関数は RQDecomp3x3 に基づいている。

◆ estimateAffine2D() [1/2]

Mat cv::estimateAffine2D ( InputArray from,
InputArray to,
OutputArray inliers = noArray(),
int method = RANSAC,
double ransacReprojThreshold = 3,
size_t maxIters = 2000,
double confidence = 0.99,
size_t refineIters = 10 )
Python:
cv.estimateAffine2D(from_, to[, inliers[, method[, ransacReprojThreshold[, maxIters[, confidence[, refineIters]]]]]]) -> retval, inliers
cv.estimateAffine2D(pts1, pts2, params[, inliers]) -> retval, inliers

#include <opencv2/geometry/3d.hpp>

2つの2D点集合間の最適なアフィン変換を計算する。

次を計算する

\[ \begin{bmatrix} x\\ y\\ \end{bmatrix} = \begin{bmatrix} a_{11} & a_{12}\\ a_{21} & a_{22}\\ \end{bmatrix} \begin{bmatrix} X\\ Y\\ \end{bmatrix} + \begin{bmatrix} b_1\\ b_2\\ \end{bmatrix} \]

引数
from\((X,Y)\) を含む1番目の入力2次元点群。
to\((x,y)\) を含む2番目の入力2次元点群。
inliersどの点がインライアであるかを示す出力ベクトル(1=インライア、0=アウトライア)。
method変換の計算に使用するロバストな手法。次の手法が指定可能である:
  • RANSAC - RANSACベースのロバストな手法
  • LMEDS - 最小メジアン法によるロバストな手法。RANSACがデフォルトの手法である。
ransacReprojThreshold点をインライアとみなすための、RANSAC アルゴリズムにおける最大再投影誤差。RANSAC にのみ適用される。
maxItersロバスト手法の最大反復回数。
confidence推定される変換の信頼度。0から1の値で、通常は 0.95 から 0.99 の間であれば十分である。1 に近すぎる値は推定を大幅に遅くする可能性がある。0.8〜0.9 より低い値は誤った変換の推定につながることがある。
refineItersリファインアルゴリズム(Levenberg-Marquardt)の最大反復回数。0 を渡すとリファインが無効になり、出力行列はロバスト手法の出力となる。
戻り値
Output 2D affine transformation matrix \(2 \times 3\) or empty matrix if transformation could not be estimated. The returned matrix has the following form:

\[ \begin{bmatrix} a_{11} & a_{12} & b_1\\ a_{21} & a_{22} & b_2\\ \end{bmatrix} \]

この関数は、選択したロバストなアルゴリズムを用いて、2つの2D点集合間の最適な2Dアフィン変換を推定する。

計算された変換は、その後(インライアのみを用いて)Levenberg-Marquardt法でさらに精緻化され、再投影誤差をいっそう低減する。

覚え書き
RANSAC法は事実上どのようなアウトライア比率にも対応できるが、インライアとアウトライアを区別するためのしきい値を必要とする。LMeDS法はしきい値を必要としないが、インライアが50%を超える場合にのみ正しく機能する。
参照
estimateAffinePartial2D, getAffineTransform

◆ estimateAffine2D() [2/2]

Mat cv::estimateAffine2D ( InputArray pts1,
InputArray pts2,
OutputArray inliers,
const UsacParams & params )
Python:
cv.estimateAffine2D(from_, to[, inliers[, method[, ransacReprojThreshold[, maxIters[, confidence[, refineIters]]]]]]) -> retval, inliers
cv.estimateAffine2D(pts1, pts2, params[, inliers]) -> retval, inliers

◆ estimateAffine3D() [1/2]

cv::Mat cv::estimateAffine3D ( InputArray src,
InputArray dst,
double * scale = nullptr,
bool force_rotation = true )
Python:
cv.estimateAffine3D(src, dst[, out[, inliers[, ransacThreshold[, confidence]]]]) -> retval, out, inliers
cv.estimateAffine3D(src, dst[, force_rotation]) -> retval, scale

#include <opencv2/geometry/3d.hpp>

2つの3D点集合間の最適なアフィン変換を計算する。

これは \(\sum{i} dst_i - c \cdot R \cdot src_i \) を最小化する \(R,s,t\) を計算する。ここで \(R\) は3x3の回転行列、\(t\) は3x1の並進ベクトル、\(s\) はスカラーのスケール値である。これはUmeyamaのアルゴリズム [288] の実装である。推定されるアフィン変換は同次スケールを持ち、これは7自由度を持つアフィン変換の部分クラスである。点の対の集合は、それぞれ少なくとも3点を含む必要がある。

引数
src1番目の入力3次元点群。
dst2番目の入力3次元点群。
scalenull を渡すと、スケールパラメータ c は 1.0 と仮定される。そうでなければ、指し示す変数に最適なスケールが設定される。
force_rotationtrue の場合、返される回転は決して鏡映にならない。たとえば右手系と左手系の座標系の間の変換を最適化する場合など、これが望ましくないことがある。
戻り値
3D affine transformation matrix \(3 \times 4\) of the form

\[T = \begin{bmatrix} R & t\\ \end{bmatrix} \]

◆ estimateAffine3D() [2/2]

bool cv::estimateAffine3D ( InputArray src,
InputArray dst,
OutputArray out,
OutputArray inliers,
double ransacThreshold = 3,
double confidence = 0.99 )
Python:
cv.estimateAffine3D(src, dst[, out[, inliers[, ransacThreshold[, confidence]]]]) -> retval, out, inliers
cv.estimateAffine3D(src, dst[, force_rotation]) -> retval, scale

#include <opencv2/geometry/3d.hpp>

2つの3D点集合間の最適なアフィン変換を計算する。

次を計算する

\[ \begin{bmatrix} x\\ y\\ z\\ \end{bmatrix} = \begin{bmatrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33}\\ \end{bmatrix} \begin{bmatrix} X\\ Y\\ Z\\ \end{bmatrix} + \begin{bmatrix} b_1\\ b_2\\ b_3\\ \end{bmatrix} \]

引数
src\((X,Y,Z)\) を含む1番目の入力3次元点群。
dst\((x,y,z)\) を含む2番目の入力3次元点群。
out次の形式の出力3次元アフィン変換行列 \(3 \times 4\)

\[ \begin{bmatrix} a_{11} & a_{12} & a_{13} & b_1\\ a_{21} & a_{22} & a_{23} & b_2\\ a_{31} & a_{32} & a_{33} & b_3\\ \end{bmatrix} \]

inliersどの点がインライアであるかを示す出力ベクトル(1=インライア、0=アウトライア)。
ransacThreshold点をインライアとみなすための、RANSAC アルゴリズムにおける最大再投影誤差。
confidence推定される変換の信頼度。0から1の値で、通常は 0.95 から 0.99 の間であれば十分である。1 に近すぎる値は推定を大幅に遅くする可能性がある。0.8〜0.9 より低い値は誤った変換の推定につながることがある。
戻り値
解が見つかったかどうか。

この関数は、RANSACアルゴリズムを用いて、2つの3D点集合間の最適な3Dアフィン変換を推定する。

◆ estimateAffinePartial2D()

cv::Mat cv::estimateAffinePartial2D ( InputArray from,
InputArray to,
OutputArray inliers = noArray(),
int method = RANSAC,
double ransacReprojThreshold = 3,
size_t maxIters = 2000,
double confidence = 0.99,
size_t refineIters = 10 )
Python:
cv.estimateAffinePartial2D(from_, to[, inliers[, method[, ransacReprojThreshold[, maxIters[, confidence[, refineIters]]]]]]) -> retval, inliers

#include <opencv2/geometry/3d.hpp>

2つの2D点集合間で4自由度を持つ最適な限定アフィン変換を計算する。

引数
from1番目の入力2次元点群。
to2番目の入力2次元点群。
inliersどの点がインライアであるかを示す出力ベクトル。
method変換の計算に使用するロバストな手法。次の手法が指定可能である:
  • RANSAC - RANSACベースのロバストな手法
  • LMEDS - 最小メジアン法によるロバストな手法。RANSACがデフォルトの手法である。
ransacReprojThreshold点をインライアとみなすための、RANSAC アルゴリズムにおける最大再投影誤差。RANSAC にのみ適用される。
maxItersロバスト手法の最大反復回数。
confidence推定される変換の信頼度。0から1の値で、通常は 0.95 から 0.99 の間であれば十分である。1 に近すぎる値は推定を大幅に遅くする可能性がある。0.8〜0.9 より低い値は誤った変換の推定につながることがある。
refineItersリファインアルゴリズム(Levenberg-Marquardt)の最大反復回数。0 を渡すとリファインが無効になり、出力行列はロバスト手法の出力となる。
戻り値
出力される2Dアフィン変換(4自由度)行列 \(2 \times 3\)、または変換を推定できなかった場合は空の行列。

この関数は、並進、回転、一様スケーリングの組み合わせに限定された4自由度を持つ最適な2Dアフィン変換を推定する。ロバストな推定には選択したアルゴリズムを使用する。

計算された変換は、その後(インライアのみを用いて)Levenberg-Marquardt法でさらに精緻化され、再投影誤差をいっそう低減する。

推定される変換行列は次のとおりである:

\[ \begin{bmatrix} \cos(\theta) \cdot s & -\sin(\theta) \cdot s & t_x \\ \sin(\theta) \cdot s & \cos(\theta) \cdot s & t_y \end{bmatrix} \]

ここで \( \theta \) は回転角、\( s \) はスケーリング係数、\( t_x, t_y \) はそれぞれ \( x, y \) 軸方向の並進である。

覚え書き
RANSAC法は事実上どのようなアウトライア比率にも対応できるが、インライアとアウトライアを区別するためのしきい値を必要とする。LMeDS法はしきい値を必要としないが、インライアが50%を超える場合にのみ正しく機能する。
参照
estimateAffine2D, getAffineTransform

◆ estimateTranslation2D()

cv::Vec2d cv::estimateTranslation2D ( InputArray from,
InputArray to,
OutputArray inliers = noArray(),
int method = RANSAC,
double ransacReprojThreshold = 3,
size_t maxIters = 2000,
double confidence = 0.99,
size_t refineIters = 0 )
Python:
cv.estimateTranslation2D(from_, to[, inliers[, method[, ransacReprojThreshold[, maxIters[, confidence[, refineIters]]]]]]) -> retval, inliers

#include <opencv2/geometry/3d.hpp>

2つの2D点群の間の純粋な2D平行移動を計算する。

次を計算する

\[ \begin{bmatrix} x\\ y \end{bmatrix} = \begin{bmatrix} 1 & 0\\ 0 & 1 \end{bmatrix} \begin{bmatrix} X\\ Y \end{bmatrix} + \begin{bmatrix} t_x\\ t_y \end{bmatrix}. \]

引数
from\((X,Y)\) を含む1番目の入力2次元点群。
to\((x,y)\) を含む2番目の入力2次元点群。
inliersどの点がインライアであるかを示す出力ベクトル(1=インライア、0=アウトライア)。
method変換の計算に使用するロバストな手法。次の手法が指定可能である:
  • RANSAC - RANSACベースのロバストな手法
  • LMEDS - 最小メジアン法によるロバストな手法。RANSACがデフォルトの手法である。
ransacReprojThreshold点をインライアとみなすための、RANSAC アルゴリズムにおける最大再投影誤差。RANSAC にのみ適用される。
maxItersロバスト手法の最大反復回数。
confidence推定される変換の信頼度。0から1の値で、通常は 0.95 から 0.99 の間であれば十分である。1 に近すぎる値は推定を大幅に遅くする可能性がある。0.8〜0.9 より低い値は誤った変換の推定につながることがある。
refineIters詳細化アルゴリズムの最大反復回数。純粋な並進の場合はインライアに対する最小二乗解が閉形式で求まるため、0 を渡すこと(追加の詳細化を行わない)が推奨される。
戻り値
cv::Vec2d 形式の2D平行移動ベクトル \([t_x, t_y]^T\)。平行移動を推定できなかった場合、両成分はNaNに設定され、inliers が指定されている場合はマスクがゼロで埋められる。
Converting to a 2x3 transformation matrix:

\[ \begin{bmatrix} 1 & 0 & t_x\\ 0 & 1 & t_y \end{bmatrix} \]

cv::Vec2d t = cv::estimateTranslation2D(from, to, inliers);
cv::Mat T = (cv::Mat_<double>(2,3) << 1,0,t[0], 0,1,t[1]);
Template matrix class derived from Mat.
Definition mat.hpp:2581
Comma-separated Matrix Initializer.
Definition mat.hpp:964
cv::Vec2d estimateTranslation2D(InputArray from, InputArray to, OutputArray inliers=noArray(), int method=RANSAC, double ransacReprojThreshold=3, size_t maxIters=2000, double confidence=0.99, size_t refineIters=0)
Computes a pure 2D translation between two 2D point sets.

この関数は、選択したロバストアルゴリズムを用いて2つの2D点群の間の純粋な2D平行移動を推定する。インライアは再投影誤差のしきい値によって決定される。

覚え書き
RANSAC法はほぼ任意の割合の外れ値を扱えるが、インライアと外れ値を区別するためのしきい値を必要とする。LMeDS法はしきい値を必要としないが、インライアが50%を超える場合にのみ正しく動作する。
参照
estimateAffine2D, estimateAffinePartial2D, getAffineTransform

◆ estimateTranslation3D()

bool cv::estimateTranslation3D ( InputArray src,
InputArray dst,
OutputArray out,
OutputArray inliers,
double ransacThreshold = 3,
double confidence = 0.99 )
Python:
cv.estimateTranslation3D(src, dst[, out[, inliers[, ransacThreshold[, confidence]]]]) -> retval, out, inliers

#include <opencv2/geometry/3d.hpp>

2つの3D点群の間の最適な平行移動を計算する。

次を計算する

\[ \begin{bmatrix} x\\ y\\ z\\ \end{bmatrix} = \begin{bmatrix} X\\ Y\\ Z\\ \end{bmatrix} + \begin{bmatrix} b_1\\ b_2\\ b_3\\ \end{bmatrix} \]

引数
src\((X,Y,Z)\) を含む1番目の入力3次元点群。
dst\((x,y,z)\) を含む2番目の入力3次元点群。
out次の形式の出力 3D 並進ベクトル \(3 \times 1\)

\[ \begin{bmatrix} b_1 \\ b_2 \\ b_3 \\ \end{bmatrix} \]

inliersどの点がインライアであるかを示す出力ベクトル(1=インライア、0=アウトライア)。
ransacThreshold点をインライアとみなすための、RANSAC アルゴリズムにおける最大再投影誤差。
confidence推定される変換の信頼度。0から1の値で、通常は 0.95 から 0.99 の間であれば十分である。1 に近すぎる値は推定を大幅に遅くする可能性がある。0.8〜0.9 より低い値は誤った変換の推定につながることがある。
戻り値
並進が見つかったかどうか。

この関数は、RANSACアルゴリズムを用いて2つの3D点群の間の最適な3D平行移動を推定する。

◆ filterHomographyDecompByVisibleRefpoints()

void cv::filterHomographyDecompByVisibleRefpoints ( InputArrayOfArrays rotations,
InputArrayOfArrays normals,
InputArray beforePoints,
InputArray afterPoints,
OutputArray possibleSolutions,
InputArray pointsMask = noArray() )
Python:
cv.filterHomographyDecompByVisibleRefpoints(rotations, normals, beforePoints, afterPoints[, possibleSolutions[, pointsMask]]) -> possibleSolutions

#include <opencv2/geometry/3d.hpp>

追加情報に基づいてホモグラフィ分解の結果を絞り込む。

引数
rotations回転行列のベクトル。
normals平面の法線行列のベクトル。
beforePointsホモグラフィを適用する前の(補正された)可視の参照点のベクトル
afterPointsホモグラフィを適用した後の(補正された)可視の参照点のベクトル
possibleSolutionsフィルタリング後の有効な解集合を表す int インデックスのベクトル
pointsMaskfindHomography 関数によって与えられるインライアのマスクを表す、CV_8U、CV_8S または CV_Bool 型の省略可能な Mat/Vector

この関数は、[187] で説明されているように、追加情報に基づいてdecomposeHomographyMatの出力をフィルタリングすることを目的としている。手法の概要: decomposeHomographyMat関数は2つの一意な解とそれらの"反対解"を返し、合計4つの解になる。ホモグラフィ変換が適用される前後にカメラフレームで見える点の集合にアクセスできる場合、見えるすべての参照点がカメラの前方にあることと整合するホモグラフィを検証することで、どれが真に可能性のある解で、どれが反対解かを判定できる。入力は変更されず、フィルタリングされた解集合は既存の集合へのインデックスとして返される。

◆ findEssentialMat() [1/4]

Mat cv::findEssentialMat ( InputArray points1,
InputArray points2,
double focal = 1.0,
Point2d pp = Point2d(0, 0),
int method = RANSAC,
double prob = 0.999,
double threshold = 1.0,
int maxIters = 1000,
OutputArray mask = noArray() )
Python:
cv.findEssentialMat(points1, points2, cameraMatrix[, method[, prob[, threshold[, maxIters[, mask]]]]]) -> retval, mask
cv.findEssentialMat(points1, points2[, focal[, pp[, method[, prob[, threshold[, maxIters[, mask]]]]]]]) -> retval, mask
cv.findEssentialMat(points1, points2, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2[, method[, prob[, threshold[, mask]]]]) -> retval, mask
cv.findEssentialMat(points1, points2, cameraMatrix1, cameraMatrix2, dist_coeff1, dist_coeff2, params[, mask]) -> retval, mask

#include <opencv2/geometry/3d.hpp>

これは利便性のために提供されているオーバーロードされたメンバ関数である。上記の関数とは、受け取る引数のみが異なる。

引数
points11 枚目の画像からの N 個(N >= 5)の 2D 点の配列。点の座標は浮動小数点(単精度または倍精度)でなければならない。
points2points1 と同じサイズおよび形式の、2 枚目の画像の点の配列。
focalカメラの焦点距離。この関数は、points1 と points2 が同じ焦点距離および主点を持つカメラからの特徴点であると仮定することに注意。
ppカメラの主点。
method基礎行列の計算手法。
  • RANSACアルゴリズムには RANSAC
  • LMedSアルゴリズムには LMEDS
thresholdRANSAC で使用される引数。点からエピポーラ線までの最大距離(ピクセル単位)であり、これを超える点はアウトライアとみなされ、最終的な基礎行列の計算には使用されない。点の位置特定の精度、画像の解像度、画像のノイズに応じて、1〜3 程度の値に設定できる。
probRANSAC または LMedS 手法でのみ使用される引数。推定された行列が正しいという望ましい信頼水準(確率)を指定する。
maskN 要素の出力配列で、各要素はアウトライアに対しては 0 に、それ以外の点に対しては 1 に設定される。この配列は RANSAC および LMedS 手法でのみ計算される。
maxItersロバスト手法の最大反復回数。

この関数は、焦点距離と主点からカメラ内部行列を計算する点で上記の関数と異なる:

\[A = \begin{bmatrix} f & 0 & x_{pp} \\ 0 & f & y_{pp} \\ 0 & 0 & 1 \end{bmatrix}\]

◆ findEssentialMat() [2/4]

Mat cv::findEssentialMat ( InputArray points1,
InputArray points2,
InputArray cameraMatrix,
int method = RANSAC,
double prob = 0.999,
double threshold = 1.0,
int maxIters = 1000,
OutputArray mask = noArray() )
Python:
cv.findEssentialMat(points1, points2, cameraMatrix[, method[, prob[, threshold[, maxIters[, mask]]]]]) -> retval, mask
cv.findEssentialMat(points1, points2[, focal[, pp[, method[, prob[, threshold[, maxIters[, mask]]]]]]]) -> retval, mask
cv.findEssentialMat(points1, points2, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2[, method[, prob[, threshold[, mask]]]]) -> retval, mask
cv.findEssentialMat(points1, points2, cameraMatrix1, cameraMatrix2, dist_coeff1, dist_coeff2, params[, mask]) -> retval, mask

#include <opencv2/geometry/3d.hpp>

2つの画像内の対応する点から基本行列(essential matrix)を計算する。

引数
points11 枚目の画像からの N 個(N >= 5)の 2D 点の配列。点の座標は浮動小数点(単精度または倍精度)でなければならない。
points2points1 と同じサイズおよび形式の、2 枚目の画像の点の配列。
cameraMatrixカメラ内部行列 \(\cameramatrix{A}\) 。この関数は、points1 と points2 が同じカメラ内部行列を持つカメラからの特徴点であることを前提とする点に注意。この前提が使用ケースに当てはまらない場合は、別の関数オーバーロードを使用するか、両方のカメラに対して P = cv::NoArray() を指定した undistortPoints を使用して、画像点を正規化画像座標に変換する。これは単位カメラ内部行列に対して有効である。これらの座標を渡す場合は、このパラメータに単位行列を渡すこと。
method基本行列の計算手法。
  • RANSACアルゴリズムには RANSAC
  • LMedSアルゴリズムには LMEDS
probRANSAC または LMedS 手法でのみ使用される引数。推定された行列が正しいという望ましい信頼水準(確率)を指定する。
thresholdRANSAC で使用される引数。点からエピポーラ線までの最大距離(ピクセル単位)であり、これを超える点はアウトライアとみなされ、最終的な基礎行列の計算には使用されない。点の位置特定の精度、画像の解像度、画像のノイズに応じて、1〜3 程度の値に設定できる。
maskN 要素の出力配列で、各要素はアウトライアに対しては 0 に、それ以外の点に対しては 1 に設定される。この配列は RANSAC および LMedS 手法でのみ計算される。
maxItersロバスト手法の最大反復回数。

この関数は、[216] の5点アルゴリズムソルバーに基づいて基本行列を推定する。[261] も関連している。エピポーラ幾何は次式で記述される:

\[[p_2; 1]^T K^{-T} E K^{-1} [p_1; 1] = 0\]

ここで \(E\) は基本行列(essential matrix)、\(p_1\) と \(p_2\) はそれぞれ1番目と2番目の画像内の対応する点である。この関数の結果はさらに decomposeEssentialMat または recoverPose に渡して、カメラ間の相対的な姿勢を復元できる。

◆ findEssentialMat() [3/4]

Mat cv::findEssentialMat ( InputArray points1,
InputArray points2,
InputArray cameraMatrix1,
InputArray cameraMatrix2,
InputArray dist_coeff1,
InputArray dist_coeff2,
OutputArray mask,
const UsacParams & params )
Python:
cv.findEssentialMat(points1, points2, cameraMatrix[, method[, prob[, threshold[, maxIters[, mask]]]]]) -> retval, mask
cv.findEssentialMat(points1, points2[, focal[, pp[, method[, prob[, threshold[, maxIters[, mask]]]]]]]) -> retval, mask
cv.findEssentialMat(points1, points2, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2[, method[, prob[, threshold[, mask]]]]) -> retval, mask
cv.findEssentialMat(points1, points2, cameraMatrix1, cameraMatrix2, dist_coeff1, dist_coeff2, params[, mask]) -> retval, mask

◆ findEssentialMat() [4/4]

Mat cv::findEssentialMat ( InputArray points1,
InputArray points2,
InputArray cameraMatrix1,
InputArray distCoeffs1,
InputArray cameraMatrix2,
InputArray distCoeffs2,
int method = RANSAC,
double prob = 0.999,
double threshold = 1.0,
OutputArray mask = noArray() )
Python:
cv.findEssentialMat(points1, points2, cameraMatrix[, method[, prob[, threshold[, maxIters[, mask]]]]]) -> retval, mask
cv.findEssentialMat(points1, points2[, focal[, pp[, method[, prob[, threshold[, maxIters[, mask]]]]]]]) -> retval, mask
cv.findEssentialMat(points1, points2, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2[, method[, prob[, threshold[, mask]]]]) -> retval, mask
cv.findEssentialMat(points1, points2, cameraMatrix1, cameraMatrix2, dist_coeff1, dist_coeff2, params[, mask]) -> retval, mask

#include <opencv2/geometry/3d.hpp>

潜在的に異なる2つのカメラからの2つの画像内の対応する点から基本行列(essential matrix)を計算する。

引数
points11 枚目の画像からの N 個(N >= 5)の 2D 点の配列。点の座標は浮動小数点(単精度または倍精度)でなければならない。
points2points1 と同じサイズおよび形式の、2 枚目の画像の点の配列。
cameraMatrix11 つ目のカメラのカメラ行列 \(K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\) 。
cameraMatrix22 つ目のカメラのカメラ行列 \(K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\) 。
distCoeffs11 つ目のカメラの歪み係数の入力ベクトル \((k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\) で、4, 5, 8, 12, または 14 要素。ベクトルが NULL/空の場合、歪み係数は 0 と仮定される。
distCoeffs22 つ目のカメラの歪み係数の入力ベクトル \((k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\) で、4, 5, 8, 12, または 14 要素。ベクトルが NULL/空の場合、歪み係数は 0 と仮定される。
method基本行列の計算手法。
  • RANSACアルゴリズムには RANSAC
  • LMedSアルゴリズムには LMEDS
probRANSAC または LMedS 手法でのみ使用される引数。推定された行列が正しいという望ましい信頼水準(確率)を指定する。
thresholdRANSAC で使用される引数。点からエピポーラ線までの最大距離(ピクセル単位)であり、これを超える点はアウトライアとみなされ、最終的な基礎行列の計算には使用されない。点の位置特定の精度、画像の解像度、画像のノイズに応じて、1〜3 程度の値に設定できる。
maskN 要素の出力配列で、各要素はアウトライアに対しては 0 に、それ以外の点に対しては 1 に設定される。この配列は RANSAC および LMedS 手法でのみ計算される。

この関数は、[216] の5点アルゴリズムソルバーに基づいて基本行列を推定する。[261] も関連している。エピポーラ幾何は次式で記述される:

\[[p_2; 1]^T K^{-T} E K^{-1} [p_1; 1] = 0\]

ここで \(E\) は基本行列(essential matrix)、\(p_1\) と \(p_2\) はそれぞれ1番目と2番目の画像内の対応する点である。この関数の結果はさらに decomposeEssentialMat または recoverPose に渡して、カメラ間の相対的な姿勢を復元できる。

◆ findFundamentalMat() [1/4]

Mat cv::findFundamentalMat ( InputArray points1,
InputArray points2,
int method,
double ransacReprojThreshold,
double confidence,
int maxIters,
OutputArray mask = noArray() )
Python:
cv.findFundamentalMat(points1, points2, method, ransacReprojThreshold, confidence, maxIters[, mask]) -> retval, mask
cv.findFundamentalMat(points1, points2[, method[, ransacReprojThreshold[, confidence[, mask]]]]) -> retval, mask
cv.findFundamentalMat(points1, points2, params[, mask]) -> retval, mask

#include <opencv2/geometry/3d.hpp>

2つの画像内の対応する点から基礎行列(fundamental matrix)を計算する。

引数
points11 枚目の画像からの N 個の点の配列。点の座標は浮動小数点(単精度または倍精度)でなければならない。
points2points1 と同じサイズおよび形式の、2 枚目の画像の点の配列。
method基礎行列の計算手法。
  • 7点アルゴリズムには FM_7POINT。\(N = 7\)
  • 8点アルゴリズムには FM_8POINT。\(N \ge 8\)
  • RANSACアルゴリズムには FM_RANSAC。\(N \ge 8\)
  • LMedSアルゴリズムには FM_LMEDS。\(N \ge 8\)
ransacReprojThresholdRANSAC でのみ使用される引数。点からエピポーラ線までの最大距離(ピクセル単位)であり、これを超える点はアウトライアとみなされ、最終的な基礎行列の計算には使用されない。点の位置特定の精度、画像の解像度、画像のノイズに応じて、1〜3 程度の値に設定できる。
confidenceRANSAC および LMedS 手法でのみ使用される引数。推定された行列が正しいという望ましい信頼水準(確率)を指定する。
[out]mask省略可能な出力マスク
maxItersロバスト手法の最大反復回数。

エピポーラ幾何は次の式で表される:

\[[p_2; 1]^T F [p_1; 1] = 0\]

ここで \(F\) は基礎行列(fundamental matrix)、\(p_1\) と \(p_2\) はそれぞれ1番目と2番目の画像内の対応する点である。

この関数は、上記の4つの手法のいずれかを用いて基礎行列(fundamental matrix)を計算し、求めた基礎行列を返す。通常は1つの行列だけが見つかる。ただし7点アルゴリズムの場合、関数は最大3つの解(3つの行列を順に格納する \(9 \times 3\) 行列)を返すことがある。

計算された基礎行列はさらにcomputeCorrespondEpilinesに渡すことができ、指定した点に対応するエピポーラ線を求められる。またstereoRectifyUncalibratedに渡して平行化変換を計算することもできる。:

// Example. Estimation of fundamental matrix using the RANSAC algorithm
int point_count = 100;
vector<Point2f> points1(point_count);
vector<Point2f> points2(point_count);
// initialize the points here ...
for( int i = 0; i < point_count; i++ )
{
points1[i] = ...;
points2[i] = ...;
}
Mat fundamental_matrix =
findFundamentalMat(points1, points2, FM_RANSAC, 3, 0.99);
Mat findFundamentalMat(InputArray points1, InputArray points2, int method, double ransacReprojThreshold, double confidence, int maxIters, OutputArray mask=noArray())
Calculates a fundamental matrix from the corresponding points in two images.
@ FM_RANSAC
RANSAC algorithm. It needs at least 15 points. 7-point algorithm is used.
Definition 3d.hpp:410

◆ findFundamentalMat() [2/4]

Mat cv::findFundamentalMat ( InputArray points1,
InputArray points2,
int method = FM_RANSAC,
double ransacReprojThreshold = 3.,
double confidence = 0.99,
OutputArray mask = noArray() )
Python:
cv.findFundamentalMat(points1, points2, method, ransacReprojThreshold, confidence, maxIters[, mask]) -> retval, mask
cv.findFundamentalMat(points1, points2[, method[, ransacReprojThreshold[, confidence[, mask]]]]) -> retval, mask
cv.findFundamentalMat(points1, points2, params[, mask]) -> retval, mask

#include <opencv2/geometry/3d.hpp>

これは利便性のために提供されているオーバーロードされたメンバ関数である。上記の関数とは、受け取る引数のみが異なる。

◆ findFundamentalMat() [3/4]

Mat cv::findFundamentalMat ( InputArray points1,
InputArray points2,
OutputArray mask,
const UsacParams & params )
Python:
cv.findFundamentalMat(points1, points2, method, ransacReprojThreshold, confidence, maxIters[, mask]) -> retval, mask
cv.findFundamentalMat(points1, points2[, method[, ransacReprojThreshold[, confidence[, mask]]]]) -> retval, mask
cv.findFundamentalMat(points1, points2, params[, mask]) -> retval, mask

◆ findFundamentalMat() [4/4]

Mat cv::findFundamentalMat ( InputArray points1,
InputArray points2,
OutputArray mask,
int method = FM_RANSAC,
double ransacReprojThreshold = 3.,
double confidence = 0.99 )
Python:
cv.findFundamentalMat(points1, points2, method, ransacReprojThreshold, confidence, maxIters[, mask]) -> retval, mask
cv.findFundamentalMat(points1, points2[, method[, ransacReprojThreshold[, confidence[, mask]]]]) -> retval, mask
cv.findFundamentalMat(points1, points2, params[, mask]) -> retval, mask

#include <opencv2/geometry/3d.hpp>

これは利便性のために提供されているオーバーロードされたメンバ関数である。上記の関数とは、受け取る引数のみが異なる。

◆ findHomography() [1/3]

Mat cv::findHomography ( InputArray srcPoints,
InputArray dstPoints,
int method = 0,
double ransacReprojThreshold = 3,
OutputArray mask = noArray(),
const int maxIters = 2000,
const double confidence = 0.995 )
Python:
cv.findHomography(srcPoints, dstPoints[, method[, ransacReprojThreshold[, mask[, maxIters[, confidence]]]]]) -> retval, mask
cv.findHomography(srcPoints, dstPoints, params[, mask]) -> retval, mask

#include <opencv2/geometry/3d.hpp>

2つの平面の間の透視変換を求める。

引数
srcPoints元の平面における点の座標。型 CV_32FC2 の行列または vector<Point2f> 。
dstPoints対象平面における点の座標。型 CV_32FC2 の行列または vector<Point2f> 。
methodホモグラフィ行列の計算に使用する手法。次の手法が指定可能である:
  • 0 - すべての点を使用する通常の手法、すなわち最小二乗法
  • RANSAC - RANSACベースのロバストな手法
  • LMEDS - 最小メジアン法によるロバストな手法
  • RHO - PROSACベースのロバストな手法
ransacReprojThreshold点のペアをインライアとして扱うために許容される最大の再投影誤差(RANSAC および RHO 手法でのみ使用される)。すなわち、次の場合

\[\| \texttt{dstPoints} _i - \texttt{convertPointsHomogeneous} ( \texttt{H} \cdot \texttt{srcPoints} _i) \|_2 > \texttt{ransacReprojThreshold}\]

点 \(i\) はアウトライアとみなされる。srcPoints と dstPoints がピクセル単位で測定されている場合、通常この引数は 1〜10 程度の範囲に設定するのが妥当である。
maskロバストな手法(RANSAC または LMeDS)によって設定される省略可能な出力マスク。入力マスクの値は無視されることに注意。
maxItersRANSAC の最大反復回数。
confidence信頼水準。0 から 1 の間。

この関数は、ソース平面と宛先平面の間の透視変換 \(H\) を求めて返す:

\[s_i \vecthree{x'_i}{y'_i}{1} \sim H \vecthree{x_i}{y_i}{1}\]

そのため、逆投影誤差

\[\sum _i \left ( x'_i- \frac{h_{11} x_i + h_{12} y_i + h_{13}}{h_{31} x_i + h_{32} y_i + h_{33}} \right )^2+ \left ( y'_i- \frac{h_{21} x_i + h_{22} y_i + h_{23}}{h_{31} x_i + h_{32} y_i + h_{33}} \right )^2\]

が最小化される。引数methodがデフォルト値の0に設定されている場合、関数はすべての点ペアを使用し、単純な最小二乗法によって初期ホモグラフィ推定値を計算する。

ただし、すべての点ペア(\(srcPoints_i\)、\(dstPoints_i\))が剛体的な透視変換に適合しない場合(つまり外れ値が存在する場合)、この初期推定値は不十分なものになる。この場合、3つのロバストな手法のいずれかを使用できる。RANSAC、LMeDS、RHOの各手法は、対応する点ペアの様々なランダムな部分集合(それぞれ4ペア、共線のペアは除外される)を多数試し、その部分集合と単純な最小二乗アルゴリズムを用いてホモグラフィ行列を推定し、計算したホモグラフィの品質・良さ(RANSACではインライアの数、LMeDSでは最小メジアン再投影誤差)を計算する。次に、最良の部分集合を用いてホモグラフィ行列の初期推定値とインライア・外れ値のマスクを生成する。

手法がロバストかどうかにかかわらず、計算されたホモグラフィ行列はさらにLevenberg-Marquardt法を用いて(ロバストな手法の場合はインライアのみを使用して)改良され、再投影誤差をさらに低減する。

RANSACおよびRHO法はほぼ任意の割合の外れ値を扱えるが、インライアと外れ値を区別するためのしきい値を必要とする。LMeDS法はしきい値を必要としないが、インライアが50%を超える場合にのみ正しく動作する。最後に、外れ値がなくノイズがかなり小さい場合は、デフォルトの手法(method=0)を使用する。

この関数は、内部行列と外部行列の初期値を求めるために使用される。ホモグラフィ行列はスケールを除いて決定される。\(h_{33}\) が非ゼロの場合、行列は \(h_{33}=1\) となるように正規化される。

覚え書き
\(H\) 行列が推定できない場合は、空の行列が返される。
参照
getAffineTransform, estimateAffine2D, estimateAffinePartial2D, getPerspectiveTransform, warpPerspective, perspectiveTransform

◆ findHomography() [2/3]

Mat cv::findHomography ( InputArray srcPoints,
InputArray dstPoints,
OutputArray mask,
const UsacParams & params )
Python:
cv.findHomography(srcPoints, dstPoints[, method[, ransacReprojThreshold[, mask[, maxIters[, confidence]]]]]) -> retval, mask
cv.findHomography(srcPoints, dstPoints, params[, mask]) -> retval, mask

◆ findHomography() [3/3]

Mat cv::findHomography ( InputArray srcPoints,
InputArray dstPoints,
OutputArray mask,
int method = 0,
double ransacReprojThreshold = 3 )
Python:
cv.findHomography(srcPoints, dstPoints[, method[, ransacReprojThreshold[, mask[, maxIters[, confidence]]]]]) -> retval, mask
cv.findHomography(srcPoints, dstPoints, params[, mask]) -> retval, mask

#include <opencv2/geometry/3d.hpp>

これは利便性のために提供されているオーバーロードされたメンバ関数である。上記の関数とは、受け取る引数のみが異なる。

◆ getDefaultNewCameraMatrix()

Mat cv::getDefaultNewCameraMatrix ( InputArray cameraMatrix,
Size imgsize = Size(),
bool centerPrincipalPoint = false )
Python:
cv.getDefaultNewCameraMatrix(cameraMatrix[, imgsize[, centerPrincipalPoint]]) -> retval

#include <opencv2/geometry/3d.hpp>

デフォルトの新しいカメラ行列を返す。

この関数は、入力cameraMatrixの正確なコピー(centerPrinicipalPoint=falseの場合)か、変更されたもの(centerPrincipalPoint=trueの場合)のいずれかのカメラ行列を返す。

後者の場合、新しいカメラ行列は次のようになる:

\[\begin{bmatrix} f_x && 0 && ( \texttt{imgSize.width} -1)*0.5 \\ 0 && f_y && ( \texttt{imgSize.height} -1)*0.5 \\ 0 && 0 && 1 \end{bmatrix} ,\]

ここで \(f_x\) と \(f_y\) はそれぞれ cameraMatrix の \((0,0)\) 要素と \((1,1)\) 要素である。

デフォルトでは、OpenCVの歪み補正関数(initUndistortRectifyMap, undistortを参照)は主点を移動しない。しかしステレオを扱う場合、両方のビューの主点を同じy座標(多くのステレオ対応アルゴリズムで要求される)に、場合によっては同じx座標にも移動させることが重要である。そのため、主点が中心に位置するように各ビューの新しいカメラ行列を構成できる。

引数
cameraMatrix入力カメラ行列。
imgsizeカメラビュー画像のサイズ(ピクセル単位)。
centerPrincipalPoint新しいカメラ行列における主点の位置。この引数は、この位置を画像中心にすべきかどうかを示す。

◆ getOptimalNewCameraMatrix()

Mat cv::getOptimalNewCameraMatrix ( InputArray cameraMatrix,
InputArray distCoeffs,
Size imageSize,
double alpha,
Size newImgSize = Size(),
Rect * validPixROI = 0,
bool centerPrincipalPoint = false )
Python:
cv.getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, alpha[, newImgSize[, centerPrincipalPoint]]) -> retval, validPixROI

#include <opencv2/geometry/3d.hpp>

自由スケーリングパラメータに基づく新しいカメラ内部行列を返す。

引数
cameraMatrix入力カメラ内部行列。
distCoeffs歪み係数の入力ベクトル \(\distcoeffs\)。ベクトルが NULL/空の場合、歪み係数は 0 と仮定される。
imageSize元の画像サイズ。
alpha0(歪み補正後の画像内のすべてのピクセルが有効な場合)から1(元画像のすべてのピクセルが歪み補正後の画像に保持される場合)の間のフリースケーリングパラメータ。詳細は stereoRectify を参照。
newImgSize平行化後の画像サイズ。デフォルトでは imageSize に設定される。
validPixROI歪み補正後の画像内の、すべてが良好なピクセルからなる領域を囲む省略可能な出力矩形。stereoRectify の roi1、roi2 の説明を参照。
centerPrincipalPoint新しいカメラ内部行列において主点を画像中心にすべきかどうかを示す省略可能なフラグ。デフォルトでは、主点は元画像の一部(alpha によって決定される)を補正後の画像に最も良く合わせるように選択される。
戻り値
new_camera_matrix 出力される新しいカメラ内部行列。

この関数は、自由スケーリングパラメータに基づいて最適な新しいカメラ内部行列を計算して返す。このパラメータを変化させることで、意味のあるピクセルのみを取得したり(alpha=0)、隅に有用な情報がある場合に元画像のすべてのピクセルを保持したり(alpha=1)、あるいはその中間の結果を得たりできる。alpha>0のとき、歪み補正後の結果には、撮影された歪み画像の外側にある"仮想"ピクセルに対応する黒いピクセルが生じる可能性が高い。元のカメラ内部行列、歪み係数、計算された新しいカメラ内部行列、およびnewImageSizeをinitUndistortRectifyMapに渡して、remap用のマップを生成する。

◆ getUndistortRectangles()

void cv::getUndistortRectangles ( InputArray cameraMatrix,
InputArray distCoeffs,
InputArray R,
InputArray newCameraMatrix,
Size imgSize,
Rect_< double > & inner,
Rect_< double > & outer )

#include <opencv2/geometry/3d.hpp>

"歪み補正された"画像平面に対する内接矩形とバウンディング矩形を返す。

この関数は、指定したカメラ行列、歪み係数、省略可能な3D回転、および"新しい"カメラ行列を用いて、画像平面の歪み補正をシミュレートする。顕著な放射状(あるいはピンクッション)歪みがある場合、矩形の画像平面は歪んで凸または凹の形状になる。この関数は、そのような歪み補正後の近似的な内接(内側)矩形とバウンディング(外側)矩形を計算する。これらの矩形を使ってnewCameraMatrixを調整することで、例えば結果画像が元画像のすべてのデータを収めるようにしたり(その代わり大きな"黒い"領域が生じる可能性がある)、あるいは元画像の端付近のデータを多少失う代わりに黒い領域をなくしたりできる。getOptimalNewCameraMatrix関数は、この関数を使って最適な新しいカメラ行列を計算する。

引数
cameraMatrix元のカメラ行列。
distCoeffs歪み係数。
R投影前に適用する省略可能な3D回転(stereoRectify などを参照)
newCameraMatrix歪み補正後の新しいカメラ行列。通常は元の cameraMatrix と一致する。
imgSize画像平面のサイズ。
inner歪み補正後の画像平面に内接する最大の出力矩形。
outer歪み補正後の画像平面の最小バウンディング矩形(出力)。

◆ matMulDeriv()

void cv::matMulDeriv ( InputArray A,
InputArray B,
OutputArray dABdA,
OutputArray dABdB )
Python:
cv.matMulDeriv(A, B[, dABdA[, dABdB]]) -> dABdA, dABdB

#include <opencv2/geometry/3d.hpp>

乗算される各行列について、行列積の偏微分を計算する。

引数
A1 つ目の乗算される行列。
B2 つ目の乗算される行列。
dABdAサイズ \(\texttt{A.rows*B.cols} \times {A.rows*A.cols}\) の 1 つ目の出力導関数行列 d(A*B)/dA 。
dABdBサイズ \(\texttt{A.rows*B.cols} \times {B.rows*B.cols}\) の 2 つ目の出力導関数行列 d(A*B)/dB 。

この関数は、行列積 \(A*B\) の各要素の、2つの入力行列それぞれの要素に関する偏微分を計算する。この関数はstereoCalibrateでヤコビ行列を計算するために使われるが、他の類似の最適化関数でも使用できる。

◆ projectPoints() [1/2]

void cv::projectPoints ( InputArray objectPoints,
InputArray rvec,
InputArray tvec,
InputArray cameraMatrix,
InputArray distCoeffs,
OutputArray imagePoints,
OutputArray dpdr,
OutputArray dpdt,
OutputArray dpdf = noArray(),
OutputArray dpdc = noArray(),
OutputArray dpdk = noArray(),
OutputArray dpdo = noArray(),
double aspectRatio = 0. )
Python:
cv.projectPoints(objectPoints, rvec, tvec, cameraMatrix, distCoeffs[, imagePoints[, jacobian[, aspectRatio]]]) -> imagePoints, jacobian
cv.projectPointsSepJ(objectPoints, rvec, tvec, cameraMatrix, distCoeffs[, imagePoints[, dpdr[, dpdt[, dpdf[, dpdc[, dpdk[, dpdo[, aspectRatio]]]]]]]]) -> imagePoints, dpdr, dpdt, dpdf, dpdc, dpdk, dpdo

#include <opencv2/geometry/3d.hpp>

これは利便性のために提供されているオーバーロードされたメンバ関数である。上記の関数とは、受け取る引数のみが異なる。

◆ projectPoints() [2/2]

void cv::projectPoints ( InputArray objectPoints,
InputArray rvec,
InputArray tvec,
InputArray cameraMatrix,
InputArray distCoeffs,
OutputArray imagePoints,
OutputArray jacobian = noArray(),
double aspectRatio = 0 )
Python:
cv.projectPoints(objectPoints, rvec, tvec, cameraMatrix, distCoeffs[, imagePoints[, jacobian[, aspectRatio]]]) -> imagePoints, jacobian
cv.projectPointsSepJ(objectPoints, rvec, tvec, cameraMatrix, distCoeffs[, imagePoints[, dpdr[, dpdt[, dpdf[, dpdc[, dpdk[, dpdo[, aspectRatio]]]]]]]]) -> imagePoints, dpdr, dpdt, dpdf, dpdc, dpdk, dpdo

#include <opencv2/geometry/3d.hpp>

3D 点を画像平面に射影する。

この関数は、カメラの内部パラメータと外部パラメータが与えられたとき、3D点の画像平面への2D投影を計算する。オプションで、画像点座標(すべての入力パラメータの関数)の特定のパラメータ(内部および/または外部)に関する偏微分の行列であるヤコビアンを計算する。ヤコビアンはcalibrateCamera, solvePnP, stereoCalibrateでのグローバル最適化中に使用される。この関数自体は、現在の内部・外部パラメータが与えられたときの再投影誤差の計算にも使用できる。

覚え書き
Coordinate Systems:
  • 入力 (objectPoints): ワールド座標フレームにおける3D点。
  • 出力 (imagePoints): 歪みを適用した、画像平面のピクセル座標での2D投影。座標 \((u, v)\) は画像の左上隅からピクセル単位で測定される。

変換の連鎖は次のとおり: ワールド座標 → カメラ座標(rvec/tvec経由) → 正規化カメラ座標 → 歪みの適用 → ピクセル座標(cameraMatrix経由)。

引数
objectPointsワールド座標系を基準として表されたオブジェクト点の配列。3xN/Nx3 の 1 チャンネルまたは 1xN/Nx1 の 3 チャンネル(または vector<Point3f> )で、N はビュー内の点の数。
rvec回転ベクトル(Rodrigues)。tvecと組み合わせることで、ワールド座標系からカメラ座標系への基底変換を行う。詳細はcalibrateCameraを参照。
tvec並進ベクトル。上記の引数の説明を参照。
cameraMatrixカメラの内部行列 \(\cameramatrix{A}\) 。
distCoeffs歪み係数の入力ベクトル \(\distcoeffs\) 。ベクトルが空の場合、歪み係数は 0 と仮定される。
imagePointsピクセル座標での画像点の出力配列。1xN/Nx1の2チャンネル、またはvector<Point2f> 。
jacobian省略可能な出力で、画像点を回転ベクトル・並進ベクトル・焦点距離・主点座標・歪み係数の各成分で微分した 2Nx(10+<numDistCoeffs>) のヤコビ行列。旧インターフェースでは、ヤコビ行列の各成分が異なる出力パラメータを通して返される。
aspectRatio省略可能な「固定アスペクト比」パラメータ。このパラメータが0でない場合、関数はアスペクト比 ( \(f_x / f_y\)) が固定であると仮定し、それに応じてヤコビ行列を調整する。
覚え書き
rvec = tvec = \([0, 0, 0]\) と設定する、cameraMatrix を 3x3 単位行列に設定する、あるいはゼロの歪み係数を渡すことで、この関数のさまざまな有用な部分的ケースを得ることができる。これは、点の疎な集合に対して歪み座標を計算したり、理想的な歪みゼロの設定で透視変換を適用したり(さらに微分を計算したり)できることを意味する。

◆ recoverPose() [1/4]

int cv::recoverPose ( InputArray E,
InputArray points1,
InputArray points2,
InputArray cameraMatrix,
OutputArray R,
OutputArray t,
double distanceThresh,
InputOutputArray mask = noArray(),
OutputArray triangulatedPoints = noArray() )
Python:
cv.recoverPose(points1, points2, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2[, E[, R[, t[, method[, prob[, threshold[, mask]]]]]]]) -> retval, E, R, t, mask
cv.recoverPose(E, points1, points2, cameraMatrix[, R[, t[, mask]]]) -> retval, R, t, mask
cv.recoverPose(E, points1, points2[, R[, t[, focal[, pp[, mask]]]]]) -> retval, R, t, mask
cv.recoverPose(E, points1, points2, cameraMatrix, distanceThresh[, R[, t[, mask[, triangulatedPoints]]]]) -> retval, R, t, mask, triangulatedPoints

#include <opencv2/geometry/3d.hpp>

これは利便性のために提供されているオーバーロードされたメンバ関数である。上記の関数とは、受け取る引数のみが異なる。

引数
E入力の基本行列。
points11枚目の画像に含まれるN個の2D点の配列。点の座標は浮動小数点(単精度または倍精度)である必要がある。
points2points1 と同じサイズおよび形式の、2 枚目の画像の点の配列。
cameraMatrixカメラ内部行列 \(\cameramatrix{A}\) 。この関数は、points1 と points2 が同一のカメラ内部行列を持つカメラから得られた特徴点であることを前提とする点に注意する。
R出力の回転行列。並進ベクトルと組み合わせることで、この行列は1台目のカメラ座標系から2台目のカメラ座標系への基底変換を行うタプルを構成する。一般に、このタプルに t を用いることはできない点に注意する。下記のパラメータ説明を参照。
t出力の並進ベクトル。このベクトルは decomposeEssentialMat によって得られるため、スケールを除いてのみ既知である。すなわち t は並進ベクトルの方向を表し、単位長さを持つ。
distanceThresh遠方の点(すなわち無限遠点)を除外するために用いるしきい値距離。
maskpoints1 と points2 のインライアに対する入出力マスク。空でない場合、与えられた基本行列 E に対する points1 と points2 のインライアを示す。これらのインライアのみが姿勢復元に用いられる。出力マスクには、キラリティチェックを通過したインライアのみが残る。
triangulatedPoints三角測量によって再構成された3D点。

この関数は前述の関数と異なり、カイラリティチェックに使用される三角測量された 3D 点を出力する。

◆ recoverPose() [2/4]

int cv::recoverPose ( InputArray E,
InputArray points1,
InputArray points2,
InputArray cameraMatrix,
OutputArray R,
OutputArray t,
InputOutputArray mask = noArray() )
Python:
cv.recoverPose(points1, points2, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2[, E[, R[, t[, method[, prob[, threshold[, mask]]]]]]]) -> retval, E, R, t, mask
cv.recoverPose(E, points1, points2, cameraMatrix[, R[, t[, mask]]]) -> retval, R, t, mask
cv.recoverPose(E, points1, points2[, R[, t[, focal[, pp[, mask]]]]]) -> retval, R, t, mask
cv.recoverPose(E, points1, points2, cameraMatrix, distanceThresh[, R[, t[, mask[, triangulatedPoints]]]]) -> retval, R, t, mask, triangulatedPoints

#include <opencv2/geometry/3d.hpp>

推定された基本行列と 2 枚の画像内の対応点から、カイラリティチェックを用いてカメラの相対回転と並進を復元する。チェックを通過したインライアの数を返す。

引数
E入力の基本行列。
points11枚目の画像に含まれるN個の2D点の配列。点の座標は浮動小数点(単精度または倍精度)である必要がある。
points2points1 と同じサイズおよび形式の、2 枚目の画像の点の配列。
cameraMatrixカメラ内部行列 \(\cameramatrix{A}\) 。この関数は、points1 と points2 が同一のカメラ内部行列を持つカメラから得られた特徴点であることを前提とする点に注意する。
R出力の回転行列。並進ベクトルと組み合わせることで、この行列は1台目のカメラ座標系から2台目のカメラ座標系への基底変換を行うタプルを構成する。一般に、このタプルに t を用いることはできない点に注意する。下記で説明するパラメータを参照。
t出力の並進ベクトル。このベクトルは decomposeEssentialMat によって得られるため、スケールを除いてのみ既知である。すなわち t は並進ベクトルの方向を表し、単位長さを持つ。
maskpoints1 と points2 のインライアに対する入出力マスク。空でない場合、与えられた基本行列 E に対する points1 と points2 のインライアを示す。これらのインライアのみが姿勢復元に用いられる。出力マスクには、キラリティチェックを通過したインライアのみが残る。

この関数は、decomposeEssentialMatを用いて基本行列を分解し、チラリティチェックを行うことで可能な姿勢の仮説を検証する。チラリティチェックとは、三角測量された3D点が正の奥行きを持つべきであることを意味する。詳細は [216] にある。

この関数は、findEssentialMat の出力である E と mask を処理するために使用できる。このシナリオでは、points1 と points2 は findEssentialMat への同じ入力である。

// Example. Estimation of fundamental matrix using the RANSAC algorithm
int point_count = 100;
vector<Point2f> points1(point_count);
vector<Point2f> points2(point_count);
// initialize the points here ...
for( int i = 0; i < point_count; i++ )
{
points1[i] = ...;
points2[i] = ...;
}
// cametra matrix with both focal lengths = 1, and principal point = (0, 0)
Mat cameraMatrix = Mat::eye(3, 3, CV_64F);
Mat E, R, t, mask;
E = findEssentialMat(points1, points2, cameraMatrix, RANSAC, 0.999, 1.0, mask);
recoverPose(E, points1, points2, cameraMatrix, R, t, mask);
static CV_NODISCARD_STD MatExpr eye(int rows, int cols, int type)
Returns an identity matrix of the specified size and type.
#define CV_64F
Definition interface.h:60
int recoverPose(InputArray points1, InputArray points2, InputArray cameraMatrix1, InputArray distCoeffs1, InputArray cameraMatrix2, InputArray distCoeffs2, OutputArray E, OutputArray R, OutputArray t, int method=cv::RANSAC, double prob=0.999, double threshold=1.0, InputOutputArray mask=noArray())
Recovers the relative camera rotation and the translation from corresponding points in two images fro...
Mat findEssentialMat(InputArray points1, InputArray points2, InputArray cameraMatrix, int method=RANSAC, double prob=0.999, double threshold=1.0, int maxIters=1000, OutputArray mask=noArray())
Calculates an essential matrix from the corresponding points in two images.
@ RANSAC
RANSAC algorithm.
Definition 3d.hpp:373

◆ recoverPose() [3/4]

int cv::recoverPose ( InputArray E,
InputArray points1,
InputArray points2,
OutputArray R,
OutputArray t,
double focal = 1.0,
Point2d pp = Point2d(0, 0),
InputOutputArray mask = noArray() )
Python:
cv.recoverPose(points1, points2, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2[, E[, R[, t[, method[, prob[, threshold[, mask]]]]]]]) -> retval, E, R, t, mask
cv.recoverPose(E, points1, points2, cameraMatrix[, R[, t[, mask]]]) -> retval, R, t, mask
cv.recoverPose(E, points1, points2[, R[, t[, focal[, pp[, mask]]]]]) -> retval, R, t, mask
cv.recoverPose(E, points1, points2, cameraMatrix, distanceThresh[, R[, t[, mask[, triangulatedPoints]]]]) -> retval, R, t, mask, triangulatedPoints

#include <opencv2/geometry/3d.hpp>

これは利便性のために提供されているオーバーロードされたメンバ関数である。上記の関数とは、受け取る引数のみが異なる。

引数
E入力の基本行列。
points11枚目の画像に含まれるN個の2D点の配列。点の座標は浮動小数点(単精度または倍精度)である必要がある。
points2points1 と同じサイズおよび形式の、2 枚目の画像の点の配列。
R出力の回転行列。並進ベクトルと組み合わせることで、この行列は1台目のカメラ座標系から2台目のカメラ座標系への基底変換を行うタプルを構成する。一般に、このタプルに t を用いることはできない点に注意する。下記のパラメータ説明を参照。
t出力の並進ベクトル。このベクトルは decomposeEssentialMat によって得られるため、スケールを除いてのみ既知である。すなわち t は並進ベクトルの方向を表し、単位長さを持つ。
focalカメラの焦点距離。この関数は、points1 と points2 が同一の焦点距離と主点を持つカメラから得られた特徴点であることを前提とする点に注意する。
ppカメラの主点。
maskpoints1 と points2 のインライアに対する入出力マスク。空でない場合、与えられた基本行列 E に対する points1 と points2 のインライアを示す。これらのインライアのみが姿勢復元に用いられる。出力マスクには、キラリティチェックを通過したインライアのみが残る。

この関数は、焦点距離と主点からカメラ内部行列を計算する点で上記の関数と異なる:

\[A = \begin{bmatrix} f & 0 & x_{pp} \\ 0 & f & y_{pp} \\ 0 & 0 & 1 \end{bmatrix}\]

◆ recoverPose() [4/4]

int cv::recoverPose ( InputArray points1,
InputArray points2,
InputArray cameraMatrix1,
InputArray distCoeffs1,
InputArray cameraMatrix2,
InputArray distCoeffs2,
OutputArray E,
OutputArray R,
OutputArray t,
int method = cv::RANSAC,
double prob = 0.999,
double threshold = 1.0,
InputOutputArray mask = noArray() )
Python:
cv.recoverPose(points1, points2, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2[, E[, R[, t[, method[, prob[, threshold[, mask]]]]]]]) -> retval, E, R, t, mask
cv.recoverPose(E, points1, points2, cameraMatrix[, R[, t[, mask]]]) -> retval, R, t, mask
cv.recoverPose(E, points1, points2[, R[, t[, focal[, pp[, mask]]]]]) -> retval, R, t, mask
cv.recoverPose(E, points1, points2, cameraMatrix, distanceThresh[, R[, t[, mask[, triangulatedPoints]]]]) -> retval, R, t, mask, triangulatedPoints

#include <opencv2/geometry/3d.hpp>

異なる2台のカメラで撮影した2枚の画像中の対応点から、相対的なカメラの回転と並進を、チラリティチェックを用いて復元する。チェックを通過したインライアの数を返す。

引数
points11枚目の画像に含まれるN個の2D点の配列。点の座標は浮動小数点(単精度または倍精度)である必要がある。
points2points1 と同じサイズおよび形式の、2 枚目の画像の点の配列。
cameraMatrix11台目のカメラの入出力カメラ行列。calibrateCameraと同じ。さらにステレオの場合は追加のフラグを使用できる。下記参照。
distCoeffs1歪み係数の入出力ベクトル。calibrateCameraと同じ。
cameraMatrix21台目のカメラの入出力カメラ行列。calibrateCameraと同じ。さらにステレオの場合は追加のフラグを使用できる。下記参照。
distCoeffs2歪み係数の入出力ベクトル。calibrateCameraと同じ。
E出力の基本行列。
R出力の回転行列。並進ベクトルと組み合わせることで、この行列は1台目のカメラ座標系から2台目のカメラ座標系への基底変換を行うタプルを構成する。一般に、このタプルに t を用いることはできない点に注意する。下記で説明するパラメータを参照。
t出力の並進ベクトル。このベクトルは decomposeEssentialMat によって得られるため、スケールを除いてのみ既知である。すなわち t は並進ベクトルの方向を表し、単位長さを持つ。
method基本行列の計算手法。
  • RANSACアルゴリズムには RANSAC
  • LMedSアルゴリズムには LMEDS
probRANSAC または LMedS 手法でのみ使用される引数。推定された行列が正しいという望ましい信頼水準(確率)を指定する。
thresholdRANSAC で使用される引数。点からエピポーラ線までの最大距離(ピクセル単位)であり、これを超える点はアウトライアとみなされ、最終的な基礎行列の計算には使用されない。点の位置特定の精度、画像の解像度、画像のノイズに応じて、1〜3 程度の値に設定できる。
maskpoints1 と points2 のインライアに対する入出力マスク。空でない場合、与えられた基本行列 E に対する points1 と points2 のインライアを示す。これらのインライアのみが姿勢復元に用いられる。出力マスクには、キラリティチェックを通過したインライアのみが残る。

この関数は、decomposeEssentialMatを用いて基本行列を分解し、チラリティチェックを行うことで可能な姿勢の仮説を検証する。チラリティチェックとは、三角測量された3D点が正の奥行きを持つべきであることを意味する。詳細は [216] にある。

この関数は、findEssentialMat の出力である E と mask を処理するために使用できる。このシナリオでは、points1 と points2 は findEssentialMat への同じ入力である。

// Example. Estimation of fundamental matrix using the RANSAC algorithm
int point_count = 100;
vector<Point2f> points1(point_count);
vector<Point2f> points2(point_count);
// initialize the points here ...
for( int i = 0; i < point_count; i++ )
{
points1[i] = ...;
points2[i] = ...;
}
// Input: camera calibration of both cameras, for example using intrinsic chessboard calibration.
Mat cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2;
// Output: Essential matrix, relative rotation and relative translation.
Mat E, R, t, mask;
recoverPose(points1, points2, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, E, R, t, mask);

◆ Rodrigues()

void cv::Rodrigues ( InputArray src,
OutputArray dst,
OutputArray jacobian = noArray() )
Python:
cv.Rodrigues(src[, dst[, jacobian]]) -> dst, jacobian

#include <opencv2/geometry/3d.hpp>

回転行列を回転ベクトルに、またはその逆に変換する。

引数
src入力の回転ベクトル (3x1 または 1x3) もしくは回転行列 (3x3)。
dst出力の回転行列 (3x3) もしくは回転ベクトル (3x1 または 1x3)。それぞれ入力に対応する。
jacobian省略可能な出力ヤコビ行列 (3x9 または 9x3)。出力配列の成分を入力配列の成分で偏微分した行列である。

\[\begin{array}{l} \theta \leftarrow norm(r) \\ r \leftarrow r/ \theta \\ R = \cos(\theta) I + (1- \cos{\theta} ) r r^T + \sin(\theta) \vecthreethree{0}{-r_z}{r_y}{r_z}{0}{-r_x}{-r_y}{r_x}{0} \end{array}\]

逆変換も同様に簡単に行える。なぜなら

\[\sin ( \theta ) \vecthreethree{0}{-r_z}{r_y}{r_z}{0}{-r_x}{-r_y}{r_x}{0} = \frac{R - R^T}{2}\]

回転ベクトルは、回転行列の便利で最もコンパクトな表現である(任意の回転行列はわずか3自由度しか持たないため)。この表現は、calibrateCamera, stereoCalibrate, solvePnP のようなグローバルな3D幾何最適化手順で使用される。

覚え書き
More information about the computation of the derivative of a 3D rotation matrix with respect to its exponential coordinate can be found in:
  • A Compact Formula for the Derivative of a 3-D Rotation in Exponential Coordinates, Guillermo Gallego, Anthony J. Yezzi [101]
Useful information on SE(3) and Lie Groups can be found in:
  • A tutorial on SE(3) transformation parameterizations and on-manifold optimization, Jose-Luis Blanco [31]
  • Lie Groups for 2D and 3D Transformation, Ethan Eade [82]
  • A micro Lie theory for state estimation in robotics, Joan Solà, Jérémie Deray, Dinesh Atchuthan [258]

◆ RQDecomp3x3()

Vec3d cv::RQDecomp3x3 ( InputArray src,
OutputArray mtxR,
OutputArray mtxQ,
OutputArray Qx = noArray(),
OutputArray Qy = noArray(),
OutputArray Qz = noArray() )
Python:
cv.RQDecomp3x3(src[, mtxR[, mtxQ[, Qx[, Qy[, Qz]]]]]) -> retval, mtxR, mtxQ, Qx, Qy, Qz

#include <opencv2/geometry/3d.hpp>

3x3 行列の RQ 分解を計算する。

引数
src3x3 の入力行列。
mtxR出力の 3x3 上三角行列。
mtxQ出力の 3x3 直交行列。
Qx省略可能な出力で、x軸まわりの 3x3 回転行列。
Qy省略可能な出力で、y軸まわりの 3x3 回転行列。
Qz省略可能な出力で、z軸まわりの 3x3 回転行列。

この関数は、与えられた回転を用いて RQ 分解を計算する。この関数は decomposeProjectionMatrix において、射影行列の左 3x3 部分行列をカメラ行列と回転行列に分解するために使用される。

オプションで、各軸に対応する3つの回転行列と、OpenGLで使用できる3つのオイラー角(度数、戻り値として)を返す。なお、ある物体の同じ姿勢をもたらす3つの主軸まわりの回転の列は、常に複数存在することに注意する(例えば [257] を参照)。返される3つの回転行列と対応する3つのオイラー角は、あり得る解の1つにすぎない。

◆ sampsonDistance()

double cv::sampsonDistance ( InputArray pt1,
InputArray pt2,
InputArray F )
Python:
cv.sampsonDistance(pt1, pt2, F) -> retval

#include <opencv2/geometry/3d.hpp>

2 点間のサンプソン距離を計算する。

関数 cv::sampsonDistance は、幾何誤差の 1 次近似を次のように計算して返す。

\[ sd( \texttt{pt1} , \texttt{pt2} )= \frac{(\texttt{pt2}^t \cdot \texttt{F} \cdot \texttt{pt1})^2} {((\texttt{F} \cdot \texttt{pt1})(0))^2 + ((\texttt{F} \cdot \texttt{pt1})(1))^2 + ((\texttt{F}^t \cdot \texttt{pt2})(0))^2 + ((\texttt{F}^t \cdot \texttt{pt2})(1))^2} \]

基礎行列はfindFundamentalMat関数を使って計算できる。詳細は [121] の11.4.3を参照。

引数
pt11番目の同次2D点。
pt22番目の同次2D点。
F基礎行列。
戻り値
計算されたサンプソン距離。

◆ solveP3P()

int cv::solveP3P ( InputArray objectPoints,
InputArray imagePoints,
InputArray cameraMatrix,
InputArray distCoeffs,
OutputArrayOfArrays rvecs,
OutputArrayOfArrays tvecs,
int flags )
Python:
cv.solveP3P(objectPoints, imagePoints, cameraMatrix, distCoeffs, flags[, rvecs[, tvecs]]) -> retval, rvecs, tvecs

#include <opencv2/geometry/3d.hpp>

3 組の 3D-2D 点対応から物体姿勢 \( {}^{c}\mathbf{T}_o \) を求める。

Perspective projection, from object to camera frame
参照
Perspective-n-Point (PnP) による姿勢推定
引数
objectPoints物体座標空間における物体点の配列。3x3 1チャンネル、または 1x3/3x1 3チャンネル。vector<Point3f> をここに渡すこともできる。
imagePoints対応する画像点の配列。3x2 1チャンネル、または 1x3/3x1 2チャンネル。vector<Point2f> をここに渡すこともできる。
cameraMatrix入力のカメラ内部行列 \(\cameramatrix{A}\) 。
distCoeffs歪み係数の入力ベクトル \(\distcoeffs\)。ベクトルが NULL/空の場合、歪み係数は 0 と仮定される。
rvecs出力の回転ベクトル(Rodrigues を参照)。tvecs と組み合わせることで、モデル座標系からカメラ座標系へ点を移す。P3P問題は最大4個の解を持つ。
tvecs出力の並進ベクトル。
flagsP3P問題を解くための手法:
  • SOLVEPNP_P3P Ding, Y., Yang, J., Larsson, V., Olsson, C., & Åstrom, K. の論文 "Revisiting the P3P Problem" ([73]) に基づく手法。
  • SOLVEPNP_AP3P T. Ke と S. Roumeliotis の論文 "An Efficient Algebraic Solution to the Perspective-Three-Point Problem" ([149]) に基づく手法。

この関数は、3 つの物体点、それらに対応する画像投影、ならびにカメラ内部行列と歪み係数が与えられたとき、物体姿勢を推定する。

覚え書き
解は再投影誤差の小さい順(低い順から高い順)にソートされる。

◆ solvePnP()

bool cv::solvePnP ( InputArray objectPoints,
InputArray imagePoints,
InputArray cameraMatrix,
InputArray distCoeffs,
OutputArray rvec,
OutputArray tvec,
bool useExtrinsicGuess = false,
int flags = SOLVEPNP_ITERATIVE )
Python:
cv.solvePnP(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, useExtrinsicGuess[, flags]]]]) -> retval, rvec, tvec

#include <opencv2/geometry/3d.hpp>

3D-2D 点対応から物体姿勢 \( {}^{c}\mathbf{T}_o \) を求める。

Perspective projection, from object to camera frame
参照
Perspective-n-Point (PnP) による姿勢推定

この関数は、物体座標系で表された 3D 点をカメラ座標系へ変換する回転ベクトルと並進ベクトルを、さまざまな手法を用いて返す。

  • P3P 手法(SOLVEPNP_P3P, SOLVEPNP_AP3P): 一意の解を返すには 4 つの入力点が必要である。
  • SOLVEPNP_IPPE 入力点は >= 4 でなければならず、物体点は同一平面上になければならない。
  • SOLVEPNP_IPPE_SQUARE Special case suitable for marker pose estimation. Number of input points must be 4. Object points must be defined in the following order:
    • 点 0: [-squareLength / 2, squareLength / 2, 0]
    • 点 1: [ squareLength / 2, squareLength / 2, 0]
    • 点 2: [ squareLength / 2, -squareLength / 2, 0]
    • 点 3: [-squareLength / 2, -squareLength / 2, 0]
  • それ以外のすべてのフラグでは、入力点の数は >= 4 でなければならず、オブジェクト点は任意の配置でよい。
引数
objectPoints物体座標空間における物体点の配列。Nx3 1チャンネル、または 1xN/Nx1 3チャンネル(Nは点の個数)。vector<Point3d> をここに渡すこともできる。
imagePoints対応する画像点の配列。Nx2 1チャンネル、または 1xN/Nx1 2チャンネル(Nは点の個数)。vector<Point2d> をここに渡すこともできる。
cameraMatrix入力のカメラ内部行列 \(\cameramatrix{A}\) 。
distCoeffs歪み係数の入力ベクトル \(\distcoeffs\)。ベクトルが NULL/空の場合、歪み係数は 0 と仮定される。
rvec出力の回転ベクトル(Rodrigues を参照)。tvec と組み合わせることで、モデル座標系からカメラ座標系へ点を移す。
tvec出力の並進ベクトル。
useExtrinsicGuessSOLVEPNP_ITERATIVE で用いられるパラメータ。true (1) の場合、関数は与えられた rvec と tvec の値を回転ベクトルと並進ベクトルの初期近似値として使用し、さらにそれらを最適化する。
flagsPnP問題を解くための手法。calib3d_solvePnP_flags を参照。

Perspective-n-Point に関する詳しい情報は Perspective-n-Point (PnP) による姿勢推定 に記載されている。

覚え書き
  • 平面拡張現実に solvePnP を使用する方法の例は opencv_source_code/samples/python/plane_ar.py にある。
  • If you are using Python:
    • solvePnPは連続したメモリ配列を必要とする(modules/3d/src/solvepnp.cppバージョン2.4.9の55行目付近でcv::Mat::checkVector()を用いるアサーションで強制される)ため、Numpy配列のスライスは入力として機能しない。
    • P3Pアルゴリズムは、2チャンネルの情報を必要とするundistortPointsを呼び出す(modules/3d/src/solvepnp.cppバージョン2.4.9の75行目付近)ため、画像点が形状(N,1,2)の配列であることを要求する。
    • したがって、D.shape = (N,M) であるデータ D = np.array(...) が与えられたとき、その一部を例えば imagePoints として使用するには、新しい配列にコピーする必要が実質的にある: imagePoints = np.ascontiguousarray(D[:,:2]).reshape((N,1,2))
  • 一般的な場合、点の最小数は 4 である。SOLVEPNP_P3P および SOLVEPNP_AP3P 手法の場合、正確に 4 点を使用する必要がある(最初の 3 点は P3P 問題のすべての解を推定するために使用され、最後の 1 点は再投影誤差を最小化する最良の解を保持するために使用される)。
  • SOLVEPNP_ITERATIVE 手法かつ useExtrinsicGuess=true の場合、点の最小数は 3 である(3 点で姿勢を計算するには十分だが、最大 4 つの解が存在する)。収束させるには、初期解が大域解に近い必要がある。何らかの解が見つかった場合、関数は true を返す。解の品質評価はユーザーのコードが担う。
  • SOLVEPNP_IPPE では、入力点は >= 4 でなければならず、物体点は同一平面上になければならない。
  • With SOLVEPNP_IPPE_SQUARE this is a special case suitable for marker pose estimation. Number of input points must be 4. Object points must be defined in the following order:
    • 点 0: [-squareLength / 2, squareLength / 2, 0]
    • 点 1: [ squareLength / 2, squareLength / 2, 0]
    • 点 2: [ squareLength / 2, -squareLength / 2, 0]
    • 点 3: [-squareLength / 2, -squareLength / 2, 0]
  • SOLVEPNP_SQPNP では、入力点は >= 3 でなければならない。

◆ solvePnPGeneric()

int cv::solvePnPGeneric ( InputArray objectPoints,
InputArray imagePoints,
InputArray cameraMatrix,
InputArray distCoeffs,
OutputArrayOfArrays rvecs,
OutputArrayOfArrays tvecs,
bool useExtrinsicGuess = false,
int flags = SOLVEPNP_ITERATIVE,
InputArray rvec = noArray(),
InputArray tvec = noArray(),
OutputArray reprojectionError = noArray() )
Python:
cv.solvePnPGeneric(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvecs[, tvecs[, useExtrinsicGuess[, flags[, rvec[, tvec[, reprojectionError]]]]]]]) -> retval, rvecs, tvecs, reprojectionError

#include <opencv2/geometry/3d.hpp>

3D-2D 点対応から物体姿勢 \( {}^{c}\mathbf{T}_o \) を求める。

Perspective projection, from object to camera frame
参照
Perspective-n-Point (PnP) による姿勢推定

この関数は、入力点の数と選択した手法に応じて、可能なすべての解のリスト(解は <回転ベクトル, 並進ベクトル> の組)を返す。

  • P3P 手法(SOLVEPNP_P3P, SOLVEPNP_AP3P): 3 または 4 つの入力点。3 つの入力点の場合、返される解の数は 0 から 4 の間になりうる。
  • SOLVEPNP_IPPE 入力点は4個以上で、オブジェクト点は同一平面上になければならない。2つの解を返す。
  • SOLVEPNP_IPPE_SQUARE Special case suitable for marker pose estimation. Number of input points must be 4 and 2 solutions are returned. Object points must be defined in the following order:
    • 点 0: [-squareLength / 2, squareLength / 2, 0]
    • 点 1: [ squareLength / 2, squareLength / 2, 0]
    • 点 2: [ squareLength / 2, -squareLength / 2, 0]
    • 点 3: [-squareLength / 2, -squareLength / 2, 0]
  • その他すべてのフラグでは、入力点の数は4個以上でなければならず、オブジェクト点は任意の配置でよい。返される解は1つだけである。
引数
objectPoints物体座標空間における物体点の配列。Nx3 1チャンネル、または 1xN/Nx1 3チャンネル(Nは点の個数)。vector<Point3d> をここに渡すこともできる。
imagePoints対応する画像点の配列。Nx2 1チャンネル、または 1xN/Nx1 2チャンネル(Nは点の個数)。vector<Point2d> をここに渡すこともできる。
cameraMatrix入力のカメラ内部行列 \(\cameramatrix{A}\) 。
distCoeffs歪み係数の入力ベクトル \(\distcoeffs\)。ベクトルが NULL/空の場合、歪み係数は 0 と仮定される。
rvecs出力の回転ベクトル(Rodrigues を参照)のベクトル。tvecs と組み合わせることで、モデル座標系からカメラ座標系へ点を移す。
tvecs出力の並進ベクトルのベクトル。
useExtrinsicGuessSOLVEPNP_ITERATIVE で用いられるパラメータ。true (1) の場合、関数は与えられた rvec と tvec の値を回転ベクトルと並進ベクトルの初期近似値として使用し、さらにそれらを最適化する。
flagsPnP問題を解くための手法。calib3d_solvePnP_flags を参照。
rvec反復的なPnP精緻化アルゴリズムを初期化するために使用する回転ベクトル。フラグが SOLVEPNP_ITERATIVE で useExtrinsicGuess が true に設定されている場合に用いられる。
tvec反復的なPnP精緻化アルゴリズムを初期化するために使用する並進ベクトル。フラグが SOLVEPNP_ITERATIVE で useExtrinsicGuess が true に設定されている場合に用いられる。
reprojectionError省略可能な再投影誤差のベクトル。入力画像点と、推定姿勢で投影した3D物体点との間のRMS誤差( \( \text{RMSE} = \sqrt{\frac{\sum_{i}^{N} \left ( \hat{y_i} - y_i \right )^2}{N}} \))である。

詳細は Perspective-n-Point (PnP) による姿勢推定 で説明されている。

覚え書き
  • 平面拡張現実に solvePnP を使用する方法の例は opencv_source_code/samples/python/plane_ar.py にある。
  • If you are using Python:
    • solvePnPは連続したメモリ配列を必要とする(modules/3d/src/solvepnp.cppバージョン2.4.9の55行目付近でcv::Mat::checkVector()を用いるアサーションで強制される)ため、Numpy配列のスライスは入力として機能しない。
    • P3Pアルゴリズムは、2チャンネルの情報を必要とするundistortPointsを呼び出す(modules/3d/src/solvepnp.cppバージョン2.4.9の75行目付近)ため、画像点が形状(N,1,2)の配列であることを要求する。
    • したがって、D.shape = (N,M) であるデータ D = np.array(...) が与えられたとき、その一部を例えば imagePoints として使用するには、新しい配列にコピーする必要が実質的にある: imagePoints = np.ascontiguousarray(D[:,:2]).reshape((N,1,2))
  • 一般的な場合、点の最小数は 4 である。SOLVEPNP_P3P および SOLVEPNP_AP3P 手法の場合、正確に 4 点を使用する必要がある(最初の 3 点は P3P 問題のすべての解を推定するために使用され、最後の 1 点は再投影誤差を最小化する最良の解を保持するために使用される)。
  • SOLVEPNP_ITERATIVE 法で useExtrinsicGuess=true の場合、点の最小数は3である(3点で姿勢を計算できるが、最大4つの解が存在しうる)。収束させるには初期解が大域解に近いことが望ましい。
  • SOLVEPNP_IPPE では、入力点は >= 4 でなければならず、物体点は同一平面上になければならない。
  • With SOLVEPNP_IPPE_SQUARE this is a special case suitable for marker pose estimation. Number of input points must be 4. Object points must be defined in the following order:
    • 点 0: [-squareLength / 2, squareLength / 2, 0]
    • 点 1: [ squareLength / 2, squareLength / 2, 0]
    • 点 2: [ squareLength / 2, -squareLength / 2, 0]
    • 点 3: [-squareLength / 2, -squareLength / 2, 0]
  • SOLVEPNP_SQPNP では、入力点は >= 3 でなければならない。

◆ solvePnPRansac() [1/2]

bool cv::solvePnPRansac ( InputArray objectPoints,
InputArray imagePoints,
InputArray cameraMatrix,
InputArray distCoeffs,
OutputArray rvec,
OutputArray tvec,
bool useExtrinsicGuess = false,
int iterationsCount = 100,
float reprojectionError = 8.0,
double confidence = 0.99,
OutputArray inliers = noArray(),
int flags = SOLVEPNP_ITERATIVE )
Python:
cv.solvePnPRansac(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, useExtrinsicGuess[, iterationsCount[, reprojectionError[, confidence[, inliers[, flags]]]]]]]]) -> retval, rvec, tvec, inliers
cv.solvePnPRansac(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, inliers[, params]]]]) -> retval, cameraMatrix, rvec, tvec, inliers

#include <opencv2/geometry/3d.hpp>

不正なマッチに対処するためRANSACスキームを用いて、3D-2D点対応からオブジェクト姿勢 \( {}^{c}\mathbf{T}_o \) を求める。

Perspective projection, from object to camera frame
参照
Perspective-n-Point (PnP) による姿勢推定
引数
objectPoints物体座標空間における物体点の配列。Nx3 1チャンネル、または 1xN/Nx1 3チャンネル(Nは点の個数)。vector<Point3d> をここに渡すこともできる。
imagePoints対応する画像点の配列。Nx2 1チャンネル、または 1xN/Nx1 2チャンネル(Nは点の個数)。vector<Point2d> をここに渡すこともできる。
cameraMatrix入力のカメラ内部行列 \(\cameramatrix{A}\) 。
distCoeffs歪み係数の入力ベクトル \(\distcoeffs\)。ベクトルが NULL/空の場合、歪み係数は 0 と仮定される。
rvec出力の回転ベクトル(Rodrigues を参照)。tvec と組み合わせることで、モデル座標系からカメラ座標系へ点を移す。
tvec出力の並進ベクトル。
useExtrinsicGuessSOLVEPNP_ITERATIVE で用いられるパラメータ。true (1) の場合、関数は与えられた rvec と tvec の値を回転ベクトルと並進ベクトルの初期近似値として使用し、さらにそれらを最適化する。
iterationsCount反復回数。
reprojectionErrorRANSAC手続きで用いられるインライアのしきい値。このパラメータ値は、観測された点投影と計算された点投影の間で、インライアとみなすための最大許容距離である。
confidenceアルゴリズムが有用な結果を生成する確率。
inliersobjectPoints と imagePoints 内のインライアのインデックスを含む出力ベクトル。
flagsPnP問題を解くための手法(solvePnP を参照)。

この関数は、与えられたオブジェクト点の集合、それに対応する画像投影、ならびにカメラ内部行列と歪み係数からオブジェクト姿勢を推定する。この関数は再投影誤差、すなわち観測された投影 imagePoints と(projectPoints を用いて)投影された objectPoints との二乗距離の総和を最小化するような姿勢を求める。RANSACの利用により、この関数は外れ値に対して頑健になる。

覚え書き

◆ solvePnPRansac() [2/2]

bool cv::solvePnPRansac ( InputArray objectPoints,
InputArray imagePoints,
InputOutputArray cameraMatrix,
InputArray distCoeffs,
OutputArray rvec,
OutputArray tvec,
OutputArray inliers,
const UsacParams & params = UsacParams() )
Python:
cv.solvePnPRansac(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, useExtrinsicGuess[, iterationsCount[, reprojectionError[, confidence[, inliers[, flags]]]]]]]]) -> retval, rvec, tvec, inliers
cv.solvePnPRansac(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, inliers[, params]]]]) -> retval, cameraMatrix, rvec, tvec, inliers

◆ solvePnPRefineLM()

void cv::solvePnPRefineLM ( InputArray objectPoints,
InputArray imagePoints,
InputArray cameraMatrix,
InputArray distCoeffs,
InputOutputArray rvec,
InputOutputArray tvec,
TermCriteria criteria = TermCriteria(TermCriteria::EPS+TermCriteria::COUNT, 20, FLT_EPSILON) )
Python:
cv.solvePnPRefineLM(objectPoints, imagePoints, cameraMatrix, distCoeffs, rvec, tvec[, criteria]) -> rvec, tvec

#include <opencv2/geometry/3d.hpp>

3D-2D点対応から、初期解を起点として姿勢(オブジェクト座標系で表現された3D点をカメラ座標系へ変換する並進と回転)を精緻化する。

参照
Perspective-n-Point (PnP) による姿勢推定
引数
objectPoints物体座標空間における物体点の配列。Nx3 1チャンネル、または 1xN/Nx1 3チャンネル(Nは点の個数)。vector<Point3d> をここに渡すこともできる。
imagePoints対応する画像点の配列。Nx2 1チャンネル、または 1xN/Nx1 2チャンネル(Nは点の個数)。vector<Point2d> をここに渡すこともできる。
cameraMatrix入力のカメラ内部行列 \(\cameramatrix{A}\) 。
distCoeffs歪み係数の入力ベクトル \(\distcoeffs\)。ベクトルが NULL/空の場合、歪み係数は 0 と仮定される。
rvec入出力の回転ベクトル(Rodrigues を参照)。tvec と組み合わせることで、モデル座標系からカメラ座標系へ点を移す。入力値は初期解として使用される。
tvec入出力の並進ベクトル。入力値は初期解として使用される。
criteriaLevenberg-Marquardt反復アルゴリズムを停止する条件。

この関数は、少なくとも3つの物体点、それらに対応する画像投影、回転・並進ベクトルの初期解、ならびにカメラ内部行列と歪み係数が与えられたとき、物体の姿勢を精緻化する。この関数は、Levenberg-Marquardt反復最小化 [185] [81] の処理に従って、回転ベクトルと並進ベクトルに関する投影誤差を最小化する。

◆ solvePnPRefineVVS()

void cv::solvePnPRefineVVS ( InputArray objectPoints,
InputArray imagePoints,
InputArray cameraMatrix,
InputArray distCoeffs,
InputOutputArray rvec,
InputOutputArray tvec,
TermCriteria criteria = TermCriteria(TermCriteria::EPS+TermCriteria::COUNT, 20, FLT_EPSILON),
double VVSlambda = 1 )
Python:
cv.solvePnPRefineVVS(objectPoints, imagePoints, cameraMatrix, distCoeffs, rvec, tvec[, criteria[, VVSlambda]]) -> rvec, tvec

#include <opencv2/geometry/3d.hpp>

3D-2D点対応から、初期解を起点として姿勢(オブジェクト座標系で表現された3D点をカメラ座標系へ変換する並進と回転)を精緻化する。

参照
Perspective-n-Point (PnP) による姿勢推定
引数
objectPoints物体座標空間における物体点の配列。Nx3 1チャンネル、または 1xN/Nx1 3チャンネル(Nは点の個数)。vector<Point3d> をここに渡すこともできる。
imagePoints対応する画像点の配列。Nx2 1チャンネル、または 1xN/Nx1 2チャンネル(Nは点の個数)。vector<Point2d> をここに渡すこともできる。
cameraMatrix入力のカメラ内部行列 \(\cameramatrix{A}\) 。
distCoeffs歪み係数の入力ベクトル \(\distcoeffs\)。ベクトルが NULL/空の場合、歪み係数は 0 と仮定される。
rvec入出力の回転ベクトル(Rodrigues を参照)。tvec と組み合わせることで、モデル座標系からカメラ座標系へ点を移す。入力値は初期解として使用される。
tvec入出力の並進ベクトル。入力値は初期解として使用される。
criteriaLevenberg-Marquardt反復アルゴリズムを停止する条件。
VVSlambda仮想視覚サーボ制御則のゲイン。減衰Gauss-Newton定式化における \(\alpha\) ゲインに相当する。

この関数は、少なくとも3つの物体点、それらに対応する画像投影、回転・並進ベクトルの初期解、ならびにカメラ内部行列と歪み係数が与えられたとき、物体の姿勢を精緻化する。この関数は、仮想ビジュアルサーボイング(VVS) [54] [189] 方式を用いて、回転ベクトルと並進ベクトルに関する投影誤差を最小化する。

◆ triangulatePoints()

void cv::triangulatePoints ( InputArray projMatr1,
InputArray projMatr2,
InputArray projPoints1,
InputArray projPoints2,
OutputArray points4D )
Python:
cv.triangulatePoints(projMatr1, projMatr2, projPoints1, projPoints2[, points4D]) -> points4D

#include <opencv2/geometry/3d.hpp>

この関数は、ステレオカメラによる観測を用いて3次元点を(同次座標で)再構成する。

引数
projMatr11台目のカメラの3x4射影行列。すなわち、この行列はワールド座標系で与えられた3D点を1枚目の画像へ射影する。
projMatr22台目のカメラの3x4射影行列。すなわち、この行列はワールド座標系で与えられた3D点を2枚目の画像へ射影する。
projPoints11枚目の画像内の特徴点の2xN配列。C++版の場合、特徴点のベクトル、またはサイズ 1xN もしくは Nx1 の2チャンネル行列でもよい。
projPoints22枚目の画像内の対応する点の2xN配列。C++版の場合、特徴点のベクトル、またはサイズ 1xN もしくは Nx1 の2チャンネル行列でもよい。
points4D同次座標で再構成された点の4xN配列。これらの点はワールド座標系で返される。
覚え書き
この関数が動作するには、すべての入力データがfloat型でなければならないことに注意する。
stereoRectifyからの射影行列を使用する場合、返される点は1台目のカメラの平行化座標系で表される。
参照
reprojectImageTo3D

◆ undistortImagePoints()

void cv::undistortImagePoints ( InputArray src,
OutputArray dst,
InputArray cameraMatrix,
InputArray distCoeffs,
TermCriteria = TermCriteria(TermCriteria::MAX_ITER, 5, 0.01) )
Python:
cv.undistortImagePoints(src, cameraMatrix, distCoeffs[, dst[, arg1]]) -> dst

#include <opencv2/geometry/3d.hpp>

歪み補正された画像点の位置を計算する。

引数
src観測された点の位置。2xN/Nx2 の1チャンネル、または 1xN/Nx1 の2チャンネル(CV_32FC2 または CV_64FC2)(あるいは vector<Point2f> )。
dst出力の歪み補正された点の位置(1xN/Nx1 の2チャンネル、または vector<Point2f> )。
cameraMatrixカメラ行列 \(\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\) 。
distCoeffs歪み係数

◆ undistortPoints()

void cv::undistortPoints ( InputArray src,
OutputArray dst,
InputArray cameraMatrix,
InputArray distCoeffs,
InputArray R = noArray(),
InputArray P = noArray(),
TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER, 5, 0.01) )
Python:
cv.undistortPoints(src, cameraMatrix, distCoeffs[, dst[, R[, P[, criteria]]]]) -> dst

#include <opencv2/geometry/3d.hpp>

観測された点の座標から理想的な点の座標を計算する。

この関数はundistortinitUndistortRectifyMapに似ているが、ラスター画像ではなく疎な点集合に対して動作する。またこの関数はprojectPointsの逆変換を行う。3D物体の場合は3D座標を復元しないが、平面物体の場合は、適切なRが指定されていれば並進ベクトルを除いて復元する。

観測された各点の座標 \((u, v)\) について、この関数は次を計算する:

\[ \begin{array}{l} x^{"} \leftarrow (u - c_x)/f_x \\ y^{"} \leftarrow (v - c_y)/f_y \\ (x',y') = undistort(x^{"},y^{"}, \texttt{distCoeffs}) \\ {[X\,Y\,W]} ^T \leftarrow R*[x' \, y' \, 1]^T \\ x \leftarrow X/W \\ y \leftarrow Y/W \\ \text{only performed if P is specified:} \\ u' \leftarrow x {f'}_x + {c'}_x \\ v' \leftarrow y {f'}_y + {c'}_y \end{array} \]

ここで undistort は、正規化された歪んだ点の座標から正規化された元の点の座標を推定する近似的な反復アルゴリズムである(「正規化」とは座標がカメラ行列に依存しないことを意味する)。

この関数は、ステレオカメラヘッドと単眼カメラ(R が空の場合)の両方に使用できる。

覚え書き
Coordinate Systems:
  • 入力 (src): 点は歪んだ画像のピクセル座標で与えられることが期待される。すなわち、画像の左上隅からピクセル単位で測定される座標 \((u, v)\)。
  • Output (dst): The coordinate system of output points depends on parameter P:
    • P が指定されている(空でない)場合: 出力点は、カメラ行列 P を用いた平行化/歪み除去後の画像平面のピクセル座標になる。
    • Pが空または恒等の場合: 出力点は正規化カメラ座標("正規化画像座標"とも呼ばれる)となる。これはカメラの焦点面における無次元の座標 \((x, y)\) で、ピクセル座標とは \(x = (u - c_x) / f_x\) および \(y = (v - c_y) / f_y\) の関係にある。これらの正規化座標はカメラの内部パラメータに依存せず、3D復元やエピポーラ幾何に有用である。
引数
src歪んだ画像における観測点のピクセル座標。2xN/Nx2の1チャンネル、または1xN/Nx1の2チャンネル(CV_32FC2またはCV_64FC2)(あるいはvector<Point2f> )。
dst歪み補正および逆透視変換後の出力の理想点座標(1xN/Nx1 の2チャンネル、または vector<Point2f> )。行列 P が単位行列または省略された場合、dst には正規化された点座標が格納される。
cameraMatrixカメラ行列 \(\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\) 。
distCoeffs歪み係数の入力ベクトル \((k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\) で、4, 5, 8, 12, または 14 要素。ベクトルが NULL/空の場合、歪み係数は 0 と仮定される。
R対象空間における平行化変換(3x3行列)。stereoRectifyで計算したR1またはR2を渡せる。行列が空の場合は恒等変換を使用する。
P新しいカメラ行列(3x3)、または新しい射影行列(3x4) \(\begin{bmatrix} {f'}_x & 0 & {c'}_x & t_x \\ 0 & {f'}_y & {c'}_y & t_y \\ 0 & 0 & 1 & t_z \end{bmatrix}\)。stereoRectifyで計算したP1またはP2を渡せる。行列が空の場合は恒等の新しいカメラ行列を使用し、出力は正規化座標になる。
criteria反復的な点の歪み補正アルゴリズムの終了条件。