Esempio n. 1
0
    void OnRectangleUpdate(List <RotatedRect> l)
    {
        if (!isEnabled)
        {
            return;
        }

        if (l.Count == 0)
        {
            renderer.material.SetInt("_enable_rect", 0);
            return;
        }
        renderer.material.SetInt("_enable_rect", 1);
        int width  = DepthSourceManager.Width();
        int height = DepthSourceManager.Height();

        System.Drawing.PointF[] points = l[0].GetVertices();
        Vector4[] positions            = new Vector4[4];
        for (int j = 0; j < 4; j++)
        {
            Vector2 point = new Vector2(points[j].X / width, points[j].Y / height);
            point = point * 2 - new Vector2(1, 1);
            //point = -point;
            positions[j] = new Vector4(point.x, point.y, 0, 0);
        }
        renderer.material.SetVectorArray("rectangle_points", positions);
    }
Esempio n. 2
0
    // Update is called once per frame
    void UpdatedRect(byte[] bg, byte[] rects)
    {
        if (!gameObject.activeInHierarchy)
        {
            return;
        }

        int width  = DepthSourceManager.Width();
        int height = DepthSourceManager.Height();

        if (_Texture == null)
        {
            converted_data = new Color[width * height];
            for (int i = 0; i < converted_data.Length; i++)
            {
                converted_data[i] = new Color(0, 0, 0, 0);
            }
            _Texture = new Texture2D(width, height, TextureFormat.RGBAFloat, false);
            gameObject.GetComponent <RawImage>().material.SetTextureScale("_MainTex", new Vector2(-1, 1));
            gameObject.GetComponent <RawImage>().texture = _Texture;
        }

        for (int i = 0; i < bg.Length; i++)
        {
            converted_data[i] = new Color((float)bg[i] / 255.0f * 10, (float)rects[i] / 255.0f * 10, 0.0f, 0.0f);
        }

        _Texture.SetPixels(converted_data);
        _Texture.Apply();
    }
Esempio n. 3
0
 void Start()
 {
     frameDescription   = KinectSensor.GetDefault().DepthFrameSource.FrameDescription;
     depthSourceManager = DepthSourceManager.GetComponent <DepthSourceManager>();
     depthTexture       = new Texture2D(frameDescription.Width, frameDescription.Height, TextureFormat.RGB24, false);
     depthImageBuffer   = new byte[frameDescription.LengthInPixels * 3];
 }
    private const bool useSensor = true;        // For debugging purposes. Uses heightmap instead of sensor data when false

    void Start()
    {
        sensor = KinectSensor.GetDefault();

        if (sensor != null)
        {
            mapper  = sensor.CoordinateMapper;
            manager = depthSourceManager.GetComponent <DepthSourceManager> ();
            if (manager == null)
            {
                return;
            }

            mesh = new Mesh();                          // Initialize mesh
            GetComponent <MeshFilter> ().mesh = mesh;

            FrameDescription frameDesc = sensor.DepthFrameSource.FrameDescription;
            frameWidth  = frameDesc.Width;
            frameHeight = frameDesc.Height;

            spacing = scale / frameHeight;

            CreateMesh(frameWidth / downsampleSize, frameHeight / downsampleSize);

            if (!sensor.IsOpen)
            {
                sensor.Open();
            }
        }
    }
Esempio n. 5
0
    void Update()
    {
        //depthBuffer の更新

        if (DepthSourceManager == null)
        {
            return;
        }

        _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>();

        depthBuffer = _DepthManager.GetData();

        // 指の判定

        checkPoint();

        // 初期化キー待機

        if (Input.GetKey(KeyCode.I))
        {
            Invoke("setFirstPoint", 0.5f);
        }
        if (Input.GetKey(KeyCode.C))
        {
            // 球体の半径取得

            IndexDatas indexDatasObj = GetComponent <IndexDatas>();

            int radius = checkCircleLength(indexDatasObj.indexes_Y[3]);

            GameObject gameobject = Instantiate(painter, new Vector3(indexDatasObj.indexes_X[3], indexDatasObj.indexes_Y[3], 1), Quaternion.identity);
            gameobject.transform.localScale = new Vector3(radius, radius, 1);
        }
    }
    public void Init(float height, Vector3 rot, float distance, KinectConfig.Box[] buttons)
    {
        _Mesh      = new Mesh();
        _Mesh.name = "DynamicKinectMesh";
        _Collider  = GetComponent <MeshCollider>();

        colors = new Color32[54272];
        for (int i = 0; i < colors.Count(); i++)
        {
            colors[i] = new Color32(255, 255, 255, 255);
        }

        GetComponent <MeshFilter>().mesh = _Mesh;
        _DepthManager      = DepthSourceManager.GetComponent <DepthSourceManager>();
        _DepthManager.maxZ = distance * 1000.0f;

        _DepthManager.Init();

        transform.position = new Vector3(0, height, 0);
        transform.rotation = Quaternion.Euler(rot);

        foreach (KinectConfig.Box buttonData in buttons)
        {
            createButton(buttonData);
        }
    }
