OpenCVForUnity icon indicating copy to clipboard operation
OpenCVForUnity copied to clipboard

StereoSGBM Doesn't work at all

Open AndreAhmed opened this issue 4 years ago • 1 comments

Hi, I'm trying to do it with an example from ZED Camera, and The Canvas is white.

I tested the matrices I get from Zed in the image update function and they are CORRECT, Gray scaled with correct format 8UC_1

    private StereoSGBM leftMatcher;
    private StereoMatcher rightMatcher;
    private DisparityWLSFilter wls;
        leftMatcher = StereoSGBM.create(0, 16, wsize);
        leftMatcher.setP1(24 * wsize * wsize);
        leftMatcher.setP2(96 * wsize * wsize);
        leftMatcher.setPreFilterCap(63);
        leftMatcher.setMode(StereoSGBM.MODE_SGBM_3WAY);
        wls =  Ximgproc.createDisparityWLSFilter(leftMatcher);
        rightMatcher = Ximgproc.createRightMatcher(leftMatcher);
        wls.setLambda(160000);
        wls.setSigmaColor(1.5);

     texture = new Texture2D(1280, 720, TextureFormat.RGBA32, false);
 private void ImageUpdated(Camera cam, Mat cvMatLeft, Mat cvMatRight)
    {
        Mat disparity_left = new Mat(cvMatRight.rows(), cvMatRight.cols(), CvType.CV_16S);
        Mat disparity_right = new Mat(cvMatRight.rows(), cvMatRight.cols(), CvType.CV_16S);
        Mat filtered_disp = new Mat(cvMatRight.rows(), cvMatRight.cols(), CvType.CV_16S);
        Mat imgDisparity8U = new Mat(cvMatRight.rows(), cvMatRight.cols(), CvType.CV_8UC1);

        leftMatcher.compute(cvMatLeft, cvMatRight, disparity_left);
        int min_disp = leftMatcher.getMinDisparity();
        int num_disp = leftMatcher.getNumDisparities();
        rightMatcher.setMinDisparity(-(min_disp + num_disp) + 1);
        rightMatcher.setDisp12MaxDiff(1000000);
        rightMatcher.setSpeckleWindowSize(0);

        rightMatcher.compute(cvMatRight, cvMatLeft, disparity_right);

    
        wls.filter(disparity_left, cvMatLeft, filtered_disp, disparity_right);


        //normalize to CvType.CV_8U
        Core.normalize(filtered_disp, imgDisparity8U, 0, 255, Core.NORM_MINMAX, CvType.CV_8U);



        Utils.matToTexture2D(imgDisparity8U, texture);
        canvas.GetComponent<RawImage>().texture = texture;


    }

AndreAhmed avatar Nov 04 '20 14:11 AndreAhmed

In order to display the native opencv's error code, please enclose the code in Utils.setDebugMode(true) and Utils.setDebugMode(false). Do you see the error in the console?

Utils.setDebugMode(true);

Utils.setDebugMode(false);

EnoxSoftware avatar Nov 06 '20 14:11 EnoxSoftware