1 投影
void cv::projectPoints(
cv::InputArray objectPoints,
cv::InputArray rvec,
cv::InputArray tvec,
cv::InputArray cameraMatrix,
cv::InputArray distCoeffs,
cv::OutputArray imagePoints,
cv::OutputArray jacobian = cv::noArray(),
double aspectRatio = 0
)
2 仿射变换和透视变换
函数 | 用法 |
---|
cv::transform() | 仿射变换一系列点 |
cv::warpAffine() | 仿射变换整幅图 |
cv::getAffineTransform() | 从点计算仿射矩阵 |
cv::getRotationMatrix2D() | 计算仿射矩阵获得旋转 |
cv::perspectiveTransform() | 透视变换一系列点 |
cv::warpPerspective() | 透视变换整幅图 |
cv::getPerspectiveTransform() | 填充透视变换矩阵的参数 |
3 三维姿态估计
3.1 使用cv::solvePnP()计算外参
bool cv::solvePnP(
cv::InputArray objectPoints,
cv::InputArray imagePoints,
cv::InputArray cameraMatrix,
cv::InputArray distCoeffs,
cv::OutputArray rvec,
cv::OutputArray tvec,
bool useExtrinsicGuess = false,
int flags = cv::ITERATIVE
)
3.2 使用cv::solvePnPRansac()计算外参
bool cv::solvePnPRansac(
cv::InputArray objectPoints,
cv::InputArray imagePoints,
cv::InputArray cameraMatrix,
cv::InputArray distCoeffs,
cv::OutputArray rvec,
cv::OutputArray tvec,
bool useExtrinsicGuess = false,
int iterationsCount = 100,
float reprojectionError = 8.0,
int minInliersCount = 100,
cv::OutputArray inliers = cv::noArray(),
int flags = cv::ITERATIVE
)
4 立体成像
4.1 使用cv::findFundamentalMat()求解基本矩阵
cv::Mat cv::findFundamentalMat(
cv::InputArray points1,
cv::InputArray points2,
int method = cv::FM_RANSAC,
double param1 = 3.0,
double param2 = 0.99,
cv::OutputArray mask = cv::noArray()
)
方法的值 | 点数 | 算法 |
---|
cv::FM_7POINT | N=7 | 7点算法 |
cv::FM_8POINT | N>=8 | 8点算法 |
cv::FM_RANSAC | N>=8 | RANSAC算法 |
cv::FM_LMEDS | N>=8 | LMedS算法 |
4.2 计算极线
void cv::computeCorrespondEpilines(
cv::InputArray points,
int whichImage,
cv::InputArray F,
cv::OutputArray lines
);
4.3 立体标定
double cv::stereoCalibrate(
cv::InputArrayOfArrays objectPoints,
cv::InputArrayOfArrays imagePoints1,
cv::InputArrayOfArrays imagePoints2,
cv::InputOutputArray cameraMatrix1,
cv::InputOutputArray distCoeffs1,
cv::InputOutputArray cameraMatrix2,
cv::InputOutputArray distCoeffs2,
cv::Size imageSize,
cv::OutputArray R,
cv::OutputArray T,
cv::OutputArray E,
cv::OutputArray F,
cv::TermCriteria criteria = cv::TermCriteria(
cv::TermCriteria::COUNT | cv::TermCriteria::EPS,
30,
1e-6
),
int flags = cv::CALIB_FIX_INTRINSIC
);
4.4 立体校正
4.4.1 非标定立体校正: Hartley算法
bool cv::stereoRectifyUncalibrated(
cv::InputArray points1,
cv::InputArray points2,
cv::InputArray F,
cv::Size imgSize,
cv::OutputArray H1,
cv::OutputArray H2,
double threshold = 5.0
)
4.4.2 已标定立体校正: Bouguet算法
void cv::stereoRectify(
cv::InputArray cameraMatrix1,
cv::InputArray distCoeffs1,
cv::InputArray cameraMatrix2,
cv::InputArray distCoeffs2,
cv::Size imageSize,
cv::InputArray R,
cv::InputArray T,
cv::OutputArray R1,
cv::OutputArray R2,
cv::OutputArray P1,
cv::OutputArray P2,
cv::OutputArray Q,
int flags,
double alpha = -1,
cv::Size newImageSize = cv::Size(),
cv::Rect* validPixROI1 = 0,
cv::Rect* validPixROI2 = 0
);
4.4.3 校正映射
void cv::initUndistortRectifyMap(
cv::InputArray cameraMatrix,
cv::InputArray distortCoeffs,
cv::InputArray R,
cv::InputArray newCameraMatrix,
cv::Size size,
int m1type,
cv::OutputArray map1,
cv::OutputArray map2
)
4.5 立体匹配
class cv::StereoMatcher : public cv::Algorithm {
public:
enum {
DISP_SHIFT = 4,
DISP_SCALE = (1 << DISP_SHIFT)
};
virtual void compute(
cv::InputArray left,
cv::InputArray right,
cv::OutputArray disparity
) = 0;
virtual int getMinDisparity() const = 0;
virtual void setMinDisparity(int minDisparity) = 0;
virtual int getNumDisparity() const = 0;
virtual void setNumDisparities(int numDisparities) = 0
virtual int getBlockSize() const = 0;
virtual void setBlockSize(int blockSize) = 0;
virtual int getSpeckleWindowSize() const = 0;
virtual void setSpeckleWindowSize(int speckleWindowSize) = 0;
virtual int getSpeckleRange() const = 0;
virtual void setSpeckleRange(int speckleRange) = 0;
...
}
4.5.1 使用cv::StereoBM计算立体深度(块匹配)
class cv::StereoBM : public cv::StereoMatcher {
enum {
PREFILTER_NORMALIZED_RESPONSE = 0,
PREFILTER_XSOBEL = 1
}
virtual int getPreFilterType() const = 0;
virtual void setPreFilterType(int preFilterType) = 0;
virtual int getPreFilterSize() const = 0;
virtual void setPreFilterSize(int preFilterSize) = 0;
virtual int getPreFilterCap() const = 0;
virtual void setPreFilterCap(int preFilterCap) = 0;
virtual int getTextureThreshold() const = 0;
virtual void setTextureThreshold(int textureThreshold) = 0;
virtual int getUniquenessRatio() const = 0;
virtual void setUniquenessRatio(int uniquenessRatio) = 0;
static cv::Ptr<cv::StereoBM> create(
int numDisparities = 0,
int blockSize = 21
);
};
4.5.2 使用cv::StereoSGBM计算立体深度(半全局块匹配)
class cv::StereoSGBM : public cv::StereoMatcher {
enum {
MODE_SGBM = 0,
MODE_HH = 1,
MODE_SGBM_3WAY = 2
}
virtual int getPreFilterCap() const = 0;
virtual void setPreFilterCap(int preFilterCap) = 0;
virtual int getUniquenessRatio() const = 0;
virtual void setUniquenessRatio(int uniquenessRatio) = 0;
virtual int getP1() const = 0;
virtual void setP1(int P1) = 0;
virtual int getP2() const = 0;
virtual void setP2(int P2) = 0;
virtual int getMode() const = 0;
virtual void setMode(int mode) = 0;
static cv::Ptr<cv::StereoSGBM> create(
int minDisparities,
int numDisparities,
int blockSize,
int P1 = 0,
int P2 = 0,
int disp12MaxDiff = 0,
int preFilterCap = 0,
int uniquenessRatio = 0,
int speckleWindowSize = 0,
int speckleRange = 0,
int mode = StereoSGBM::MODE_SGBM
);
};
4.6 来自三维重投影的深度映射
void cv::perspectiveTransform(
cv::InputArray src,
cv::OutputArray dst,
cv::InputArray Q
)
void cv::reprojectImageTo3D(
cv::InputArray disparity,
cv::OutputArray _3dImage,
cv::InputArray Q,
bool handleMissingValues = false,
int ddepth = -1
);