Esempio n. 1
0
    void Start()
    {
        _Sensor = KinectSensor.GetDefault();
        if (_Sensor != null)
        {
            _Mapper           = _Sensor.CoordinateMapper;
            _CameraIntrinsics = _Mapper.GetDepthCameraIntrinsics();

            var frameDesc = _Sensor.DepthFrameSource.FrameDescription;

            // Downsample to lower resolution
            CreateMesh(frameDesc.Width / _DownsampleSize, frameDesc.Height / _DownsampleSize);

            if (!_Sensor.IsOpen)
            {
                _Sensor.Open();
            }
        }

        // 初始化参数
        colmap = new float[512];
        rowmap = new float[424];

        for (int i = 0; i < 512; i++)
        {
            colmap[i] = (i - _CameraIntrinsics.PrincipalPointX + 0.5f) / _CameraIntrinsics.FocalLengthX;
        }
        for (int i = 0; i < 424; i++)
        {
            rowmap[i] = (i - _CameraIntrinsics.PrincipalPointY + 0.5f) / _CameraIntrinsics.FocalLengthY;
        }
    }
Esempio n. 2
0
    void Start()
    {
        int width = 0, height = 0;

        _Sensor = KinectSensor.GetDefault();
        if (_Sensor != null)
        {
            _Mapper           = _Sensor.CoordinateMapper;
            _CameraIntrinsics = _Mapper.GetDepthCameraIntrinsics();

            var frameDesc = _Sensor.DepthFrameSource.FrameDescription;
            width  = frameDesc.Width;
            height = frameDesc.Height;
            // Downsample to lower resolution
            _TrianglesTemplate = CreateMesh(frameDesc.Width / _DownsampleSize, frameDesc.Height / _DownsampleSize);

            if (!_Sensor.IsOpen)
            {
                _Sensor.Open();
            }
        }
        // must be greater than 0, less or equal to 2048 and a multiple of 4.
        _Buffer = new ComputeBuffer(_TrianglesTemplate.Length / 3, 60);

        _Shader.SetInt("width", width);
        _Shader.SetInt("height", height);
        _Shader.SetInt("downSampleSize", _DownsampleSize);
        _Shader.SetFloat("cx", _CameraIntrinsics.PrincipalPointX);
        _Shader.SetFloat("cy", _CameraIntrinsics.PrincipalPointY);
        _Shader.SetFloat("fx", _CameraIntrinsics.FocalLengthX);
        _Shader.SetFloat("fy", _CameraIntrinsics.FocalLengthY);
    }
Esempio n. 3
0
    // Use this for initialization
    private void Start()
    {
        myShader = Shader.Find("Unlit/Texture_color");
        _Sensor  = KinectSensor.GetDefault();
        if (_Sensor != null)
        {
            //get coordinate mapper
            _Mapper = _Sensor.CoordinateMapper;
            var frameDesc = _Sensor.DepthFrameSource.FrameDescription;

            //set the camera intrinsics
            PrincipalPointX = _Mapper.GetDepthCameraIntrinsics().PrincipalPointX;
            PrincipalPointY = _Mapper.GetDepthCameraIntrinsics().PrincipalPointY;
            FocalLengthX    = _Mapper.GetDepthCameraIntrinsics().FocalLengthX;
            FocalLengthY    = _Mapper.GetDepthCameraIntrinsics().FocalLengthY;

            //get frame Width and Height
            W = frameDesc.Width;
            H = frameDesc.Height;

            //calculate local scaled variables
            scaledW = (int)Math.Floor((double)W / skip + 1);
            scaledH = (int)Math.Floor((double)H / skip + 1);

            //for GUI controls... movie is not recording at start
            //started = false;

            if (!_Sensor.IsOpen)
            {
                _Sensor.Open();
            }
        }

        structure = new GameObject("Point Cloud");
        structure.transform.parent        = gameObject.transform;
        structure.transform.localPosition = new Vector3(0, 0, 0);

        _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>();
        if (_MultiManager == null)
        {
            return;
        }

        elapsedTime = 0;
    }