Esempio n. 7
0
    // Update is called once per frame
    void Update()
    {
        //Debug.Log("Depth camera: " + DepthSourceManager.Width() + " " + DepthSourceManager.Height());
        float lsz = DepthSourceManager.Height() / ((float)DepthSourceManager.Width());
        float lsx = lsz * ColorSourceManager.ColorWidth / ((float)ColorSourceManager.ColorHeight);

        transform.localScale = 0.2f * new Vector3(lsx, 5.0f, lsz);
    }
    // Start is called before the first frame update
    void Start()
    {
        _Sensor = KinectSensor.GetDefault();

        texture = new Texture2D(depthWidth, depthHeight);
        gameObject.GetComponent <Renderer>().material.mainTexture = texture;
        _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>();
        frameDesc     = _Sensor.DepthFrameSource.FrameDescription;
    }
Esempio n. 9
0
    private void updatedRect(Transform t, RotatedRect r)
    {
        if (!isListening)
        {
            return;
        }

        var points_kinect = r.GetVertices();

        calibrateHomographyMaths(points_kinect, DepthSourceManager.Width(), DepthSourceManager.Height());
    }
Esempio n. 10
0
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }

        if (DepthSourceManager == null)
        {
            return;
        }

        _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>();
        if (_DepthManager == null)
        {
            return;
        }

        updateTexture();
        compute_shader.SetTexture(handle_main, "reader", A);
        compute_shader.SetTexture(handle_main, "reader2", texture);
        compute_shader.SetFloat("_time", Time.time);
        compute_shader.SetFloat("_img1", _img1);
        compute_shader.SetFloat("_img2", _img2);
        compute_shader.SetFloat("_img3", _img3);
        compute_shader.SetFloat("_img4", _img4);
        compute_shader.SetFloat("_s1", _s1);
        compute_shader.SetFloat("_s2", _s2);
        compute_shader.SetFloat("_s3", _s3);
        compute_shader.SetFloat("_s4", _s4);
        compute_shader.SetFloat("_s5", _s5);
        compute_shader.SetFloat("_s6", _s6);
        compute_shader.SetFloat("_rx1", _rx1);
        compute_shader.SetFloat("_rx2", _rx2);
        compute_shader.SetFloat("_ry1", _ry1);
        compute_shader.SetFloat("_ry2", _ry2);
        compute_shader.SetFloat("_blur", _blur);
        compute_shader.SetTexture(handle_main, "writer", B);
        compute_shader.SetTexture(handle_main, "writer2", C);
        compute_shader.Dispatch(handle_main, B.width / 8, B.height / 8, 1);
        compute_shader.SetTexture(handle_main, "reader", B);
        compute_shader.SetTexture(handle_main, "writer", A);
        compute_shader.Dispatch(handle_main, B.width / 8, B.height / 8, 1);
        material.SetTexture("_MainTex", C);
        img1.GetComponent <Renderer>().material.mainTexture = B;
        img2.GetComponent <Renderer>().material.mainTexture = B;
        img3.GetComponent <Renderer>().material.mainTexture = B;
        img4.GetComponent <Renderer>().material.mainTexture = B;
        //decor.GetComponent<Renderer>().material.SetTexture("_sec", texture);
    }
Esempio n. 11
0
    // public RenderTexture rd;

    void Start()
    {
        // Get the description of the depth frames.
        depthFrameDesc = KinectSensor.GetDefault().DepthFrameSource.FrameDescription;

        // get reference to DepthSourceManager (which is included in the distributed 'Kinect for Windows v2 Unity Plugin zip')
        depthSourceManagerScript = depthSourceManager.GetComponent <DepthSourceManager>();

        // allocate.
        depthBitmapBuffer = new byte[depthFrameDesc.LengthInPixels * 3];
        texture           = new Texture2D(depthFrameDesc.Width, depthFrameDesc.Height, TextureFormat.RGB24, false);

        // arrange size of gameObject to be drawn
        //gameObject.transform.localScale = new Vector3(scale * depthFrameDesc.Width / depthFrameDesc.Height, scale, 1.0f);
    }
    void Start()
    {
        // Get the description of the depth frames.
        depthFrameDesc = KinectSensor.GetDefault().DepthFrameSource.FrameDescription;

        // get reference to DepthSourceManager (which is included in the distributed 'Kinect for Windows v2 Unity Plugin zip')
        depthSourceManagerScript = depthSourceManager.GetComponent<DepthSourceManager> ();

        // allocate.
        depthBitmapBuffer = new byte[depthFrameDesc.LengthInPixels * 3];
        texture = new Texture2D(depthFrameDesc.Width, depthFrameDesc.Height, TextureFormat.RGB24, false);

        // arrange size of gameObject to be drawn
        gameObject.transform.localScale = new Vector3 (scale * depthFrameDesc.Width / depthFrameDesc.Height, scale, 1.0f);
    }
 void Start()
 {
     depthFrameDesc = KinectSensor.GetDefault().DepthFrameSource.FrameDescription;
     depthWidth = depthFrameDesc.Width;
     depthHeight = depthFrameDesc.Height;
     // buffer for points mapped to camera space coordinate.
     mapper = KinectSensor.GetDefault().CoordinateMapper;
     cameraSpacePoints = new CameraSpacePoint[depthWidth * depthHeight];
     depthSourceManagerScript = depthSourceManager.GetComponent<DepthSourceManager>();
     colorSourceManagerScript = colorSourceManager.GetComponent<ColorSourceManager>();
     particles = new ParticleSystem.Particle[depthWidth * depthHeight];
     color_reader = KinectSensor.GetDefault().ColorFrameSource.OpenReader();
     colorFrameDesc = KinectSensor.GetDefault().ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
     colorSpacePoints = new ColorSpacePoint[depthWidth * depthHeight];
     color_array = new byte[colorFrameDesc.BytesPerPixel * colorFrameDesc.LengthInPixels];
 }
Esempio n. 14
0
 void Start()
 {
     depthFrameDesc = KinectSensor.GetDefault().DepthFrameSource.FrameDescription;
     depthWidth     = depthFrameDesc.Width;
     depthHeight    = depthFrameDesc.Height;
     // buffer for points mapped to camera space coordinate.
     mapper                   = KinectSensor.GetDefault().CoordinateMapper;
     cameraSpacePoints        = new CameraSpacePoint[depthWidth * depthHeight];
     depthSourceManagerScript = depthSourceManager.GetComponent <DepthSourceManager>();
     colorSourceManagerScript = colorSourceManager.GetComponent <ColorSourceManager>();
     particles                = new ParticleSystem.Particle[depthWidth * depthHeight];
     color_reader             = KinectSensor.GetDefault().ColorFrameSource.OpenReader();
     colorFrameDesc           = KinectSensor.GetDefault().ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
     colorSpacePoints         = new ColorSpacePoint[depthWidth * depthHeight];
     color_array              = new byte[colorFrameDesc.BytesPerPixel * colorFrameDesc.LengthInPixels];
 }
Esempio n. 15
0
    void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }

        // scene root of world hierarchy
        WorldParent = GameObject.FindGameObjectWithTag("WorldParent").transform;

        GameManager  = FindObjectOfType <GameManager>();
        DepthManager = FindObjectOfType <DepthSourceManager>();
        Palette      = gameObject.AddComponent <ColorPalette>();

        UnityEngine.Application.targetFrameRate = 60;
    }
    void Start()
    {
        // Get the description of the depth frames.
        depthFrameDesc = KinectSensor.GetDefault().DepthFrameSource.FrameDescription;
        depthWidth = depthFrameDesc.Width;
        depthHeight = depthFrameDesc.Height;

        // buffer for points mapped to camera space coordinate.
        cameraSpacePoints = new CameraSpacePoint[depthWidth * depthHeight];
        mapper = KinectSensor.GetDefault ().CoordinateMapper;

        // get reference to DepthSourceManager (which is included in the distributed 'Kinect for Windows v2 Unity Plugin zip')
        depthSourceManagerScript = depthSourceManager.GetComponent<DepthSourceManager> ();

        // particles to be drawn
        particles = new ParticleSystem.Particle[depthWidth * depthHeight];
    }
    void Start()
    {
        // Get the description of the depth frames.
        depthFrameDesc = KinectSensor.GetDefault().DepthFrameSource.FrameDescription;
        depthWidth     = depthFrameDesc.Width;
        depthHeight    = depthFrameDesc.Height;

        // buffer for points mapped to camera space coordinate.
        cameraSpacePoints = new CameraSpacePoint[depthWidth * depthHeight];
        mapper            = KinectSensor.GetDefault().CoordinateMapper;

        // get reference to DepthSourceManager (which is included in the distributed 'Kinect for Windows v2 Unity Plugin zip')
        depthSourceManagerScript = depthSourceManager.GetComponent <DepthSourceManager> ();

        // particles to be drawn
        particles = new ParticleSystem.Particle[depthWidth * depthHeight];
    }
Esempio n. 18
0
    // Use this for initialization
    void Start()
    {
        PlayerPrefUpdateBroadcast.Instance.OnPlayerPrefsUpdated += OnPlayerPrefsUpdated;
        if (loadConfigOnStart)
        {
            loadConfig();
        }

        kinect = KinectSensor.GetDefault();
        if (kinect != null)
        {
            mapper = kinect.CoordinateMapper;
            var frameDesc = kinect.DepthFrameSource.FrameDescription;

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

            depthWidth   = frameDesc.Width;
            depthHeight  = frameDesc.Height;
            depthMapSize = depthHeight * depthWidth / downSample;

            Debug.Log("Kinect Depth Width :" + depthWidth + " / Height : " + depthHeight);

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

        depthManager = GetComponent <DepthSourceManager>();

        if (useTCLStreamer)
        {
            int numLines = depthHeight / (downSample - 1);
            pcl = new KPCL[numLines];
            for (int i = 0; i < numLines; i++)
            {
                pcl[i]        = new KPCL();
                pcl[i].points = new KPCL.Vector_3[(depthWidth / (downSample - 1))];
            }

            pcl[0].isFirst = true;
        }
    }
Esempio n. 19
0
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }

        if (DepthSourceManager == null)
        {
            return;
        }

        _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>();
        if (_DepthManager == null)
        {
            return;
        }

        updateTexture();

        //gameObject.GetComponent<Renderer>().material.mainTexture = texture;
        //gameObject.GetComponent<detec>().C = texture;
    }
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }
        //點擊滑鼠右鍵切換單組資源配置或是多組資源配置。
        if (Input.GetButtonDown("Fire1"))
        {
            if(ViewMode == DepthViewMode.MultiSourceReader)
            {
                ViewMode = DepthViewMode.SeparateSourceReaders;
            }
            else
            {
                ViewMode = DepthViewMode.MultiSourceReader;
            }
        }
        //使用上下左右鍵旋轉Mesh物件。
        float yVal = Input.GetAxis("Horizontal");
        float xVal = -Input.GetAxis("Vertical");

        transform.Rotate(
            (xVal * Time.deltaTime * _Speed),
            (yVal * Time.deltaTime * _Speed),
            0,
            Space.Self);
        //如果切換到了單組資源配置的執行工作。
        if (ViewMode == DepthViewMode.SeparateSourceReaders)
        {
            if (ColorSourceManager == null)
            {
                return;
            }

            _ColorManager = ColorSourceManager.GetComponent<ColorSourceManager>();
            if (_ColorManager == null)
            {
                return;
            }

            if (DepthSourceManager == null)
            {
                return;
            }

            _DepthManager = DepthSourceManager.GetComponent<DepthSourceManager>();
            if (_DepthManager == null)
            {
                return;
            }

            gameObject.renderer.material.mainTexture = _ColorManager.GetColorTexture();
            RefreshData(_DepthManager.GetData(),
                _ColorManager.ColorWidth,
                _ColorManager.ColorHeight);
        }
        else//如果切換到了多組資源配置的執行工作。
        {
            if (MultiSourceManager == null)
            {
                return;
            }

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

            gameObject.renderer.material.mainTexture = _MultiManager.GetColorTexture();

            RefreshData(_MultiManager.GetDepthData(),
                        _MultiManager.ColorWidth,
                        _MultiManager.ColorHeight);
        }
    }
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }

        if (Input.GetButtonDown("Fire1"))
        {
            if (ViewMode == DepthViewMode.MultiSourceReader)
            {
                ViewMode = DepthViewMode.SeparateSourceReaders;
            }
            else
            {
                ViewMode = DepthViewMode.MultiSourceReader;
            }
        }

        float yVal = Input.GetAxis("Horizontal");
        float xVal = -Input.GetAxis("Vertical");

        transform.Rotate(
            (xVal * Time.deltaTime * _Speed),
            (yVal * Time.deltaTime * _Speed),
            0,
            Space.Self);

        if (ViewMode == DepthViewMode.SeparateSourceReaders)
        {
            if (ColorSourceManager == null)
            {
                return;
            }

            _ColorManager = ColorSourceManager.GetComponent <ColorSourceManager>();
            if (_ColorManager == null)
            {
                return;
            }

            if (DepthSourceManager == null)
            {
                return;
            }

            _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>();
            if (_DepthManager == null)
            {
                return;
            }

            gameObject.GetComponent <Renderer>().material.mainTexture = _ColorManager.GetColorTexture();
            RefreshData(_DepthManager.GetData(),
                        _ColorManager.ColorWidth,
                        _ColorManager.ColorHeight);
        }
        else
        {
            if (MultiSourceManager == null)
            {
                return;
            }

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

            gameObject.GetComponent <Renderer>().material.mainTexture = _MultiManager.GetColorTexture();

            RefreshData(_MultiManager.GetDepthData(),
                        _MultiManager.ColorWidth,
                        _MultiManager.ColorHeight);
        }
    }
Esempio n. 22
0
    void Update()
    {
        if (_Reader != null)
        {
            var frame = _Reader.AcquireLatestFrame();

            if (frame != null)
            {
                frame.CopyConvertedFrameDataToArray(_Data, ColorImageFormat.Rgba);
                _Texture.LoadRawTextureData(_Data);
                _Texture.Apply();

                frame.Dispose();
                frame = null;

                if (prevX != -1 && prevY != -1) {
                    startSearchOffsetX = (int)prevX;
                    startSearchOffsetY = (int)prevY;
                } else {
                    startSearchOffsetX = 0;
                    startSearchOffsetY = 0;
                }

                //Rasmus här är nya koden för sökningen av bollen. Vi har globala variabler uppe som vi använder
                //Point är bara en punkt som innehåller x,y (koordinater) och r,g,b (rgb-värden). tempPixelColor och yellowBall är Pointobjekt
                int pixelSteps = 7;
                for(int i = 0; i < ColorWidth; i+=pixelSteps){
                    for(int j = 0; j < ColorHeight; j+=pixelSteps){
                        //int ii = (offsetX + startSearchOffsetX + i) % ColorWidth;
                        //int jj = (offsetY + startSearchOffsetY + j) % ColorHeight;

                        int ii = i;
                        int jj = j;

                        tempPixelColor.r = _Texture.GetPixel(ii,jj).r;
                        tempPixelColor.g = _Texture.GetPixel(ii,jj).g;
                        tempPixelColor.b = _Texture.GetPixel(ii,jj).b;

                        //Euclidean räknar bara ut euklidiska distansen i rgb-format mellan pixeln vi kollar och vårt försatta värde av den gula bollen
                        currentColorDistance = Euclidean(tempPixelColor, yellowBall);
                        if(currentColorDistance < _allowedDistance){
                            DrawCircle(ii,jj);
                            //Debug.Log("ii/jj is:" + ii.ToString() + "/" + jj.ToString());

                            //We have found what we think is a match. Now find the middle point

                            int precisionCheckSize = 200;
                            int numMatches = 0;
                            double x = 0;
                            double y = 0;
                            double xSum = 0, ySum = 0;
                            for (int i2 = -precisionCheckSize; i2 < precisionCheckSize; i2 += 4) {
                                for (int j2 = -precisionCheckSize; j2 < precisionCheckSize; j2 += 4) {
                                    x = ii+i2;
                                    y = jj+j2;
                                    //Debug.Log("INSIDE CHECK: ii/jj is:" + ii.ToString() + "/" + jj.ToString());

                                    if (x >= 0 && x < ColorWidth && y >= 0 && y < ColorHeight) {
                                        tempPixelColor.r = _Texture.GetPixel((int)x, (int)y).r;
                                        tempPixelColor.g = _Texture.GetPixel((int)x, (int)y).g;
                                        tempPixelColor.b = _Texture.GetPixel((int)x, (int)y).b;

                                        /*
                                        if (Euclidean(tempPixelColor, yellowBall) < 0.3) {
                                            Debug.Log("euclidian: " + Euclidean(tempPixelColor, yellowBall).ToString());
                                        }*/

                                        if (Euclidean(tempPixelColor, yellowBall) < _allowedDistance*0.7) {
                                            //match was found!
                                            //Debug.Log("Match found!");
                                            numMatches += 1;
                                            xSum += x;
                                            ySum += y;
                                        }
                                    }
                                }
                            }

                            if (numMatches > 0) {
                                //Debug.Log(numMatches);
                                x = xSum / (double)numMatches;
                                y = ySum / (double)numMatches;

                                //SOCKET: data ska vara koordinater
                                //dataToSend = System.Text.Encoding.ASCII.GetBytes("hej2");
                                dataToSend = System.Text.Encoding.ASCII.GetBytes(x.ToString() + " " + y.ToString());
                                if (stream != null) { stream.Write(dataToSend, 0, dataToSend.Length); }

                                if (prevX != -1 && prevY != -1) {
                                    DrawCircle((x+prevX)/2, (y+prevY)/2);
                                } else {
                                    DrawCircle(x, y);
                                }
                                prevX = x;
                                prevY = y;

                                foundX = x;
                                foundY = y;

                                //Debug.Log ("x=" + x.ToString() + ", y=" + y.ToString() + "numMatches=" + numMatches.ToString());
                                Debug.Log ("numMatches: " + numMatches.ToString());

                                //jump out of loop, don't look for more objects
                                i = ColorWidth + 9001;
                                j = ColorHeight + 9001;
                            }

                            // _DepthManager borde innehålla djupdatan men om man kommenterar ut nedstående tre rader så funkar ej utskriften av pixelvärdet längre???
                            if (DepthSourceManager == null){return;}

                            _DepthManager = DepthSourceManager.GetComponent<DepthSourceManager>();

                            if (_DepthManager == null){return;}
                            //Debug.Log (_DepthManager.GetData());
                            //*Debug.Log(currentColorDistance);

                        } else {
                            //DrawCircle(-500.0,-500.0);
                            //lineRenderer.SetVertexCount(0);
                            prevX = -1;
                            prevY = -1;
                        }
                    }
                }
                //Debug.Log (ColorWidth);
                //Debug.Log (ColorHeight);
            }
        }
    }
Esempio n. 23
0
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }

        float yVal = Input.GetAxis("Horizontal");
        float xVal = -Input.GetAxis("Vertical");

        transform.Rotate(
            (xVal * Time.deltaTime * _Speed),
            (yVal * Time.deltaTime * _Speed),
            0,
            Space.Self);

        if (DepthSourceManager == null)
        {
            return;
        }

        _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>();
        if (_DepthManager == null)
        {
            return;
        }

        /*if (ViewMode == DepthViewMode.SeparateSourceReaders)
         * {
         *  if (ColorSourceManager == null)
         *  {
         *      return;
         *  }
         *
         *  _ColorManager = ColorSourceManager.GetComponent<ColorSourceManager>();
         *  if (_ColorManager == null)
         *  {
         *      return;
         *  }
         *
         *
         *  gameObject.GetComponent<Renderer>().material.mainTexture = _ColorManager.GetColorTexture();
         *  RefreshData(_DepthManager.GetData(),
         *      _ColorManager.ColorWidth,
         *      _ColorManager.ColorHeight);
         * }
         * else
         * {
         *  if (MultiSourceManager == null)
         *  {
         *      return;
         *  }
         *
         *  _MultiManager = MultiSourceManager.GetComponent<MultiSourceManager>();
         *  if (_MultiManager == null)
         *  {
         *      return;
         *  }
         *
         *  gameObject.GetComponent<Renderer>().material.mainTexture = _MultiManager.GetColorTexture();
         *
         *  RefreshData(_MultiManager.GetDepthData(),
         *              _MultiManager.ColorWidth,
         *              _MultiManager.ColorHeight);
         * }*/
    }
Esempio n. 24
0
    void Start()
    {
        renderer = GetComponent <Renderer>();

        // Get the description of the depth frames.
        depthFrameDesc = KinectSensor.GetDefault().DepthFrameSource.FrameDescription;

        // get reference to DepthSourceManager (which is included in the distributed 'Kinect for Windows v2 Unity Plugin zip')
        depthSourceManagerScript = depthSourceManager.GetComponent <DepthSourceManager>();

        // allocate.
        depthBitmapBuffer  = new byte[depthFrameDesc.LengthInPixels * 4];
        depthBitmapBuffer2 = new byte[depthFrameDesc.LengthInPixels * 4];
        depthBitmapBuffer3 = new byte[depthFrameDesc.LengthInPixels * 4];

        texture    = new Texture2D(depthFrameDesc.Width, depthFrameDesc.Height, TextureFormat.BGRA32, false);
        subTexture = new Texture2D(depthFrameDesc.Width, depthFrameDesc.Height, TextureFormat.BGRA32, false);

        f_DepthMapWidth  = depthFrameDesc.Width;
        f_DepthMapHeight = depthFrameDesc.Height;

        // arrange size of gameObject to be drawn
        gameObject.transform.localScale = new Vector3(scale * depthFrameDesc.Width / depthFrameDesc.Height, scale, 1.0f);
        subObj.transform.localScale     = new Vector3(scale * depthFrameDesc.Width / depthFrameDesc.Height, scale, 1.0f);


        prevMat = new Mat(texture.height, texture.width, CvType.CV_8UC1);       //1차원 행렬 선언

        sumMat       = new Mat(texture.height, texture.width, CvType.CV_32FC1); //1차원 행렬 선언
        avgMat       = new Mat(texture.height, texture.width, CvType.CV_32FC1); //1차원 행렬 선언
        convert32Mat = new Mat(texture.height, texture.width, CvType.CV_32FC1);
        convert8Mat  = new Mat(texture.height, texture.width, CvType.CV_8UC1);

        resultMat1 = new Mat(texture.height, texture.width, CvType.CV_8UC1);
        resultMat2 = new Mat(texture.height, texture.width, CvType.CV_8UC1);
        resultMat3 = new Mat(texture.height, texture.width, CvType.CV_8UC1);

        //평균을 내기위해 avgMat에 값을 넣어준다.
        double data = MAT_BUFFER_SIZE - 1;

        for (int i = 0; i < avgMat.height(); i++)
        {
            for (int j = 0; j < avgMat.width(); j++)
            {
                avgMat.put(i, j, data);
            }
        }

        //합영상을 위한 버퍼
        matBuffer  = new CircularBuffer <Mat>(MAT_BUFFER_SIZE);
        matBuffer2 = new CircularBuffer <Mat>(MAT_BUFFER_SIZE);
        matBuffer3 = new CircularBuffer <Mat>(MAT_BUFFER_SIZE);

        sumCount1 = 0;
        sumCount2 = 0;
        sumCount3 = 0;


        //파티클 오브젝트를 생성한다.
        ParticleObjInit();
    }
Esempio n. 25
0
    void OnRectangleUpdate(List <RotatedRect> l)
    {
        if (!isEnabled)
        {
            return;
        }
        if (l.Count > 0)
        {
            if (OnUnstableRectangleEvent != null)
            {
                int width  = DepthSourceManager.Width();
                int height = DepthSourceManager.Height();

                if (debug)
                {
                    width = height = 512;
                }

                RotatedRect copy  = l[0];
                float       r_w   = copy.Size.Width;
                float       r_h   = copy.Size.Height;
                float       angle = copy.Angle;

                if (r_h > r_w)
                {
                    r_h   = copy.Size.Width;
                    r_w   = copy.Size.Height;
                    angle = angle - 90.0f;
                }

                Vector2 centre = new Vector2(l[0].Center.X / width, l[0].Center.Y / height);
                centre = centre * 2 - new Vector2(1, 1);
                centre = -centre;
                tracked.transform.position   = new Vector3(centre.x, 0, centre.y) + transform.position;
                tracked.transform.localScale = new Vector3(r_w / width, 0.2f, r_h / height) * 2;
                tracked.transform.rotation   = Quaternion.Euler(0, -angle, 0);

                OnUnstableRectangleEvent(tracked.transform, copy);
            }

            if (!detected)
            {
                if (last_seen_rect.Equals(RotatedRect.Empty))
                {
                    last_seen_rect = l[0];
                    return;
                }

                current_frame++;
                float delta_pos = (float)Vector2.Distance(new Vector2(l[0].Center.X, l[0].Center.Y), new Vector2(last_seen_rect.Center.X, last_seen_rect.Center.Y));
                float new_pos_h = position_history * 0.75f + delta_pos * 0.25f;
                //   Debug.Log("History: " + Mathf.Abs(new_pos_h - position_history));
                float diff = Mathf.Abs(new_pos_h - position_history);
                position_history = new_pos_h;

                if (current_frame < frames_to_stabilize || diff > 0.1f)
                {
                    return;
                }

                last_seen_rect = l[0];

                int width  = DepthSourceManager.Width();
                int height = DepthSourceManager.Height();

                if (debug)
                {
                    width = height = 512;
                }

                RotatedRect copy  = l[0];
                float       r_w   = copy.Size.Width;
                float       r_h   = copy.Size.Height;
                float       angle = copy.Angle;

                if (r_h > r_w)
                {
                    r_h   = copy.Size.Width;
                    r_w   = copy.Size.Height;
                    angle = angle - 90.0f;
                }

                Vector2 centre = new Vector2(l[0].Center.X / width, l[0].Center.Y / height);
                centre = centre * 2 - new Vector2(1, 1);
                centre = -centre;
                tracked.transform.position   = new Vector3(centre.x, 0, centre.y) + transform.position;
                tracked.transform.localScale = new Vector3(r_w / width, 0.2f, r_h / height) * 2;
                tracked.transform.rotation   = Quaternion.Euler(0, -angle, 0);



                if (OnStableRectangleEvent != null)
                {
                    StartCoroutine(stableRectEvent(tracked.transform, copy));
                }



                detected = true;
            }
        }
        else
        {
            //current_frame = Mathf.Max(0, current_frame - 1);

            //if(current_frame == 0)
            //{
            //    detected = false;
            //    if (OnDisappearEvent != null)
            //        OnDisappearEvent();
            //    tracked.transform.position = Vector3.one * -100000.0f;
            //}
        }
    }
Esempio n. 26
0
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }



        if (Input.GetButtonDown("Fire1"))
        {
            if (updateTerrain == true)
            {
                updateTerrain = false;
            }
            else
            {
                updateTerrain = true;
            }
        }
//
//
//
//            if(ViewMode == DepthViewMode.MultiSourceReader)
//            {
//                ViewMode = DepthViewMode.SeparateSourceReaders;
//            }
//            else
//            {
//                ViewMode = DepthViewMode.MultiSourceReader;
//            }
//        }

        float yVal = Input.GetAxis("Horizontal");
        float xVal = -Input.GetAxis("Vertical");

        //transform.Rotate (xVal, yVal, 0.0f);

        if (updateTerrain == true)
        {
            if (ViewMode == DepthViewMode.SeparateSourceReaders)
            {
                if (ColorSourceManager == null)
                {
                    return;
                }

                _ColorManager = ColorSourceManager.GetComponent <ColorSourceManager>();
                if (_ColorManager == null)
                {
                    return;
                }

                if (DepthSourceManager == null)
                {
                    return;
                }

                _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>();
                if (_DepthManager == null)
                {
                    return;
                }

                gameObject.GetComponent <Renderer>().material.mainTexture = _ColorManager.GetColorTexture();
                RefreshData(_DepthManager.GetData(),
                            _ColorManager.ColorWidth,
                            _ColorManager.ColorHeight);
            }
            else
            {
                if (MultiSourceManager == null)
                {
                    return;
                }

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

                gameObject.GetComponent <Renderer>().material.mainTexture = _MultiManager.GetColorTexture();

                RefreshData(_MultiManager.GetDepthData(),
                            _MultiManager.ColorWidth,
                            _MultiManager.ColorHeight);
            }
        }
        UpdateTransform();
    }
Esempio n. 27
0
    void Update()
    {
        if (_Sensor == null)
        {
            return;
        }

        /*if (Input.GetButtonDown("Fire1"))
         * {
         *
         *  if (ViewMode == DepthViewMode.MultiSourceReader)
         *  {
         *      ViewMode = DepthViewMode.SeparateSourceReaders;
         *  }
         *  else
         *  {
         *      ViewMode = DepthViewMode.MultiSourceReader;
         *  }
         * }
         *
         * float yVal = Input.GetAxis("Horizontal");
         * float xVal = -Input.GetAxis("Vertical");
         *
         * transform.Rotate(
         *  (xVal * Time.deltaTime * _Speed),
         *  (yVal * Time.deltaTime * _Speed),
         *  0,
         *  Space.Self);*/

        if (ViewMode == DepthViewMode.SeparateSourceReaders)
        {
            if (ColorSourceManager == null)
            {
                return;
            }

            _ColorManager = ColorSourceManager.GetComponent <ColorSourceManager>();
            if (_ColorManager == null)
            {
                return;
            }

            if (DepthSourceManager == null)
            {
                return;
            }

            _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>();
            if (_DepthManager == null)
            {
                return;
            }

            gameObject.GetComponent <Renderer>().material.mainTexture = _ColorManager.GetColorTexture();
            RefreshData(_DepthManager.GetData(),    //デプスマネージャーからushortのデプスデータ取ってきてる
                        _ColorManager.ColorWidth,
                        _ColorManager.ColorHeight);
        }
        else
        {
            if (MultiSourceManager == null)
            {
                return;
            }

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

            gameObject.GetComponent <Renderer>().material.mainTexture = _MultiManager.GetColorTexture();

            RefreshData(_MultiManager.GetDepthData(),    //デプスマネージャーからushortのデプスデータ取ってきてる
                        _MultiManager.ColorWidth,
                        _MultiManager.ColorHeight);
        }

        for (int i = 0; i < detectedx.Count; i++)  //複数手判定
        {
            if (hand1x.Count == 0)
            {
                hand1x.Add(detectedx[i]);
                hand1y.Add(detectedy[i]);
            }
            else
            {
                if (Mathf.Abs(detectedx[i] - hand1x[0]) + Mathf.Abs(detectedy[i] - hand1y[0]) < avilabledistance)   //計算量短縮のために二乗を使わないで距離判定
                {
                    hand1x.Add(detectedx[i]);
                    hand1y.Add(detectedy[i]);
                }
                else
                {
                    if (hand2x.Count == 0)
                    {
                        hand2x.Add(detectedx[i]);
                        hand2y.Add(detectedy[i]);
                    }
                    else
                    {
                        if (Mathf.Abs(detectedx[i] - hand2x[0]) + Mathf.Abs(detectedy[i] - hand2y[0]) < avilabledistance)
                        {
                            hand2x.Add(detectedx[i]);
                            hand2y.Add(detectedy[i]);
                        }
                        else
                        {
                            if (hand3x.Count == 0)
                            {
                                hand3x.Add(detectedx[i]);
                                hand3y.Add(detectedy[i]);
                            }
                            else
                            {
                                if (Mathf.Abs(detectedx[i] - hand3x[0]) + Mathf.Abs(detectedy[i] - hand3y[0]) < avilabledistance)
                                {
                                    hand3x.Add(detectedx[i]);
                                    hand3y.Add(detectedy[i]);
                                }
                                else
                                {
                                    if (hand4x.Count == 0)
                                    {
                                        hand4x.Add(detectedx[i]);
                                        hand4y.Add(detectedy[i]);
                                    }
                                    else
                                    {
                                        if (Mathf.Abs(detectedx[i] - hand4x[0]) + Mathf.Abs(detectedy[i] - hand4y[0]) < avilabledistance)
                                        {
                                            hand4x.Add(detectedx[i]);
                                            hand4y.Add(detectedy[i]);
                                        }
                                        else
                                        {
                                            if (hand5x.Count == 0)
                                            {
                                                hand5x.Add(detectedx[i]);
                                                hand5y.Add(detectedy[i]);
                                            }
                                            else
                                            {
                                                if (Mathf.Abs(detectedx[i] - hand5x[0]) + Mathf.Abs(detectedy[i] - hand5y[0]) < avilabledistance)
                                                {
                                                    hand5x.Add(detectedx[i]);
                                                    hand5y.Add(detectedy[i]);
                                                }
                                                else
                                                {
                                                    if (hand6x.Count == 0)
                                                    {
                                                        hand6x.Add(detectedx[i]);
                                                        hand6y.Add(detectedy[i]);
                                                    }
                                                    else
                                                    {
                                                        if (Mathf.Abs(detectedx[i] - hand6x[0]) + Mathf.Abs(detectedy[i] - hand6y[0]) < avilabledistance)
                                                        {
                                                            hand6x.Add(detectedx[i]);
                                                            hand6y.Add(detectedy[i]);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        hand1ave();
        hand2ave();
        hand3ave();
        hand4ave();
        hand5ave();
        hand6ave();

        detectedx.Clear();
        detectedy.Clear();
        hand1x.Clear();
        hand1y.Clear();
        hand2x.Clear();
        hand2y.Clear();
        hand3x.Clear();
        hand3y.Clear();
        hand4x.Clear();
        hand4y.Clear();
        hand5x.Clear();
        hand5y.Clear();
        hand6x.Clear();
        hand6y.Clear();
    }