欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

OpenCV for Unity鱼眼校正

程序员文章站 2022-04-17 18:12:32
...

//实际测试时D取以下值更好

(0, 0, -0.1222723392670962, 1.8382109174553397, 0.004643509151558462, 0.003429485001340429, -0.09370053614249967); 

OpenCV for Unity鱼眼校正

        //摄像机内参数矩阵
            Mat K = new Mat(3, 3, CvType.CV_64FC1);
            K.put(0, 0, 964.2931236266057, 0, 621.9682241925731,0, 958.3006969434483, 252.3649268231244, 0, 0, 1);

            //摄像机的4个畸变系数:k1,k2,k3,k4
            Mat D = new Mat(2, 2, CvType.CV_64FC1);
            D.put(0, 0, -0.4222723392670962, 0.2382109174553397, 0.004643509151558462, 0.003429485001340429, -0.09370053614249967);
            
            Size image_size = rgbaMat.size();
            Mat mapx = new Mat(image_size, CvType.CV_32FC1);
            Mat mapy = new Mat(image_size, CvType.CV_32FC1);
            Mat R = Mat.eye(3, 3, CvType.CV_32F);

            Mat newCameraMatrix = new Mat(3, 3, CvType.CV_32FC1, Scalar.all(0));
            OpenCVForUnity.Calib3dModule.Calib3d.fisheye_initUndistortRectifyMap(K, D, R, K, image_size, CvType.CV_32FC1, mapx, mapy);

            Mat t = new Mat(image_size, CvType.CV_32FC3);
            Imgproc.remap(rgbaMat, t, mapx, mapy, Imgproc.INTER_LINEAR);
            rgbaMat = t.clone();

            K.release();
            D.release();
            mapx.release();
            mapy.release();
            R.release();
            newCameraMatrix.release();
            t.release();

OpenCV for Unity鱼眼校正

相关标签: Unity