Stitching "manualy" with WarpPerspective ?

asked 2013-05-11 05:05:48 -0500

neoirto gravatar image

Hi all,

I try to stitch 2 undistorted images (Mat_Img0 and Mat_Img1), knowing there individual orientations (Mat_RotImg0 and Mat_RotImg1). So I'd like to stitch Mat_Img1 directly on Mat_Img0. I tried the following :

double  Mat_RotImg0_DATA[4][4] = {      {(double)RotImg0_00, (double)RotImg0_01, (double)RotImg0_02, 0},
                                            {(double)RotImg0_10, (double)RotImg0_11, (double)RotImg0_12, 0},
                                            {(double)RotImg0_20, (double)RotImg0_21, (double)RotImg0_22, 0},
                                            {0,0,0,1}
                                        };
Mat         Mat_RotImg0 = Mat(4, 4, CV_64F, Mat_RotImg0_DATA );


double      Mat_RotImg1_DATA[4][4] = {      {(double)RotImg1_00, (double)RotImg1_01, (double)RotImg1_02, 0},
                                            {(double)RotImg1_10, (double)RotImg1_11, (double)RotImg1_12, 0},
                                            {(double)RotImg1_20, (double)RotImg1_21, (double)RotImg1_22, 0},
                                            {0,0,0,1}
                                        };
Mat         Mat_RotImg1 = Mat(4, 4, CV_64F, Mat_RotImg1_DATA );



////////// Find rotation between the 2 images
Mat         Mat_RotImg1_to_RotImg0 = ( Mat_RotImg1.t() * Mat_RotImg0 );



Mat         A1 = (Mat_<double>(4,3) <<
            1, 0, -cx,
            0, 1, -cy,
            0, 0,    0,
            0, 0,    1);

Mat         T = (Mat_<double>(4, 4) <<
            1, 0, 0, 0,
            0, 1, 0, 0,
            0, 0, 1, fx,
            0, 0, 0, 1);

Mat         A2 = (Mat_<double>(3,4) <<
            fx,     0,      cx,     0,
            0,      fy,     cy,     0,
            0,      0,      1,      0);

Mat         Mat_Rot_warp = A2 * ( T * ( Mat_RotImg1_to_RotImg0 * A1));

////////// Apply the stitching Mat Mat_Rot_warp
warpPerspective(    Mat_Img1, Mat_Img0, Mat_Rot_warp, Mat_image_corrected.size(), INTER_NEAREST, BORDER_CONSTANT, Scalar(0, 0, 0) );

Unfortunately, it does not give the expected result. Do you see anything I do wrong in this code ?

Thanks a lot in advance for your answers ;)

edit retag flag offensive close merge delete