コード例 #1
0
    public OpenCVForUnity.CoreModule.Mat GetMat(int x, int y, int width, int height)
    {
        if (mat == null || mat.getNativeObjAddr() == System.IntPtr.Zero)
        {
            return(null);
        }

        // Crop the image by using opencv
        var rect = new OpenCVForUnity.CoreModule.Rect(x, y, width, height);
        var dst  = new OpenCVForUnity.CoreModule.Mat(mat, rect);

        // Validate the mat object
        if (dst == null || dst.getNativeObjAddr() == System.IntPtr.Zero)
        {
            return(null);
        }

        return(dst);
    }
コード例 #2
0
    public OpenCVForUnity.CoreModule.Mat GetMat()
    {
        // Get the full image
        var colors  = GetColors();
        var texture = new Texture2D(webCamTexture.width, webCamTexture.height);

        texture.SetPixels32(colors);

        // Convert the texture2d to mat format
        var dst = new OpenCVForUnity.CoreModule.Mat(webCamTexture.height, webCamTexture.width, OpenCVForUnity.CoreModule.CvType.CV_8UC3);

        OpenCVForUnity.UnityUtils.Utils.texture2DToMat(texture, dst);

        // Validate the mat object
        if (dst == null || dst.getNativeObjAddr() == System.IntPtr.Zero)
        {
            return(null);
        }

        return(dst);
    }