Пример #1
0
        public ManipulationStates DrawAndMonitorBoundingBox(TrackedItem trackedObject, ushort color, int MaxValue, int MinValue, ushort[] frameData, byte[] depthPixels)
        {
            //check to see if we're at the beginning of a row before backing out 5px
            int BoundBoxStart = trackedObject.Col <= this.ObjectParimeterBuffer ? trackedObject.DepthArrayPointer : trackedObject.DepthArrayPointer - this.ObjectParimeterBuffer;
            int BoundBoxWidth = (trackedObject.Col + trackedObject.Width + (this.ObjectParimeterBuffer * 2)) >= 512 ? trackedObject.Width : trackedObject.Width + (this.ObjectParimeterBuffer * 2);
            int closePixelCount = 0;

            if (trackedObject.TrackedPixels == null)
                trackedObject.TrackedPixels = new List<TrackedPixel>();
                        
            var objectBoundaryCenterIndex = BoundBoxStart + ((trackedObject.Height / 2) * 512)  + (BoundBoxWidth / 2);
            var objectTopBoundaryCenterDepth = frameData[objectBoundaryCenterIndex];
            var objectCenterIndex = BoundBoxStart + (BoundBoxWidth / 2);
            var objectCenterDepth = frameData[objectCenterIndex];

            

            if (!IsCalibrating && trackedObject.TrackedPixels.Count > 0)
            {                
                foreach (TrackedPixel tp in trackedObject.TrackedPixels)
                {
                    var test = frameData[tp.PixelIndexInDepthFrame];

                   
                    if (IsZeroDepth)
                    {
                       

                        if (frameData[tp.PixelIndexInDepthFrame] > 0 && frameData[tp.PixelIndexInDepthFrame] < MaxValue * 4 && tp.OrginalDepthValue > MaxValue * 4)
                        {
                            depthPixels[tp.PixelIndexInDepthFrame] = System.Convert.ToByte(4000 / MapDepthToByte);
                            closePixelCount++;
                        }
                        else if (tp.OrginalDepthValue > MaxValue * 4 && frameData[tp.PixelIndexInDepthFrame] == 0)
                        {
                            depthPixels[tp.PixelIndexInDepthFrame] = System.Convert.ToByte(4000 / MapDepthToByte);
                            closePixelCount++;
                        }
                        else if ((tp.OrginalDepthValue == 0 && frameData[tp.PixelIndexInDepthFrame] > 0) && frameData[tp.PixelIndexInDepthFrame] < MaxValue)
                        {
                            //handle when there is a zero value depth reading that is causing Touched/Released to not be recognized                        
                            if ((frameData[tp.PixelIndexInDepthFrame] > objectTopBoundaryCenterDepth - this.ObjectParimeterBuffer - 50 && frameData[tp.PixelIndexInDepthFrame] < objectTopBoundaryCenterDepth + this.ObjectParimeterBuffer + 50))
                            {
                                depthPixels[tp.PixelIndexInDepthFrame] = System.Convert.ToByte(4000 / MapDepthToByte);
                                closePixelCount++;
                            }
                        }
                        else
                        {
                            depthPixels[tp.PixelIndexInDepthFrame] = System.Convert.ToByte(color / MapDepthToByte);
                        }
                    }
                    else
                    {

                        if (tp.OrginalDepthValue > MaxValue &&
                            frameData[tp.PixelIndexInDepthFrame] < MaxValue && frameData[tp.PixelIndexInDepthFrame] >= MinValue)
                        {
                            depthPixels[tp.PixelIndexInDepthFrame] = System.Convert.ToByte(4000 / MapDepthToByte);
                            closePixelCount++;
                        }
                        else if (tp.OrginalDepthValue < MaxValue && frameData[tp.PixelIndexInDepthFrame] + 10 < tp.OrginalDepthValue && frameData[tp.PixelIndexInDepthFrame] > MinValue)
                        {
                            depthPixels[tp.PixelIndexInDepthFrame] = System.Convert.ToByte(4000 / MapDepthToByte);
                            closePixelCount++;
                        }
                        else if (tp.OrginalDepthValue == 0 && frameData[tp.PixelIndexInDepthFrame] > 0
                        && (frameData[tp.PixelIndexInDepthFrame] < MaxValue && frameData[tp.PixelIndexInDepthFrame] >= MinValue))
                        {
                            //handle when there is a zero value depth reading that is causing Touched/Released to not be recognized                        
                            if ((frameData[tp.PixelIndexInDepthFrame] > objectTopBoundaryCenterDepth - this.ObjectParimeterBuffer - 50 && frameData[tp.PixelIndexInDepthFrame] < objectTopBoundaryCenterDepth + this.ObjectParimeterBuffer + 50))
                            {
                                depthPixels[tp.PixelIndexInDepthFrame] = System.Convert.ToByte(4000 / MapDepthToByte);
                                closePixelCount++;
                            }
                        }
                        else
                        {
                            depthPixels[tp.PixelIndexInDepthFrame] = System.Convert.ToByte(color / MapDepthToByte);
                        }
                    }
                }

            }
            else
            {
                if (IsZeroDepth)
                {
                    //Check to see if the top is being interacted with
                    for (int i = BoundBoxStart; i < BoundBoxStart + BoundBoxWidth; i++)
                    {
                        depthPixels[i] = System.Convert.ToByte(color / MapDepthToByte);
                        trackedObject.TrackedPixels.Add(new TrackedPixel() { PixelIndexInDepthFrame = i, OrginalDepthValue = frameData[i] });

                        if (frameData[i] > 0 && frameData[i] <= MaxValue * 4)
                        {
                            depthPixels[i] = System.Convert.ToByte(4000 / MapDepthToByte);
                            closePixelCount++; //reached in close to pixel in object
                        }
                    }
                }
                else
                {
                    //Check to see if the top is being interacted with
                    for (int i = BoundBoxStart; i < BoundBoxStart + BoundBoxWidth; i++)
                    {
                        depthPixels[i] = System.Convert.ToByte(color / MapDepthToByte);
                        trackedObject.TrackedPixels.Add(new TrackedPixel() { PixelIndexInDepthFrame = i, OrginalDepthValue = frameData[i] });

                        if (frameData[i] <= MaxValue && frameData[i] >= MinValue)
                        {
                            depthPixels[i] = System.Convert.ToByte(4000 / MapDepthToByte);
                            closePixelCount++; //reached in close to pixel in object
                        }
                    }
                }

                var adjustFactorForCameraAngle = 0;// (MaxValue - MinValue) / (trackedObject.Height / 4);
                //Check to see if the sides of the object have been interacted with
                for (int i = 1; i < trackedObject.Height / 2; i++)
                {
                    int tmp = frameData[BoundBoxStart + (i * 512)];

                    if (trackedObject.Col > 5) //Don't draw or monitor the left edge if we're past the edge of the feed
                    {
                        trackedObject.TrackedPixels.Add(new TrackedPixel() { PixelIndexInDepthFrame = BoundBoxStart + (i * 512), OrginalDepthValue = frameData[BoundBoxStart + (i * 512)] });

                        depthPixels[BoundBoxStart + (i * 512)] = System.Convert.ToByte(color / MapDepthToByte);

                        if (IsZeroDepth)
                        {
                            if (frameData[BoundBoxStart + (i * 512)] > 0 && frameData[BoundBoxStart + (i * 512)] <= MaxValue - (adjustFactorForCameraAngle * i) * 4)
                            {
                                depthPixels[BoundBoxStart + (i * 512)] = System.Convert.ToByte(4000 / MapDepthToByte);
                                closePixelCount++;
                            }
                        }
                        else
                        {
                            if (frameData[BoundBoxStart + (i * 512)] <= MaxValue - (adjustFactorForCameraAngle * i) && frameData[BoundBoxStart + (i * 512)] >= MinValue)
                            {
                                depthPixels[BoundBoxStart + (i * 512)] = System.Convert.ToByte(4000 / MapDepthToByte);
                                closePixelCount++;
                            }
                        }
                    }

                    if ((trackedObject.Col + trackedObject.Width) < 500) //Don't draw or monitors the objects right edge if we're past the feeds edge
                    {
                        depthPixels[BoundBoxStart + (i * 512) + BoundBoxWidth] = System.Convert.ToByte(color / MapDepthToByte);
                        trackedObject.TrackedPixels.Add(new TrackedPixel() { PixelIndexInDepthFrame = BoundBoxStart + (i * 512) + BoundBoxWidth, OrginalDepthValue = frameData[BoundBoxStart + (i * 512) + BoundBoxWidth] });

                        if (IsZeroDepth)
                        {
                            if (frameData[BoundBoxStart + (i * 512) + BoundBoxWidth] > 0 && frameData[BoundBoxStart + (i * 512) + BoundBoxWidth] <= MaxValue - (adjustFactorForCameraAngle * i) * 4)
                            {
                                depthPixels[BoundBoxStart + (i * 512) + BoundBoxWidth] = System.Convert.ToByte(4000 / MapDepthToByte);
                                closePixelCount++;
                            }
                        }
                        else
                        {
                            if (frameData[BoundBoxStart + (i * 512) + BoundBoxWidth] <= MaxValue - (adjustFactorForCameraAngle * i) && frameData[BoundBoxStart + (i * 512) + BoundBoxWidth] >= MinValue)
                            {
                                depthPixels[BoundBoxStart + (i * 512) + BoundBoxWidth] = System.Convert.ToByte(4000 / MapDepthToByte);
                                closePixelCount++;
                            }
                        }
                    }
                }

            }
            if (IsCalibrating)
            {
                //Sometimes we can have pixels that get into our activte detection range because of sensor noise or object angle.
                //here we try to learn about that noise so when we actuatly try to detect a touch we have a much more accurate theshold
                if (trackedObject.DS.NosiePixelCount == 0)
                    trackedObject.DS.NosiePixelCount = 0;//closePixelCount;
                else
                {
                    trackedObject.DS.NosiePixelCount = 0;// closePixelCount + trackedObject.DS.NosiePixelCount / 2;
                }
                return ManipulationStates.NoTrack;
            }

            int w = (trackedObject.DepthArrayPointer + (512 * 10));
            int currentIndex = (trackedObject.DepthArrayPointer + (512 * 10));
            int numberOfPixelsPerObject = (trackedObject.Height / 4) * trackedObject.Width;
            int existReadCnt = 0;
            int notExistsReadCnt = 0;

          

            //Scan the object space looking for any signs the object is still there...
            for (int Y = 0; Y < trackedObject.Height / 4; Y++)
            {
                for (int X = 0; X < trackedObject.Width; X++)
                {
                    ushort depth = frameData[currentIndex + X];

                   

                    if (IsZeroDepth)
                    {
                        if (depth == 0)
                        {
                            depthPixels[currentIndex + X] = System.Convert.ToByte(4000 / MapDepthToByte);
                            existReadCnt++;
                        }
                        else
                            notExistsReadCnt++;
                    }
                    else
                    {

                        if (depth > 0 && depth <= MaxValue)
                        {
                            depthPixels[currentIndex + X] = System.Convert.ToByte(4000 / MapDepthToByte);
                            existReadCnt++;
                        }
                        //Removed - Replaced to handle when object is on the edge which causes many zero value readings
                        else if ((depth == 0 && objectCenterDepth == 0) && depth <= MaxValue)
                        {
                            depthPixels[currentIndex + X] = System.Convert.ToByte(4000 / MapDepthToByte);
                            existReadCnt++;
                        }
                        else
                        {
                            notExistsReadCnt++;
                        }
                    }

                    
                }
                currentIndex = w + (512 * Y);                
            }

            float res = (float)existReadCnt / (float)numberOfPixelsPerObject;
            var DeviceIsPresent = true;
            if (res > .10)
            {

            }
            else
            {
                DeviceIsPresent = false;
            }

          
            //Try to confirm action by evaluating how many times we've seen this state
            if (IsZeroDepth)
            {
                if (closePixelCount > trackedObject.DS.NosiePixelCount + 5)
                {
                    trackedObject.NoTouchSampleCount = 0;
                    trackedObject.TouchSampleCount++;
                }
                else
                {
                    trackedObject.NoTouchSampleCount++;
                    trackedObject.TouchSampleCount = 0;
                }
            }
            else
            {
                if (closePixelCount > trackedObject.DS.NosiePixelCount + 5)
                {
                    trackedObject.NoTouchSampleCount = 0;
                    trackedObject.TouchSampleCount++;
                }
                else
                {
                    trackedObject.NoTouchSampleCount++;
                    trackedObject.TouchSampleCount = 0;
                }
            }

            if (closePixelCount > trackedObject.DS.NosiePixelCount + MissingDataTolerance && !IsCalibrating && trackedObject.TouchSampleCount > 10)
            {
                //reset the state
                trackedObject.TouchSampleCount = 0;

                //Find out if they are putting the camera back in place
                if (DeviceIsPresent && !trackedObject.DS.DeviceRemoved && !trackedObject.DS.DeviceReplaced && !trackedObject.DS.Touched)
                {
                    trackedObject.DS.Touched = true;
                    Debug.WriteLine(trackedObject.ObjectID + " " + ManipulationStates.Touched);
                    return ManipulationStates.Touched;
                }
                else if (DeviceIsPresent && trackedObject.DS.DeviceRemoved)
                {
                    trackedObject.DS.DeviceRemoved = false;
                    trackedObject.DS.DeviceReplaced = true;
                    Debug.WriteLine(trackedObject.ObjectID + " " + ManipulationStates.Replaced);
                    return ManipulationStates.Replaced;
                }
            }
            else if (trackedObject.NoTouchSampleCount > 10)
            {
                trackedObject.NoTouchSampleCount = 0;
                //Find out if they are putting the camera back in place
                if (DeviceIsPresent && trackedObject.DS.Touched)
                {
                    trackedObject.DS.Touched = false;
                    Debug.WriteLine(trackedObject.ObjectID + " " + ManipulationStates.Released);
                    return ManipulationStates.Released;
                }
                else if (!DeviceIsPresent && !trackedObject.DS.DeviceRemoved)
                {
                    trackedObject.DS.DeviceRemoved = true;
                    Debug.WriteLine(trackedObject.ObjectID + " " + ManipulationStates.Removed);
                    return ManipulationStates.Removed;
                }
                else if (DeviceIsPresent && trackedObject.DS.DeviceReplaced)
                {
                    trackedObject.DS.Touched = false;
                    trackedObject.DS.DeviceReplaced = false;
                    return ManipulationStates.Released;
                }
            }

            return ManipulationStates.NoTrack;
        }
