Example usage for org.opencv.imgproc Imgproc initUndistortRectifyMap

List of usage examples for org.opencv.imgproc Imgproc initUndistortRectifyMap

Introduction

In this page you can find the example usage for org.opencv.imgproc Imgproc initUndistortRectifyMap.

Prototype

public static void initUndistortRectifyMap(Mat cameraMatrix, Mat distCoeffs, Mat R, Mat newCameraMatrix,
            Size size, int m1type, Mat map1, Mat map2) 

Source Link

Usage

From source file:org.openpnp.machine.reference.ReferenceCamera.java

License:Open Source License

private Mat undistort(Mat mat) {
    if (!calibration.isEnabled()) {
        return mat;
    }/* w  w w.jav  a 2  s  . c  om*/

    if (undistortionMap1 == null || undistortionMap2 == null) {
        undistortionMap1 = new Mat();
        undistortionMap2 = new Mat();
        Mat rectification = Mat.eye(3, 3, CvType.CV_32F);
        Imgproc.initUndistortRectifyMap(calibration.getCameraMatrixMat(),
                calibration.getDistortionCoefficientsMat(), rectification, calibration.getCameraMatrixMat(),
                mat.size(), CvType.CV_32FC1, undistortionMap1, undistortionMap2);
        rectification.release();
    }

    Mat dst = mat.clone();
    Imgproc.remap(mat, dst, undistortionMap1, undistortionMap2, Imgproc.INTER_LINEAR);
    mat.release();

    return dst;
}