Beispiel #1
0
    void Update()
    {
        var rawImage = kinectInputManager.GetColorBuffer();

        if (processFullImage)
        {
            // Process full image
            ProcessImage(ref rawImage, COLOR_WIDTH, COLOR_HEIGHT);
        }
        else
        {
            // Process regions of the image
            //TODO: set these as input parameters
            List <RectInt> rois = new List <RectInt>();
            rois.Add(new RectInt(0, 0, 100, 100));
            rois.Add(new RectInt(200, 200, 200, 100));
            rois.Add(new RectInt(500, 500, 250, 250));
            foreach (RectInt roi in rois)
            {
                ProcessImageRegion(ref rawImage, COLOR_WIDTH, COLOR_HEIGHT, roi);
            }
        }

        texture.LoadRawTextureData(rawImage);
        texture.Apply();
    }
Beispiel #2
0
    void Update()
    {
        var rawImage = kinectInputManager.GetColorBuffer();

        texture.LoadRawTextureData(rawImage);
        texture.Apply();
    }
Beispiel #3
0
    void Update()
    {
        foundOrientation = false;

//////// DISPLAY - BEGIN
        var rawImage = kinectInputManager.GetColorBuffer();
//////// DISPLAY - MID

        ulong id = bodyTracker.GetTrackedId(1);

        if (id != 0)
        {
            Vector2 position = bodyTracker.GetPosition(id, JointType.Head);
            if (position != Vector2.zero)
            {
                if ((position.x < COLOR_WIDTH) && (position.y < COLOR_HEIGHT))
                {
                    //TODO: should check if valid bodyTracker3D as well
                    //=> Or have a combined 2D+3D tracker
                    Vector3 pos = bodyTracker3D.GetPosition(id, JointType.Head);

                    RectInt roi = GetROI(position.x, position.y, -pos.z);
//TODO: what size minimum?
                    if ((roi.width <= 10) || (roi.height <= 10))
                    {
                        return;
                    }

//////// DISPLAY - MID
//                    var rawImage = kinectInputManager.GetColorBuffer();
//////// DISPLAY - END

                    if (filterBodyData)
                    {
                        FilterBodyData(rawImage, roi);
                    }

//////// RUNTIME_COLOURS - BEGIN

/*
 *                  // For test purpose (runtime colours setting in Editor)
 *                  minHSV = new Scalar[] {
 *                      new Scalar(leftHSVMin),
 *                      new Scalar(rightHSVMin),
 *                      new Scalar(topHSVMin)
 *                  };
 *
 *                  maxHSV = new Scalar[] {
 *                      new Scalar(leftHSVMax),
 *                      new Scalar(rightHSVMax),
 *                      new Scalar(topHSVMax)
 *                  };
 */
//////// RUNTIME_COLOURS - MID


                    Vector3[] blobs = new Vector3[3];
                    // Blobs are defined by their position (x,y) and size (z).
                    // If for a colour no blob has been found, its size is 0 (z=0).
                    bool detect = DetectColoursInROI(ref rawImage, COLOR_WIDTH, COLOR_HEIGHT, roi, true, 3, minHSV, maxHSV, ref blobs);
                    if (detect)
                    {
                        bool haveLeft  = GetPosition((int)blobs[0].x + roi.x, (int)blobs[0].y + roi.y, blobs[0].z, out Vector3 left);
                        bool haveRight = GetPosition((int)blobs[1].x + roi.x, (int)blobs[1].y + roi.y, blobs[1].z, out Vector3 right);
                        //TODO: Extend process to 3 points
                        //bool haveTop = GetPosition((int)blobs[2].x + roi.x, (int)blobs[2].y + roi.y, blobs[2].z, out Vector3 top);

                        if (haveLeft && haveRight)   // +haveTop
                        //orientation = GetOrientation(left, right, top);
                        {
                            orientation      = GetOrientation(left, right);
                            foundOrientation = true;
                        }
                    }
                }
            }
        }

        if (foundOrientation)
        {
            trackingListener.NotifyChange(orientation);
        }

//////// DISPLAY - BEGIN
        texture.LoadRawTextureData(rawImage);
        texture.Apply();
//////// DISPLAY - MID
    }
    void Update()
    {
        List <RectInt> rois = new List <RectInt>();

        ulong id = bodyTracker.GetTrackedId(1);

        if (id != 0)
        {
            Dictionary <JointType, Vector2> joints;
            if (!trackFullBody)
            {
//TODO: add possibility in Editor to specify joints
                List <JointType> jointTypes = new List <JointType> {
                    JointType.Head,
                    JointType.HandRight,
                    JointType.HandLeft
                };

                joints = new Dictionary <JointType, Vector2>();
                foreach (JointType jointType in jointTypes)
                {
                    joints.Add(jointType, bodyTracker.GetPosition(id, jointType));
                }
            }
            else
            {
                joints = bodyTracker.GetJoints(id);
            }

            foreach (KeyValuePair <JointType, Vector2> joint in joints)
            {
                Vector2 point = joint.Value;

                if (point != Vector2.zero)
                {
                    if ((point.x >= COLOR_WIDTH) || (point.y >= COLOR_HEIGHT))
                    {
                        continue;
                    }

                    int x = (int)point.x - 100;
                    int y = (int)point.y - 100;
                    int w = 200;
                    int h = 200;

                    if (joint.Key == JointType.Head)
                    {
                        x = (int)point.x - 200;
                        y = (int)point.y - 200;
                        w = 400;
                        h = 400;
                    }

                    if (x < 0)
                    {
                        x = 0;
                    }
                    if (y < 0)
                    {
                        y = 0;
                    }
                    if ((x + w) >= COLOR_WIDTH)
                    {
                        w = COLOR_WIDTH - 1 - x;
                    }
                    if ((y + h) >= COLOR_HEIGHT)
                    {
                        h = COLOR_HEIGHT - 1 - y;
                    }
                    rois.Add(new RectInt(x, y, w, h));
                }
            }
        }


        var rawImage = kinectInputManager.GetColorBuffer();

        foreach (RectInt roi in rois)
        {
//TODO: check in library if roi is in image!!!!
            ProcessImageRegion(ref rawImage, COLOR_WIDTH, COLOR_HEIGHT, roi);
        }
//        var rawImage = kinectInputManager.GetBodyIndexBuffer();

        texture.LoadRawTextureData(rawImage);
        texture.Apply();
    }