Esempio n. 4
0
    void Start()
    {
        int width = 0, height = 0;

        _Sensor = KinectSensor.GetDefault();
        if (_Sensor != null)
        {
            _Mapper           = _Sensor.CoordinateMapper;
            _CameraIntrinsics = _Mapper.GetDepthCameraIntrinsics();

            var frameDesc = _Sensor.DepthFrameSource.FrameDescription;
            width  = frameDesc.Width;
            height = frameDesc.Height;
            // Downsample to lower resolution
            _TrianglesTemplate = Init(frameDesc.Width / _DownsampleSize, frameDesc.Height / _DownsampleSize);

            if (!_Sensor.IsOpen)
            {
                _Sensor.Open();
            }
        }
        // must be greater than 0, less or equal to 2048 and a multiple of 4.
        _Buffer = new ComputeBuffer(_TrianglesTemplate.Length / 3, 36);

        // 初始化参数
        colmap = new float[512];
        rowmap = new float[424];

        for (int i = 0; i < 512; i++)
        {
            colmap[i] = (i - _CameraIntrinsics.PrincipalPointX + 0.5f) / _CameraIntrinsics.FocalLengthX;
        }
        for (int i = 0; i < 424; i++)
        {
            rowmap[i] = (i - _CameraIntrinsics.PrincipalPointY + 0.5f) / _CameraIntrinsics.FocalLengthY;
        }

        _Shader.SetInt("width", width);
        _Shader.SetInt("height", height);
        _Shader.SetInt("downSampleSize", _DownsampleSize);
        _Shader.SetFloat("cx", _CameraIntrinsics.PrincipalPointX);
        _Shader.SetFloat("cy", _CameraIntrinsics.PrincipalPointY);
        _Shader.SetFloat("fx", _CameraIntrinsics.FocalLengthX);
        _Shader.SetFloat("fy", _CameraIntrinsics.FocalLengthY);
        _Shader.SetFloat("maxDepthLimit", maxDepthLimit);
        _Shader.SetFloat("minDepthLimit", minDepthLimit);
        _Shader.SetFloat("distanceThreshold", distanceThreshold);
        //_Shader.SetFloats("colmap", colmap);
        //_Shader.SetFloats("rowmap", rowmap);
        _NumThread = _TrianglesTemplate.Length / 3 / 8;
    }
Esempio n. 5
0
        private Point3D get3DPoint(System.Windows.Point depthPoint, ushort[] depthPoints, CoordinateMapper coordinateMapper)
        {
            unsafe
            {
                //for (int i = 2000; i < 2020;i++ )
                //{

                //Console.WriteLine("DEPTHFRAME: {0}", frameData[512*424-1]);
                //}
                int depthWidth  = 512;
                int depthHeight = 424;
                if (((int)depthPoint.X) + ((int)depthPoint.Y) * depthWidth < depthWidth * depthHeight && depthPoint.X > 0 && depthPoint.Y > 0)
                {
                    //Console.WriteLine("lalala {0} , {1}", (((int)depthPoint.X) + ((int)depthPoint.Y) * depthWidth), depthPoints[((int)depthPoint.X) + ((int)depthPoint.Y) * depthWidth]);
                    double Z = (-1) * depthPoints[((int)depthPoint.X) + ((int)depthPoint.Y) * depthWidth];
                    double X = (((double)Z) * (depthPoint.X - coordinateMapper.GetDepthCameraIntrinsics().PrincipalPointX)) / coordinateMapper.GetDepthCameraIntrinsics().FocalLengthX;
                    double Y = (((double)Z) * (depthPoint.Y - coordinateMapper.GetDepthCameraIntrinsics().PrincipalPointY)) / coordinateMapper.GetDepthCameraIntrinsics().FocalLengthY;

                    return(new Point3D(X, Y, Z));
                }
            }

            return(new Point3D(-1, -1, -1));
        }
Esempio n. 6
0
    void Start()
    {
        int width = 0, height = 0;

        _Sensor = KinectSensor.GetDefault();
        if (_Sensor != null)
        {
            _Mapper           = _Sensor.CoordinateMapper;
            _CameraIntrinsics = _Mapper.GetDepthCameraIntrinsics();

            var frameDesc = _Sensor.DepthFrameSource.FrameDescription;
            width  = frameDesc.Width;
            height = frameDesc.Height;
            // Downsample to lower resolution
            _TrianglesTemplate = CreateMesh(frameDesc.Width / _DownsampleSize, frameDesc.Height / _DownsampleSize);

            if (!_Sensor.IsOpen)
            {
                _Sensor.Open();
            }
        }
        // must be greater than 0, less or equal to 2048 and a multiple of 4.
        _Buffer = new ComputeBuffer(_TrianglesTemplate.Length / 6, 60);
    }