Пример #2
0
 private void OnItemInteraction(TrackedItem item, ManipulationStates st)
 {
     var handler = this.ItemInteraction;
     if (handler != null)
     {
         var kioskEvent = new KioskStateEventArgs();
         kioskEvent.ItemSelected = item.ObjectID;
         kioskEvent.ItemState = st;
         kioskEvent.TrackingID = this.CorrelationPlayerId;
         handler(this, kioskEvent);
     }
 }
Пример #3
0
        private void UpdateTrackedObjectCollection(TrackedItem potentialTarget)
        {
            var existingTarget = (from targets in objects
                                  where ((targets.Col - 5) <= potentialTarget.Col && potentialTarget.Col < (targets.Col + targets.Width)) //DEALING WITH OVER LAP issues below
                                      && (potentialTarget.Width < targets.Width + 5 && potentialTarget.Width > targets.Width - 5) || ((potentialTarget.Col + potentialTarget.Width >= targets.Col) && (potentialTarget.Col + potentialTarget.Width) <= (targets.Col + targets.Width))
                                  select targets).FirstOrDefault();


            if (existingTarget == null)
            {
                potentialTarget.Row = potentialTarget.DepthArrayPointer / 512;
                potentialTarget.DS = new ItemState();

                potentialTarget.ObjectID = "Item" + (objects.Count + 1).ToString();
                objects.Add(potentialTarget);

                // notify any bound elements that the text has changed
                OnPropertyChanged("ObjectCount");
            }
            else
            {
                existingTarget.Col = potentialTarget.Col;
                existingTarget.Width = potentialTarget.Width;
                existingTarget.DepthArrayPointer = potentialTarget.DepthArrayPointer;
                existingTarget.Row = potentialTarget.DepthArrayPointer / 512;
            }
        }
