Now using OpenCV camera calibration function has got a camera parameter matrix and within each image outside the parameters of the matrix, then based on the laser plane calibration
# include
#include
Using namespace STD.
using namespace cv;
//global variables: camera parameter matrix and the calibration plate image rotation matrix and translation matrix
Mat instrinsic_Mat=(Mat_ & lt; Double> (3, 3) & lt; <1011.56213410783, 0, 339.4909058325158, 0, 1032.8005369113, 251.8598465394016, 0, 0, 1);
Mat instrinsic_Mat_invert=instrinsic_Mat. Inv ();
Double fx=instrinsic_Mat. At(0, 0);
Double fy=instrinsic_Mat. At(1, 1);
Cx=double instrinsic_Mat. At(0, 2);
Double cy=instrinsic_Mat. At(1, 2);
Mat ratationMat01=(Mat_ & lt; Double> (3, 1) & lt; <2.214042276280793, 2.042125553204266, 0.1539188600609928);
Mat translationMat01=(Mat_ & lt; Double> (3, 1) & lt; <2.924192514183808, 2.062099121158008, 28.91752066850143);
Mat ratationMat02=(Mat_ & lt; Double> (3, 1) & lt; <0.22120867162204, 3.066096222327546, 0.6095364322919371);
Mat translationMat02=(Mat_ & lt; Double> (3, 1) & lt; <2.069533497570583, 3.660400068141293, 26.17519894159816);
Mat ratationMat03=(Mat_ & lt; Double> (3, 1) & lt; <1.676260593562374, 2.626057515467858, 0.03787192557694142);
Mat translationMat03=(Mat_ & lt; Double> (3, 1) & lt; <3.729691927633717, 4.244904864126781, 28.52816373265996);
Mat ratationMat04=(Mat_ & lt; Double> (3, 1) & lt; <1.428369712597115, 2.611472870951897, 0.5176479463955468);
Mat translationMat04=(Mat_ & lt; Double> (3, 1) & lt; <3.414422553834327, 1.492396944583323, 37.72414534156961);
VectorLaserPoints_uv (Mat srcImage, string STR);
Mat plane (Mat ratationMat, Mat translationMat);
VectorLaserPts_uv, Mat planeEquation);
Vec6f laserline_cam (string STR, Mat ratationMat, Mat translationMat, vectorVec4d result (Vec6f laserEquation01, Vec6f laserEquation02);
Mat plane_fitting (vectorDouble error (vector
Int main ()
{
//the collection of points in the camera coordinate system under the laser stripe
Vector//linear equation of laser stripe
Vec6f laserEquation01=laserline_cam (" 1. JPG ", ratationMat01 translationMat01, laserpoint_cam01);
Vec6f laserEquation02=laserline_cam (" 2. JPG ", ratationMat02 translationMat02, laserpoint_cam02);
Vec6f laserEquation03=laserline_cam (" 3. JPG ", ratationMat03 translationMat03, laserpoint_cam03);
Vec6f laserEquation04=laserline_cam (" 4. JPG ", ratationMat04 translationMat04, laserpoint_cam04);
//laser plane equation
Vec4d laserplane0102=result (laserEquation01 laserEquation02);
Vec4d laserplane0304=result (laserEquation03 laserEquation04);
The calculation error//
Double error01=error (laserpoint_cam03 laserplane0304);
Double error02=error (laserpoint_cam04 laserplane0304);
Cout & lt; <1: "error" & lt;Cout & lt; <"Error: 2" & lt;
Cout & lt; <"The ratio of the two laser plane equation, if the same ratio, is right:"" " "
Cout & lt;//the set of two laser stripe points to a collection, used in linear fitting
Laserpoint_cam01. Insert (laserpoint_cam01. End (), laserpoint_cam02. The begin (), laserpoint_cam02. The end ());
Laserpoint_cam03. Insert (laserpoint_cam03. End (), laserpoint_cam04. The begin (), laserpoint_cam04. The end ());
//is carried out on the laser plane by least square fitting
Mat plane0102=plane_fitting (laserpoint_cam01);
Mat plane0304=plane_fitting (laserpoint_cam03);
waitKey(0);
system("pause");
return 0;
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//the second method: through the least-square method, through the pixel coordinates the points on the plane to simulate the laser plane equation
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Mat plane_fitting (vector{
Mat DST=Mat (3, 3, CV_32F, Scalar (0));
Mat out=Mat (3, 1, CV_32F, Scalar (0));
for (int i=0; I & lt; Input. The size (); I++)
{
DST. At(0, 0) +=pow (input [I] x, 2);
DST. At(0, 1) +=input [I]. * x input [I] y;
DST. At(0, 2) +=input [I]. X.
DST. At(1, 0) +=input [I]. * x input [I] y;
DST. At(1, 1) +=pow (input [I] y, 2);
DST. At(1, 2) +=input [I] y;
DST. At(2, 0) +=input [I] x;;
DST. At(2, 1) +=input [I] y;
DST. At(2, 2)=input. The size ();
Out. At(0, 0) +=(input [I]. * x input [I]. Z);
Out. At(1, 0) +=(input [I] y * input [I]. Z);
Out. At