Esempio n. 1
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. 2
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. 3
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);
    }
Esempio n. 4
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. 5
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;
            //}
        }
    }