python opencv双目相机标定_双目标定-opencv-双目相机标定

#include &ltiostream&gt

#include &ltsstream&gt

#include &lttime.h&gt

#include &ltstdio.h&gt

#include &ltstdlib.h&gt

#include &ltopencv2/core/core.hpp&gt

#include &ltopencv2/imgproc/imgproc.hpp&gt

#include &ltopencv2/calib3d/calib3d.hpp&gt

#include &ltopencv2/highgui/highgui.hpp&gt

#include &ltopencv2/features2d/features2d.hpp&gt

#ifndef DEBUG

#pragma comment(lib, "opencv_features2d249.lib")

#pragma comment(lib, "opencv_core249.lib")

#pragma comment(lib, "opencv_highgui249.lib")

#pragma comment(lib, "opencv_nonfree249.lib")

#pragma comment(lib, "opencv_imgproc249.lib")

#pragma comment(lib, "opencv_calib3d249.lib")

#else

#pragma comment(lib, "opencv_features2d249d.lib")

#pragma comment(lib, "opencv_core249d.lib")

#pragma comment(lib, "opencv_highgui249d.lib")

#pragma comment(lib, "opencv_nonfree249d.lib")

#pragma comment(lib, "opencv_imgproc249d.lib")

#pragma comment(lib, "opencv_calib3d249d.lib")

#endif

#ifndef _CRT_SECURE_NO_WARNINGS

# define _CRT_SECURE_NO_WARNINGS

#endif

using namespace cv;

using namespace std;

static void help()

{

cout &lt&lt "This is a camera calibration sample." &lt&lt endl

&lt&lt "Usage: calibration configurationFile" &lt&lt endl

&lt&lt "Near the sample file you'll find the configuration file, which has detailed help of "

"how to edit it. It may be any OpenCV supported file format XML/YAML." &lt&lt endl;

}

class Settings

{

public:

Settings() : goodInput(false) {}

enum Pattern { NOT_EXISTING, CHESSBOARD, CIRCLES_GRID, ASYMMETRIC_CIRCLES_GRID };

enum InputType {INVALID, CAMERA, VIDEO_FILE, IMAGE_LIST};

void write(FileStorage& fs) const //Write serialization for this class

{

fs &lt&lt "{" &lt&lt "BoardSize_Width" &lt&lt boardSize.width

&lt&lt "BoardSize_Height" &lt&lt boardSize.height

&lt&lt "Square_Size" &lt&lt squareSize

&lt&lt "Calibrate_Pattern" &lt&lt patternToUse

&lt&lt "Calibrate_NrOfFrameToUse" &lt&lt nrFrames

&lt&lt "Calibrate_FixAspectRatio" &lt&lt aspectRatio

&lt&lt "Calibrate_AssumeZeroTangentialDistortion" &lt&lt calibZeroTangentDist

&lt&lt "Calibrate_FixPrincipalPointAtTheCenter" &lt&lt calibFixPrincipalPoint

&lt&lt "Write_DetectedFeaturePoints" &lt&lt bwritePoints

&lt&lt "Write_extrinsicParameters" &lt&lt bwriteExtrinsics

&lt&lt "Write_outputFileName" &lt&lt outputFileName

&lt&lt "Show_UndistortedImage" &lt&lt showUndistorsed

&lt&lt "Input_FlipAroundHorizontalAxis" &lt&lt flipVertical

&lt&lt "Input_Delay" &lt&lt delay

&lt&lt "Input" &lt&lt input

&lt&lt "}";

}

void read(const FileNode& node) //Read serialization for this class

{

node["BoardSize_Width" ] &gt&gt boardSize.width;

node["BoardSize_Height"] &gt&gt boardSize.height;

node["Calibrate_Pattern"] &gt&gt patternToUse;

node["Square_Size"] &gt&gt squareSiz

各标定步骤实现方法 1 计算标靶平面与图像平面之间的映射矩阵 计算标靶平面与图像平面之间的映射矩阵,计算映射矩阵时不考虑摄像机的成像模型,只是根据平面标靶坐标点和对应的图像坐标点的数据,利用最小二乘方法计算得到[ [ix] ] .2 求解摄像机参数矩阵 由计算得到的标靶平面和图像平面的映射矩阵得到与摄像机内部参数相关的基本方程关系,求解方程得到摄像机内部参数,考虑镜头的畸变模型,将上述解方程获 得的内部参数作为初值,进行非线性优化搜索,从而计算出所有参数的准确值 [[x] ] .3 求解左右两摄像机之间的相对位置关系 设双目视觉系统左右摄像机的外部参数分别为Rl, Tl,与Rr, Tr,,即Rl, Tl表示左摄像机与世界坐标系的相对位置,Rr, Tr表示右摄像机与世界坐标系的相对位置 [[xi] ]。因此,对于空间任意一点,如果在世界坐标系、左摄像机坐标系和右摄像机坐标系中的坐标分别为Xw,, Xl , Xr,则有:Xl=RlXw+Tl ;Xr=RrXw+Tr .因此,两台摄像机之间的相对几何关系可以由下式表示R=RrRl-1 ;T=Tr- RrRl-1Tl 在实际标定过程中,由标定靶对两台摄像机同时进行摄像标定,以分别获得两台摄像机的内、外参数,从而不仅可以标定出摄像机的内部参数,还可以同时标定出双目视觉系统的结构参数 [xii] 。由单摄像机标定过程可以知道,标定靶每变换一个位置就可以得到一组摄像机外参数:Rr,Tr,与Rl, Tl,因此,由公式R=RrRl-1 ;T=Tr- RrRl-1Tl,可以得到一组结构参数R和T
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值