[opencv] 極線校正


//R = Rr*inv(Rl); T = Tr - R*Tl;
    invert(RLeft,RLeft);
    Mat R = RRight.clone();
    gemm(R,RLeft,1,1,0,R);
    Mat T;
    gemm(R,TLeft,1,1,0,T);
    T = TRight - T;

    //計算旋轉矩陣和投影矩陣
    Mat R1, R2, P1, P2, Q;
    stereoRectify(KLeft,Mat::zeros(1,5,CV_32F),KRight,Mat::zeros(1,5,CV_32F),
        imageSize,R,T,R1,R2,P1,P2,Q,CALIB_ZERO_DISPARITY,0);
    //計算映射
    Mat rmap[2][2];
    initUndistortRectifyMap(KLeft,Mat::zeros(1,5,CV_32F), R1, P1, imageSize, CV_16SC2, rmap[0][0], rmap[0][1]);
    initUndistortRectifyMap(KRight, Mat::zeros(1,5,CV_32F), R2, P2, imageSize, CV_16SC2, rmap[1][0], rmap[1][1]);
    remap(imgL, imgLr, rmap[0][0], rmap[0][1], CV_INTER_AREA);//左校正
    remap(imgR, imgRr, rmap[1][0], rmap[1][1], CV_INTER_AREA);//右校正

    Mat showImage(imageSize.height,2*imageSize.width,CV_8UC3);
    Rect rectLeft(0,0,imageSize.width,imageSize.height);
    Rect rectRight(imageSize.width,0,imageSize.width,imageSize.height);
    imgLr.copyTo(showImage(rectLeft));
    imgRr.copyTo(showImage(rectRight));
    
    for( int i = 0; i < imageSize.height; i += 32 )
    {
        line(showImage, Point(0, i), Point(2*imageSize.width, i), Scalar(0, 255, 0), 1, 8);
    }

 效果圖:

 

 代碼下載:https://github.com/zhanxiage1994/rectifyImages.git


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM