今天更新一下用OpenCV的C++代码实现单目相机标定,所用图片和上一篇文章相同,都是2000W像素的标定板图片。这里的标定代码调用的是opencv4.5.3源码的sample样例代码。可以在
E:\opencv--c++\opencv-4.5.3\sources\samples\cpp\tutorial_code\calib3d\camera_calibration找到所有标定程序所需的文件。

其中 in_VID5.xml代码主要是以XML文件存储标定配置,内容见下面代码
<?xml version="1.0"?>
<opencv_storage>
<Settings>
<!-- Number of inner corners per a item row and column. (square, circle) -->
<BoardSize_Width> 9</BoardSize_Width>
<BoardSize_Height>6</BoardSize_Height>
<!-- The size of a square in some user defined metric system (pixel, millimeter)-->
<Square_Size>50</Square_Size>
<!-- The type of input used for camera calibration. One of: CHESSBOARD CIRCLES_GRID ASYMMETRIC_CIRCLES_GRID -->
<Calibrate_Pattern>"CHESSBOARD"</Calibrate_Pattern>
<!-- The input to use for calibration.
To use an input camera -> give the ID of the camera, like "1"
To use an input video -> give the path of the input video, like "/tmp/x.avi"
To use an image list -> give the path to the XML or YAML file containing the list of the images, like "/tmp/circles_list.xml"
-->
<Input>"images/CameraCalibration/VID5/VID5.xml"</Input>
<!-- If true (non-zero) we flip the input images around the horizontal axis.-->
<Input_FlipAroundHorizontalAxis>0</Input_FlipAroundHorizontalAxis>
<!-- Time delay between frames in case of camera. -->
<Input_Delay>100</Input_Delay>
<!-- How many frames to use, for calibration. -->
<Calibrate_NrOfFrameToUse>25</Calibrate_NrOfFrameToUse>
<!-- Consider only fy as a free parameter, the ratio fx/fy stays the same as in the input cameraMatrix.
Use or not setting. 0 - False Non-Zero - True-->
<Calibrate_FixAspectRatio> 1 </Calibrate_FixAspectRatio>
<!-- If true (non-zero) tangential distortion coefficients are set to zeros and stay zero.-->
<Calibrate_AssumeZeroTangentialDistortion>1</Calibrate_AssumeZeroTangentialDistortion>
<!-- If true (non-zero) the principal point is not changed during the global optimization.-->
<Calibrate_FixPrincipalPointAtTheCenter> 1 </Calibrate_FixPrincipalPointAtTheCenter>
<!-- The name of the output log file. -->
<Write_outputFileName>"out_camera_data.xml"</Write_outputFileName>
<!-- If true (non-zero) we write to the output file the feature points.-->
<Write_DetectedFeaturePoints>1</Write_DetectedFeaturePoints>
<!-- If true (non-zero) we write to the output file the extrinsic camera parameters.-->
<Write_extrinsicParameters>1</Write_extrinsicParameters>
<!-- If true (non-zero) we write to the output file the refined 3D target grid points.-->
<Write_gridPoints>1</Write_gridPoints>
<!-- If true (non-zero) we show after calibration the undistorted images.-->
<Show_UndistortedImage>1</Show_UndistortedImage>
<!-- If true (non-zero) will be used fisheye camera model.-->
<Calibrate_UseFisheyeModel>0</Calibrate_UseFisheyeModel>
<!-- If true (non-zero) distortion coefficient k1 will be equals to zero.-->
<Fix_K1>0</Fix_K1>
<!-- If true (non-zero) distortion coefficient k2 will be equals to zero.-->
<Fix_K2>0</Fix_K2>
<!-- If true (non-zero) distortion coefficient k3 will be equals to zero.-->
<Fix_K3>0</Fix_K3>
<!-- If true (non-zero) distortion coefficient k4 will be equals to zero.-->
<Fix_K4>1</Fix_K4>
<!-- If true (non-zero) distortion coefficient k5 will be equals to zero.-->
<Fix_K5>1</Fix_K5>
</Settings>
</opencv_storage>
其中角点数为9行*6列,这里是OPenCV惯用的标定板角点尺寸。
其中两角点之间的真实距离为50mm。
标定板的模式选择chessboard即可,这是黑白棋盘标定板的意思(也有一些其他的奇奇怪怪的标定板样式,看你拍摄的图片是什么样式就选什么样式就好)。
input选项设置的是图片输入XML文件,里面的内容是这样的
<?xml version="1.0"?>
<opencv_storage>
<images>
images/CameraCalibraation/VID5/xx1.jpg
images/CameraCalibraation/VID5/xx2.jpg
images/CameraCalibraation/VID5/xx3.jpg
images/CameraCalibraation/VID5/xx4.jpg
images/CameraCalibraation/VID5/xx5.jpg
images/CameraCalibraation/VID5/xx6.jpg
images/CameraCalibraation/VID5/xx7.jpg
images/CameraCalibraation/VID5/xx8.jpg
</images>
</opencv_storage>
只需要更改图片的路径即可,这里的xx1.jpg目的是读取以1.jpg结束的任何匹配项,比如left1.jpg。
Calibrate_NrOfFrameToUse这个参数设置的是选取几张图片用于标定程序,因为我上一篇文章已经选取的20张用于标定,所以这里可以更改为20.
Write_outputFileName参数设置的是标定结果存储文件的名字,仍然是XML文件格式.
至此OPenCV提供的相机标定样例程序中的外部参数文件大致配置都清楚了,下面给出的是我已经更改完的,用于实际标定的参数文件.
第一个实际用的VID5.xml,更改了图片文件的位置,共21张2000w像素的黑白棋盘图片,20张用于标定,1张用于检测标定结果。标定图片的资源已经上传了,大家可以更具情况下载更改
<?xml version="1.0"?>
<opencv_storage>
<images>
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/1.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/2.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/3.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/4.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/5.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/6.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/7.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/8.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/9.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/10.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/11.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/12.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/13.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/14.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/15.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/16.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/17.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/18.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/19.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/20.bmp
E:/c++opencv_Projection/camera_calibration/calib/real_captured_image/21.bmp
</images>
</opencv_storage>
第二个文件是in_VID5.xml,这里我更改了上面描述的参数,25mm实际尺寸,输入文件的位置,20张标定图片等。
<?xml version="1.0"?>
<opencv_storage>
<Settings>
<!-- Number of inner corners per a item row and column. (square, circle) -->
<BoardSize_Width> 9</BoardSize_Width>
<BoardSize_Height>6</BoardSize_Height>
<!-- The size of a square in some user defined metric system (pixel, millimeter)-->
<Square_Size>25</Square_Size>
<!-- The type of input used for camera calibration. One of: CHESSBOARD CIRCLES_GRID ASYMMETRIC_CIRCLES_GRID -->
<Calibrate_Pattern>"CHESSBOARD"</Calibrate_Pattern>
<!-- The input to use for calibration.
To use an input camera -> give the ID of the camera, like "1"
To use an input video -> give the path of the input video, like "/tmp/x.avi"
To use an image list -> give the path to the XML or YAML file containing the list of the images, like "/tmp/circles_list.xml"
-->
<Input>"E:/c++opencv_Projection/camera_calibration/calib/VID5.xml"</Input>
<!-- If true (non-zero) we flip the input images around the horizontal axis.-->
<Input_FlipAroundHorizontalAxis>0</Input_FlipAroundHorizontalAxis>
<!-- Time delay between frames in case of camera. -->
<Input_Delay>100</Input_Delay>
<!-- How many frames to use, for calibration. -->
<Calibrate_NrOfFrameToUse>20</Calibrate_NrOfFrameToUse>
<!-- Consider only fy as a free parameter, the ratio fx/fy stays the same as in the input came

&spm=1001.2101.3001.5002&articleId=122398949&d=1&t=3&u=3a146a4426284d819f551b9e83175082)
413

被折叠的 条评论
为什么被折叠?



