void domainTransferDepthImage(Frame3DGPU f)
    {
        //Utils.setDebugMode(true);
        Debug.Log("Applying EdgeCleanup to Depth");
        // convert from texture to mat
        Mat rgbMat = new Mat();

        Core.flip(Util.toMat(f.postprocessedRGBImage, CvType.CV_8UC3), rgbMat, -1);
        Mat depthMat = Util.toMat(f.depthImage, CvType.CV_16UC1);

        Mat gray = new Mat();

        Imgproc.cvtColor(rgbMat, gray, Imgproc.COLOR_RGBA2GRAY);
        Mat sobelX = new Mat();
        Mat sobelY = new Mat();

        Imgproc.Sobel(gray, sobelX, CvType.CV_16S, 1, 0, (int)ksize, sobelScale, 0, Core.BORDER_DEFAULT);
        Imgproc.Sobel(gray, sobelY, CvType.CV_16S, 0, 1, (int)ksize, sobelScale, 0, Core.BORDER_DEFAULT);

        Mat depthMat8bit = new Mat();

        depthMat.convertTo(depthMat8bit, CvType.CV_8UC1, 0.03f);
        Core.bitwise_not(depthMat8bit, depthMat8bit);
        //Imgproc.equalizeHist(depthMat8bit, depthMat8bit);

        Mat depthFlipped = new Mat();

        Core.flip(depthMat8bit, depthFlipped, -1);

        Mat canneyRslt = new Mat();

        Imgproc.Canny(sobelX, sobelY, canneyRslt, cannyThreshold1, cannyThreshold2, true);

        //Imgcodecs.imwrite("C:/Users/SIGLab/AppData/LocalLow/Intel/Photo3D/3dImages/" + "depth.png", canneyRslt);

        //415 incomplete depth
        Mat cropped = depthFlipped.submat(0, 690, 0, 1190);

        Core.copyMakeBorder(cropped, depthFlipped, 0, 720 - 690, 0, 1280 - 1190, Core.BORDER_REPLICATE | Core.BORDER_ISOLATED);


        Mat laplacianRslt = new Mat();

        Imgproc.Laplacian(gray, laplacianRslt, CvType.CV_32F, 5, .1, 0);

        Ximgproc.dtFilter(canneyRslt, depthFlipped, f.refinedDepth, sigmaSpacial, sigmaColor, Ximgproc.DTF_NC, dtIter);

        // Not working with built solutions, cant figure out why
        List <Mat> matList  = new List <Mat>();
        Mat        depthLUT = Util.toMat(depthRescale, CvType.CV_8UC3);

        Core.split(depthLUT, matList);
        Mat temp = new Mat();

        f.refinedDepth.convertTo(temp, CvType.CV_8UC1);
        Core.LUT(temp, matList[0], f.refinedDepth);
        //Utils.setDebugMode(false);
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        Debug.Log("Applying EdgeCleanup to Depth");
        Mat gray = new Mat();

        Imgproc.cvtColor(color, gray, Imgproc.COLOR_RGBA2GRAY);
        Mat sobelX = new Mat();
        Mat sobelY = new Mat();

        Imgproc.Sobel(gray, sobelX, CvType.CV_16S, 1, 0, (int)ksize, sobelScale, 0, Core.BORDER_DEFAULT);
        Imgproc.Sobel(gray, sobelY, CvType.CV_16S, 0, 1, (int)ksize, sobelScale, 0, Core.BORDER_DEFAULT);

        Mat depth = Util.toMat((Texture2D)depthTexture, CvType.CV_8UC3);

        Mat depthFlipped = new Mat();
        //Core.flip(depthMat, depthFlipped, -1);
        Mat depthMat8bit = new Mat();

        depth.convertTo(depthMat8bit, CvType.CV_8UC1, 0.1f);
        //Core.bitwise_not(depthMat8bit,depthMat8bit);
        //Imgproc.equalizeHist(depthMat8bit, depthMat8bit);

        Mat canneyRslt = new Mat();

        Imgproc.Canny(sobelX, sobelY, canneyRslt, cannyThreshold1, cannyThreshold2, true);

        Mat laplacianRslt = new Mat();

        Imgproc.Laplacian(gray, laplacianRslt, CvType.CV_32F, 5, .1, 0);

        Mat DTF_NC = new Mat();

        Ximgproc.dtFilter(canneyRslt, depthMat8bit, DTF_NC, sigmaSpacial, sigmaColor, Ximgproc.DTF_NC, dtIter);


        Texture2D yTexture = (Texture2D)Util.toTexture(sobelX, TextureFormat.R16);

        sobelTextureEvent.Invoke(yTexture);

        Texture2D canneyTexture = (Texture2D)Util.toTexture(canneyRslt, TextureFormat.R8);

        canneyTextureEvent.Invoke(canneyTexture);

        Texture2D depthtexture = (Texture2D)Util.toTexture(DTF_NC, TextureFormat.R8);

        improvedDepth.Invoke(depthtexture);
    }