Esempio n. 7
0
        // Constructor
        public FrameManager()
        {
            _Sensor = KinectSensor.GetDefault();

            if (_Sensor != null)
            {
                _Mapper = _Sensor.CoordinateMapper;

                _Reader = _Sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth);

                var depthFrameDesc = _Sensor.DepthFrameSource.FrameDescription;
                DepthWidth     = depthFrameDesc.Width;
                DepthHeight    = depthFrameDesc.Height;
                DepthData_full = new ushort[depthFrameDesc.LengthInPixels];
                DepthData      = new ushort[depthFrameDesc.LengthInPixels / (defines.DOWNSAMPLE * defines.DOWNSAMPLE)];
                //DepthRaw = new byte[depthFrameDesc.LengthInPixels * 4];
                //DepthTexture_full = new Texture2D( DepthWidth, DepthHeight, TextureFormat.RGBA32, false );

                // Set FrameWidth and FrameHeight to the downsampled size
                Width  = DepthWidth / defines.DOWNSAMPLE;
                Height = DepthHeight / defines.DOWNSAMPLE;

                var colorFrameDesc = _Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
                ColorWidth         = colorFrameDesc.Width;
                ColorHeight        = colorFrameDesc.Height;
                ColorData_full     = new byte[colorFrameDesc.BytesPerPixel * colorFrameDesc.LengthInPixels];
                ColorData          = new byte[colorFrameDesc.BytesPerPixel * Width * Height];
                ColorTexture_full  = new Texture2D(ColorWidth, ColorHeight, TextureFormat.RGBA32, false);
                ColorTexture       = new Texture2D(Width, Height, TextureFormat.RGBA32, false);
                ColorTextureVisual = new Texture2D(Width, Height, TextureFormat.RGBA32, false);

                //PfImage = new Texture2D( Width, Height, TextureFormat.RGBA32, false );

                // Set buffers to align depth data to RGB and to align camera points
                ColorPoints_full    = new ColorSpacePoint[depthFrameDesc.LengthInPixels];
                Camera3DPoints_full = new CameraSpacePoint[DepthWidth * DepthHeight];
                Camera3DPoints      = new CameraSpacePoint[Width * Height];
                PfVec = new float[Width * Height];
                Mask  = new short[Width * Height];

                // Save camera intrinsics matrix
                CameraIntrinsics intrinsics = _Mapper.GetDepthCameraIntrinsics();
                K     = new Matrix4x4();
                K.m00 = intrinsics.FocalLengthX / defines.DOWNSAMPLE;
                K.m01 = 0;
                K.m02 = intrinsics.PrincipalPointX / defines.DOWNSAMPLE;
                K.m10 = 0;
                K.m11 = intrinsics.FocalLengthY / defines.DOWNSAMPLE;
                K.m12 = intrinsics.PrincipalPointY / defines.DOWNSAMPLE;
                K.m20 = 0; K.m21 = 0;
                K.m22 = 1.0f;// / defines.DOWNSAMPLE;

                // TODO print K
                Debug.Log("K = " + K);
                Debug.Log("Color Width: " + ColorWidth + " Color Height: " + ColorHeight);
                Debug.Log("Depth Width: " + DepthWidth + " Depth Height: " + DepthHeight);
                Debug.Log(" Width: " + Width + " Height: " + Height);

                // Initialize color histogram
                histogram = new ColorHistogram(defines.HISTOGRAM_NBIN, Width, Height);


                HistogramTexture = new Texture2D(4, 4, TextureFormat.RFloat, false);
                //Debug.Log( HistogramTexture.width );
                //Debug.Log( HistogramTexture.height );
                //Debug.Log( histogram.posterior.Length );

                if (!_Sensor.IsOpen)
                {
                    _Sensor.Open();
                }
            }
        }