public static RectifyCalibrated rectify ( GrayU8 origLeft , GrayU8 origRight , StereoParameters param , GrayU8 rectLeft , GrayU8 rectRight ) { // Compute rectification RectifyCalibrated rectifyAlg = RectifyImageOps . createCalibrated ( ) ; Se3_F64 leftToRight = param . getRightToLeft ( ) . invert ( null ) ; // original camera calibration matrices DMatrixRMaj K1 = PerspectiveOps . pinholeToMatrix ( param . getLeft ( ) , ( DMatrixRMaj ) null ) ; DMatrixRMaj K2 = PerspectiveOps . pinholeToMatrix ( param . getRight ( ) , ( DMatrixRMaj ) null ) ; rectifyAlg . process ( K1 , new Se3_F64 ( ) , K2 , leftToRight ) ; // rectification matrix for each image DMatrixRMaj rect1 = rectifyAlg . getRect1 ( ) ; DMatrixRMaj rect2 = rectifyAlg . getRect2 ( ) ; // New calibration matrix, DMatrixRMaj rectK = rectifyAlg . getCalibrationMatrix ( ) ; // Adjust the rectification to make the view area more useful RectifyImageOps . allInsideLeft ( param . left , rect1 , rect2 , rectK ) ; // undistorted and rectify images FMatrixRMaj rect1_F32 = new FMatrixRMaj ( 3 , 3 ) ; FMatrixRMaj rect2_F32 = new FMatrixRMaj ( 3 , 3 ) ; ConvertMatrixData . convert ( rect1 , rect1_F32 ) ; ConvertMatrixData . convert ( rect2 , rect2_F32 ) ; ImageDistort < GrayU8 , GrayU8 > imageDistortLeft = RectifyImageOps . rectifyImage ( param . getLeft ( ) , rect1_F32 , BorderType . SKIP , origLeft . getImageType ( ) ) ; ImageDistort < GrayU8 , GrayU8 > imageDistortRight = RectifyImageOps . rectifyImage ( param . getRight ( ) , rect2_F32 , BorderType . SKIP , origRight . getImageType ( ) ) ; imageDistortLeft . apply ( origLeft , rectLeft ) ; imageDistortRight . apply ( origRight , rectRight ) ; return rectifyAlg ; }
Rectified the input images using known calibration .