Пример #4
0
        public void ProcessDepthFrameData(ushort[] frameData, uint depthFrameDataSize, ushort minDepth, ushort maxDepth)
        {            
            int x = 512 * (int)SamplingRow;
            int column = StartColSamplingIndex;
            int startSampleColIndex = x + StartColSamplingIndex;
            int endSampleColIndex = x + EndColSamplingIndex;

            //These are being used to draw vertical lines on the screen for targeting purposes
            int startColDisplayIndex = StartColSamplingIndex;
            int endColDisplayIndex = EndColSamplingIndex;
            ushort minDepthTolerance = (ushort)(ObjectDetectionDepthThreshold - ObjectDepthTolerance < 0 ? 0 : ObjectDetectionDepthThreshold - ObjectDepthTolerance);                       

            //TopView variables
            var startDepthSampleIndexTopView = (int)((ObjectDetectionDepthThreshold - ObjectDepthTolerance) / _millimetersPerRow) * _bytesPerRowTopView;
            var endDepthSampleIndexTopView = (int)((ObjectDetectionDepthThreshold + ObjectDepthTolerance) / _millimetersPerRow) * _bytesPerRowTopView;
            var startDepthLineIndexTopView = (int)(ObjectDetectionDepthThreshold / _millimetersPerRow) * _bytesPerRowTopView;
            var endDepthLineIndexTopView = (int)(ObjectDetectionDepthThreshold / _millimetersPerRow) * _bytesPerRowTopView + _bytesPerRowTopView;
            var startColDisplayIndexTopView = StartColSamplingIndex;
            var endColDisplayIndexTopView = EndColSamplingIndex;

            if (IsCalibrating)
                objects.Clear();

            if (IsWindowVisible)
            {
                // convert depth to a visual representation
                for (int i = 0; i < (int)(depthFrameDataSize / DepthFrameDescription.BytesPerPixel); ++i)
                {

                    #region TopView draw out Monitoring Area
                    int j = i * _topViewBitsPerPixelConversionValue;

                    _topViewDepthPixels[j] = 0;
                    _topViewDepthPixels[j + 1] = 0;
                    _topViewDepthPixels[j + 2] = 0;

                    //depth Threshold line
                    if (j >= startDepthLineIndexTopView && j <= endDepthLineIndexTopView)
                    {
                        _topViewDepthPixels[j] = 255;
                        _topViewDepthPixels[j + 1] = 128;
                        _topViewDepthPixels[j + 2] = 0;

                    }
                    else if (j >= startDepthSampleIndexTopView && j <= (startDepthSampleIndexTopView + _bytesPerRowTopView))
                    {
                        ////Depth Thresold - Start Tolerance Line                            
                        _topViewDepthPixels[j] = 0;
                        _topViewDepthPixels[j + 1] = 0;
                        _topViewDepthPixels[j + 2] = 255;
                    }
                    else if (j >= (endDepthSampleIndexTopView - _bytesPerRowTopView) && j <= endDepthSampleIndexTopView)
                    {
                        ////Depth Thresold - End Tolerance Line                            
                        _topViewDepthPixels[j] = 0;
                        _topViewDepthPixels[j + 1] = 0;
                        _topViewDepthPixels[j + 2] = 255;
                    }                        

                    //Columns lines
                    if ((j / _topViewBitsPerPixelConversionValue) == startColDisplayIndexTopView) //left line
                    {
                        _topViewDepthPixels[j] = 255;
                        _topViewDepthPixels[j + 1] = 0;
                        _topViewDepthPixels[j + 2] = 0;

                        startColDisplayIndexTopView += 512;
                    }
                    else if ((j / _topViewBitsPerPixelConversionValue) == endColDisplayIndexTopView) //right line
                    {
                        _topViewDepthPixels[j] = 255;
                        _topViewDepthPixels[j + 1] = 0;
                        _topViewDepthPixels[j + 2] = 0;

                        endColDisplayIndexTopView += 512;
                    }
                    #endregion TopView draw out Monitoring Area

                    // Get the depth for this pixel
                    ushort depth = frameData[i];

                    if (startSampleColIndex <= i && i <= endSampleColIndex && IsCalibrating)
                    {
                        column++;
                        startSampleColIndex++;
                        if (depth <= ObjectDetectionDepthThreshold && depth >= minDepthTolerance)
                        {
                            var temp = GetTargetWidth(i, endSampleColIndex, MissingDataTolerance, ObjectDetectionDepthThreshold, minDepthTolerance, frameData);

                            if (temp > ObjectSizeThreshold)
                            {
                                var NewObject = new TrackedItem() { DepthArrayPointer = i, Width = temp, Col = column, Row = SamplingRow };

                                //TopView use this Depth value which represents the actual top left depth of the object(FindTopOfObject will change this index to be the top left of the buffer boundary)
                                var objectActualTopLeftDepthPointer = NewObject.DepthArrayPointer;                                

                             

                                NewObject.DepthArrayPointer = FindTopOfObject(NewObject.DepthArrayPointer, NewObject.Width, ref NewObject.Height, MissingDataTolerance, ObjectDetectionDepthThreshold, minDepthTolerance, frameData);

                                UpdateTrackedObjectCollection(NewObject);


                                ////Top View - Draw points representing the object buffer
                                ////Yellow box represents the Buffer boundaries around the object
                                ////Green line represents the front of the Object being detected                                
                                decimal objectTopLeftDepthValue = frameData[objectActualTopLeftDepthPointer];
                                int topViewBytlesPerPixelOverDepthView = 2; // was 3 for PixelFormats.Bgr32 in cnt + 3

                                if (objectTopLeftDepthValue <= ObjectDetectionDepthThreshold && objectTopLeftDepthValue >= minDepthTolerance)
                                {
                                    //Draw the line representing the object...                                
                                    decimal lineValuePercentOfOverallDepth = Math.Round((objectTopLeftDepthValue / 4000m), 2);
                                    var depthRowLocation = (int)(lineValuePercentOfOverallDepth * 424);
                                    var objectTopLeftIndex = (depthRowLocation * _bytesPerRowTopView) + (NewObject.Col * _topViewBitsPerPixelConversionValue);
                                    var objectBufferTopLeftIndex = (depthRowLocation * _bytesPerRowTopView) + ((ObjectParimeterBuffer * _topViewBitsPerPixelConversionValue) + NewObject.Col * _topViewBitsPerPixelConversionValue);

                                    ////object top line
                                    for (int cnt = 0; cnt < (NewObject.Width * _topViewBitsPerPixelConversionValue); cnt += _topViewBitsPerPixelConversionValue) //width of object
                                    {
                                        var bufferOffset = (ObjectParimeterBuffer * _topViewBitsPerPixelConversionValue) / 2;

                                        if (objectTopLeftIndex > 0 && objectTopLeftIndex + bufferOffset + cnt + topViewBytlesPerPixelOverDepthView < _maxTopViewDepthIndex)
                                        {
                                            //green
                                            _topViewDepthPixels[objectTopLeftIndex + bufferOffset + cnt] = 0;
                                            _topViewDepthPixels[objectTopLeftIndex + bufferOffset + cnt + 1] = 255;
                                            _topViewDepthPixels[objectTopLeftIndex + bufferOffset + cnt + 2] = 0;
                                        }
                                    }

                                    ////object buffer box
                                    for (int cnt = 0; cnt < (NewObject.Width * _topViewBitsPerPixelConversionValue) + (ObjectParimeterBuffer * _topViewBitsPerPixelConversionValue); cnt += _topViewBitsPerPixelConversionValue) //width of object + Object buffer
                                    {
                                        //object buffer boundaries                                                                                                              
                                        var objectTopLeftFrontBufferIndex = objectTopLeftIndex - (InteractionFrontBuffer * _bytesPerRowTopView) / 10;

                                        if (objectTopLeftFrontBufferIndex > 0 && objectTopLeftFrontBufferIndex + cnt + topViewBytlesPerPixelOverDepthView < _maxTopViewDepthIndex)
                                        {
                                            //Yellow
                                            _topViewDepthPixels[objectTopLeftFrontBufferIndex + cnt] = 0;
                                            _topViewDepthPixels[objectTopLeftFrontBufferIndex + cnt + 1] = 255;
                                            _topViewDepthPixels[objectTopLeftFrontBufferIndex + cnt + 2] = 255;
                                        }

                                        var objectTopLeftBackBufferIndex = objectTopLeftIndex + (InteractionBackBuffer * _bytesPerRowTopView) / 10;

                                        if (objectTopLeftBackBufferIndex > 0 && objectTopLeftBackBufferIndex + cnt + topViewBytlesPerPixelOverDepthView < _maxTopViewDepthIndex)
                                        {
                                            //Yellow
                                            _topViewDepthPixels[objectTopLeftBackBufferIndex + cnt] = 0;
                                            _topViewDepthPixels[objectTopLeftBackBufferIndex + cnt + 1] = 255;
                                            _topViewDepthPixels[objectTopLeftBackBufferIndex + cnt + 2] = 255;
                                        }

                                        //////side lines of object buffer
                                        if (cnt == 0 || cnt == ((NewObject.Width * _topViewBitsPerPixelConversionValue) + (ObjectParimeterBuffer * _topViewBitsPerPixelConversionValue) - _topViewBitsPerPixelConversionValue))
                                        {
                                            var sidePixelIndex = objectTopLeftFrontBufferIndex + _bytesPerRowTopView;
                                            do
                                            {
                                                if (sidePixelIndex > 0 && sidePixelIndex + cnt + topViewBytlesPerPixelOverDepthView < _maxTopViewDepthIndex)
                                                {
                                                    //Yellow
                                                    _topViewDepthPixels[sidePixelIndex + cnt] = 0;
                                                    _topViewDepthPixels[sidePixelIndex + cnt + 1] = 255;
                                                    _topViewDepthPixels[sidePixelIndex + cnt + 2] = 255;
                                                }

                                                sidePixelIndex = sidePixelIndex + _bytesPerRowTopView;
                                            } while (sidePixelIndex <= objectTopLeftBackBufferIndex);
                                        }
                                    }
                                }                                
                                else
                                {
                                    var lineValueDepthOutsideThreshold = depth;
                                    decimal lineValueDepthPercentOfOverallDepthOutsideThreshold = Math.Round((lineValueDepthOutsideThreshold / 4000m), 2);
                                    var depthValueRowLocationOutsideThreshold = (int)(lineValueDepthPercentOfOverallDepthOutsideThreshold * 424);
                                    var depthValueColumnOutsideThreshold = i % 512;
                                    var depthValueTopLeftIndexOutsideThreshold = (depthValueRowLocationOutsideThreshold * _bytesPerRowTopView) + (depthValueColumnOutsideThreshold * _topViewBitsPerPixelConversionValue);

                                    if (depthValueTopLeftIndexOutsideThreshold > 0 && depthValueTopLeftIndexOutsideThreshold + _topViewBitsPerPixelConversionValue < _maxTopViewDepthIndex)
                                    {
                                        _topViewDepthPixels[depthValueTopLeftIndexOutsideThreshold] = 255;
                                        _topViewDepthPixels[depthValueTopLeftIndexOutsideThreshold + 1] = 255;
                                        _topViewDepthPixels[depthValueTopLeftIndexOutsideThreshold + 2] = 255;
                                    }
                                }

                                //Jump ahead to the end of the detected object
                                column += temp;
                                i += temp;
                            }

                            _depthPixels[i] = (byte)((4000 / MapDepthToByte)); //turn it white


                            //TopView
                            var lineValueDepth = depth;
                            decimal lineValueDepthPercentOfOverallDepth = Math.Round((lineValueDepth / 4000m), 2);
                            var depthValueRowLocation = (int)(lineValueDepthPercentOfOverallDepth * 424);
                            var depthValueColumn = i % 512;
                            var depthValueTopLeftIndex = (depthValueRowLocation * _bytesPerRowTopView) + (depthValueColumn * _topViewBitsPerPixelConversionValue);

                            if (depthValueTopLeftIndex > 0 && depthValueTopLeftIndex + _topViewBitsPerPixelConversionValue < _maxTopViewDepthIndex)
                            {
                                _topViewDepthPixels[depthValueTopLeftIndex] = 255;
                                _topViewDepthPixels[depthValueTopLeftIndex + 1] = 255;
                                _topViewDepthPixels[depthValueTopLeftIndex + 2] = 255;
                            }
                        }
                        else
                        {
                            _depthPixels[i] = (byte)(depth >= minDepth && depth <= maxDepth ? (depth / MapDepthToByte) : 0); //convert depth to gray scale value

                            //TopView
                            var lineValueDepth = depth;
                            decimal lineValueDepthPercentOfOverallDepth = Math.Round((lineValueDepth / 4000m), 2);
                            var depthValueRowLocation = (int)(lineValueDepthPercentOfOverallDepth * 424);
                            var depthValueColumn = i % 512;
                            var depthValueTopLeftIndex = (depthValueRowLocation * _bytesPerRowTopView) + (depthValueColumn * _topViewBitsPerPixelConversionValue);
                            if (depthValueTopLeftIndex > 0 && depthValueTopLeftIndex + _topViewBitsPerPixelConversionValue < _maxTopViewDepthIndex)
                            {
                                _topViewDepthPixels[depthValueTopLeftIndex] = 128;
                                _topViewDepthPixels[depthValueTopLeftIndex + 1] = 128;
                                _topViewDepthPixels[depthValueTopLeftIndex + 2] = 128;
                            }

                        }                        
                    }
                    else if (i == startColDisplayIndex) //left line
                    {
                        _depthPixels[i] = (byte)((4000 / MapDepthToByte));
                        //Move pointer to next row
                        startColDisplayIndex += 512;
                    }
                    else if (i == endColDisplayIndex) //right line
                    {
                        _depthPixels[i] = (byte)((4000 / MapDepthToByte));
                        //Move pointer to next row
                        endColDisplayIndex += 512;
                    }
                    else
                    {                        
                        // To convert to a byte, we're mapping the depth value to the byte range.
                        // Values outside the reliable depth range are mapped to 0 (black).

                        //int defaultColor = 0;
                        //if(depth >= minDepth && depth <= maxDepth)
                        //    defaultColor = (depth / MapDepthToByte);


                        //_depthPixels[i] = (byte)defaultColor; //(byte)(depth >= minDepth && depth <= maxDepth ? defaultColor : 0); //middle line                    
                        //if (defaultColor > maxDefaultColor)
                        //    maxDefaultColor = defaultColor;


                        // To convert to a byte, we're mapping the depth value to the byte range.
                        // Values outside the reliable depth range are mapped to 0 (black).                    
                        _depthPixels[i] = (byte)(depth >= minDepth && depth <= maxDepth ? (depth / MapDepthToByte) : 0); //middle line
                    }
                }
            }

            foreach (TrackedItem trackedObj in objects)
            {

                var st = DrawAndMonitorBoundingBox(
                        trackedObj,
                        (byte)(4000 / MapDepthToByte),
                        ObjectDetectionDepthThreshold + InteractionFrontBuffer,
                        ObjectDetectionDepthThreshold - InteractionBackBuffer,
                        frameData,
                        _depthPixels);

                if (st != ManipulationStates.NoTrack)
                {
                 
                    OnItemInteraction(trackedObj, st);

                    if (!IsCalibrating)
                        _interactions.Insert(0, trackedObj.ObjectID + " " + st.ToString());
                }
                else
                {
                    OnItemInteraction(trackedObj, st);
                }
            }

            RenderDepthPixels();
        }
Пример #5
0
        public bool IsTargetInPlace(TrackedItem trackedObject, int Tolerance, int MaxValue, int MinValue, ushort[] frameData, byte[] depthPixels)
        {
            int currentIndex = trackedObject.DepthArrayPointer;
            int existReadCnt = 0;
            int notExistsReadCnt = 0;

            //Scan the object space looking for any signs the object is still there...
            for (int Y = 0; Y < trackedObject.Height / 2; Y++)
            {
                for (int X = 0; X < trackedObject.Width; X++)
                {
                    ushort depth = frameData[currentIndex + X];
                   
                    if (depth <= MaxValue)
                    {
                        existReadCnt++;
                    }
                    else
                    {
                        notExistsReadCnt++;
                    }

                }
                currentIndex = trackedObject.DepthArrayPointer + (512 * Y);

            }

            if (existReadCnt > 10)
                return true;
            else
                return false;

        }