【问题标题】:Depth map - stereo image in Android with OpenCV深度图 - 带有 OpenCV 的 Android 中的立体图像
【发布时间】:2015-12-27 04:01:43
【问题描述】:

我想问一下,如何使用左右相机和 JAVACV/OPENCV 库中的两个图像创建深度图(视差图)?

我在 Android 中使用 OpenCV(+JavaCV 包装器)。我在互联网上找到了这些代码 - 这是正确的代码吗?如何校准相机?

 private Mat createDisparityMap(Mat rectLeft, Mat rectRight){

        // Converts the images to a proper type for stereoMatching
        Mat left = new Mat();
        Mat right = new Mat();

        Imgproc.cvtColor(rectLeft, left, Imgproc.COLOR_BGR2GRAY);
        Imgproc.cvtColor(rectRight, right, Imgproc.COLOR_BGR2GRAY);

        // Create a new image using the size and type of the left image
        Mat disparity = new Mat(left.size(), left.type());

        int numDisparity = (int)(left.size().width/8);

        opencv_calib3d.StereoSGBM stereoAlgo = new opencv_calib3d.StereoSGBM(
                0,    // min DIsparities
                numDisparity, // numDisparities
                11,   // SADWindowSize
                2*11*11,   // 8*number_of_image_channels*SADWindowSize*SADWindowSize   // p1
                5*11*11,  // 8*number_of_image_channels*SADWindowSize*SADWindowSize  // p2

                -1,   // disp12MaxDiff
                63,   // prefilterCap
                10,   // uniqueness ratio
                0, // sreckleWindowSize
                32, // spreckle Range
                false); // full DP
        // create the DisparityMap - SLOW: O(Width*height*numDisparity)
        stereoAlgo.compute(left, right, disparity);

        Core.normalize(disparity, disparity, 0, 256, Core.NORM_MINMAX);

        return disparity;
    }

【问题讨论】:

    标签: android opencv javacv depth


    【解决方案1】:

    试试这个(与 android OpenCV SDK 更兼容):

    private Mat createDisparityMap(Mat rectLeft, Mat rectRight){
    
        // Converts the images to a proper type for stereoMatching
        Mat left = new Mat();
        Mat right = new Mat();
    
        Imgproc.cvtColor(rectLeft, left, Imgproc.COLOR_BGR2GRAY);
        Imgproc.cvtColor(rectRight, right, Imgproc.COLOR_BGR2GRAY);
    
        // Create a new image using the size and type of the left image
        Mat disparity = new Mat(left.size(), left.type());
    
        int numDisparity = (int)(left.size().width/8);
    
        StereoSGBM stereoAlgo = StereoSGBM.create(
            0,    // min DIsparities
            numDisparity, // numDisparities
            11,   // SADWindowSize
            2*11*11,   // 8*number_of_image_channels*SADWindowSize*SADWindowSize   // p1
            5*11*11,  // 8*number_of_image_channels*SADWindowSize*SADWindowSize  // p2
    
            -1,   // disp12MaxDiff
            63,   // prefilterCap
            10,   // uniqueness ratio
            0, // sreckleWindowSize
            32, // spreckle Range
            0); // full DP
        // create the DisparityMap - SLOW: O(Width*height*numDisparity)
        stereoAlgo.compute(left, right, disparity);
    
        Core.normalize(disparity, disparity, 0, 256, Core.NORM_MINMAX);
    
        return disparity;
    }
    

    【讨论】:

      猜你喜欢
      • 2015-02-27
      • 1970-01-01
      • 2014-09-06
      • 2014-07-01
      • 2017-02-05
      • 1970-01-01
      • 2013-07-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多