Home > Software engineering >  After about 3 d image problem
After about 3 d image problem

Time:09-30

Get involved in after calibration and then use matlab opencv rotation matrix and translation matrix and then three-dimensional correction of images make such couldn't use what is the warrior,
Attach the code
//the match. The CPP: defines the entry point of the console application,
//

# include "stdafx. H"
# include & lt; Opencv2 \ opencv. Hpp>
# include & lt; fstream>
# include & lt; iostream>
# include & lt; Windows. H>
using namespace cv;
using namespace std;
The Rect validROIL validROIR;
//in the left camera parameter matrix
Double LM [3] [3]={3580.44600, 2.55799, 0104
0, 3579.70317, 783.38929,
0, 0, 1};
//the left camera distortion coefficient
Double LD [5]={0.08776, 0.28040, 0.00056, 0.00093, 0.00000};

//right camera parameter matrix
Double RM [3] [3]={3542.92697, 7.12453, 0101
0, 3543.31224, 771.34343,
0, 0, 1};
//right camera distortion coefficient
Double RD [5]={0.09167, 0.73632, 0.00213, 0.00240, 0.00000};
//right camera rotation matrix
Double Rotate [3] [3]={0.736925,

0.040977,
0.674731,
0.014852,
0.996938,
0.076767,
0.675811,
0.066593,0.734061};
Double translation [3] [1]={93.80548, 5.87551, 88.00076};
Mat ocv_bm (Mat left, Mat right) {

Mat disp disp8;

CV: : StereoBM SBM;

SBM. State - & gt; SADWindowSize=5;
SBM. State - & gt; NumberOfDisparities=112;
SBM. State - & gt; PreFilterSize=5;
SBM. State - & gt; PreFilterCap=1;
SBM. State - & gt; MinDisparity=0;
SBM. State - & gt; TextureThreshold=7.
SBM. State - & gt; UniquenessRatio=5;
SBM. State - & gt; SpeckleWindowSize=0;
SBM. State - & gt; SpeckleRange=20.
SBM. State - & gt; Disp12MaxDiff=64;
SBM (left, right, disp);
The normalize (disp disp8, 0.1, 255, CV_MINMAX, CV_8U);

Return disp8;
}

Int _tmain (int arg c, _TCHAR * argv [])
{
IplImage * imge1=cvLoadImage (" E://leftpicture03. JPG ");
IplImage * imge2=cvLoadImage (" E://rightpicture03. JPG ");

CvSize imageSize=cvGetSize (imge1);
CV: : Mat cameraMatrix_L=CV: : Mat (3, 3, CV_64FC1, LM);
CV: : Mat distortionCoefficients_L=CV: : Mat (1, 5, CV_64FC1, LD);
CV: : Mat cameraMatrix_R=CV: : Mat (3, 3, CV_64FC1, RM);
CV: : Mat distortionCoefficients_R=CV: : Mat (1, 5, CV_64FC1 RD);

CV: : Mat rotations=CV: : Mat (3, 3, CV_64FC1, Rotate);
CV: : Mat translations=CV: : Mat (3, 1, CV_64FC1, translation);

CV: : the Rect roi1, roi2;
CV: : Mat m_Calib_Mat_Remap_X_L=CV: : Mat (imageSize, CV_64FC1);
CV: : Mat m_Calib_Mat_Remap_Y_L=CV: : Mat (imageSize, CV_64FC1);
CV: : Mat m_Calib_Mat_Remap_X_R=CV: : Mat (imageSize, CV_64FC1);
CV: : Mat m_Calib_Mat_Remap_Y_R=CV: : Mat (imageSize, CV_64FC1);
Double r1 [3], [3] r2 [3], [3], p1 [3] [4], p2 [3] [4], q [3] [4].
Mat R1=Mat (3, 3, CV_64FC1, R1);
Mat R2=Mat (3, 3, CV_64FC1, R2);
Mat P1=Mat (3, 4, CV_64FC1, P1);
Mat P2=Mat (3, 4, CV_64FC1, P2);
Mat Q=Mat (3, 4, CV_64FC1, Q);;
CV: : stereoRectify (
CameraMatrix_L,
DistortionCoefficients_L,
CameraMatrix_R,
DistortionCoefficients_R,
ImageSize,
Rotations,
Translations,
R1, R2, P1, P2, Q, CV_CALIB_ZERO_DISPARITY, 1, imageSize, & amp; ValidROIL, & amp; ValidROIR);
InitUndistortRectifyMap (
CameraMatrix_L,
DistortionCoefficients_L,
R1, P1,
ImageSize,
CV_32FC1,
M_Calib_Mat_Remap_X_L m_Calib_Mat_Remap_Y_L);
InitUndistortRectifyMap (
CameraMatrix_R,
DistortionCoefficients_R,
R2, P2,
ImageSize,
CV_32FC1,
M_Calib_Mat_Remap_X_R m_Calib_Mat_Remap_Y_R);
CV: : Mat frame0 frame1;
Frame0=imread (" E://leftpicture01. JPG ");
Frame1=imread (" E://rightpicture01. JPG ");
Mat frame0_1;
Mat frame1_1;
Mat frame0_1_1;
Mat frame1_1_1;
CvtColor (frame0 frame0_1, CV_RGB2GRAY);
CvtColor (frame1, frame1_1 CV_RGB2GRAY);
Remap (frame0_1 frame0_1_1, m_Calib_Mat_Remap_X_L m_Calib_Mat_Remap_Y_L, INTER_LINEAR);
Remap (frame1_1 frame1_1_1, m_Calib_Mat_Remap_X_R m_Calib_Mat_Remap_Y_R, INTER_LINEAR);
CvtColor (frame0_1_1 frame0, CV_GRAY2RGB);
CvtColor (frame1_1_1, frame1, CV_GRAY2RGB);
Imshow (" l ", frame0);
Imshow (" r ", frame1);
Mat canvas;
Double sf;
Int w, h;
Sf=600./MAX (imageSize. Width, imageSize. Height);
W=cvRound (imageSize. Width * sf);
H=cvRound (imageSize. Height * sf);
Canvas. Create (h, w * 2, CV_8UC3);

/* left image onto the canvas */
Mat canvasPart=canvas (the Rect (w * 0, 0, w, h));//get the canvas part of
The resize (frame0 canvasPart, canvasPart. The size (), 0, 0, INTER_AREA);//the image scaling to like canvasPart size
The Rect vroiL (cvRound (validROIL. X * sf), cvRound (validROIL. Y * sf),//get be intercepted area
CvRound (validROIL width * sf), cvRound (validROIL. * sf, height));
A rectangle (canvasPart vroiL, Scalar (0, 0, 255), 3, 8). Draw a rectangle//

Cout & lt; <"Made ImageL" & lt;
/* right like paint on canvas */
CanvasPart=canvas (the Rect (w, 0, w, h);//get the other part of the canvas
The resize (frame1, canvasPart canvasPart. The size (), 0, 0, INTER_LINEAR);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related