public Coord[] handLocation(PXCMImage.ImageData data, int size, int width)
        {
            Coord[] locations = new Coord[size];


            IntPtr ptr = data.buffer.planes[0];

            byte[] rgbValues = new byte[size];


            Marshal.Copy(ptr, rgbValues, 0, size);

            int counter = 0;
            int i;

            for (i = 0; i < size; i++)
            {
                if (rgbValues[i] == 0)
                {
                    locations[counter++] = new Coord(i, width);
                }
            }
            //locations[counter] = -1;

            Array.Resize(ref locations, counter - 1);

            return(locations);
        }
Example #2
0
 private void UpdateColorImage(PXCMImage colorFrame)
 {
     if (colorFrame != null)
     {
         PXCMImage.ImageData data = null;
         var ret = colorFrame.AcquireAccess(
             PXCMImage.Access.ACCESS_READ,
             PXCMImage.PixelFormat.PIXEL_FORMAT_RGB24,
             out data);
         if (ret >= pxcmStatus.PXCM_STATUS_NO_ERROR)
         {
             var info   = colorFrame.QueryInfo();
             var length = data.pitches[0] * info.height;
             var buffer = data.ToByteArray(0, length);
             this.ColorImageElement = BitmapSource.Create(
                 info.width,
                 info.height,
                 96,
                 96,
                 PixelFormats.Bgr24,
                 null,
                 buffer,
                 data.pitches[0]);
             colorFrame.ReleaseAccess(data);
         }
     }
 }
        /* Given a full frame, this isolates the pixels that actually
         * contain the hand in question.  It then returns the pixel locations
         * for this hand.
         * */
        public void handLocation(ref Coord[] locations, PXCMImage.ImageData data, int width)
        {
            //Load the depth data from the frame.
            IntPtr ptr = data.buffer.planes[0];

            //Initilize the byte array for the bitmap.
            byte[] rgbValues = new byte[locations.Length];

            //Copy the passed in image data into byte array.
            Marshal.Copy(ptr, rgbValues, 0, locations.Length);


            //Loop through the values indetifying the hand values.
            int counter = 0;
            int i;

            for (i = 0; i < locations.Length; i++)
            {
                if (rgbValues[i] == 0)
                {
                    locations[counter++] = new Coord(i, width);
                }
            }

            //Resize the array to the smaller size.
            if (counter > 1)
            {
                Array.Resize(ref locations, counter - 1);
            }

            return;
        }
Example #4
0
    void RSCapture()
    {
        //----------------------RS---------------------
        /* Make sure PXCMSenseManager Instance is Initialized */
        if (psm == null)
        {
            LogText.text = "PXCMSM Failed";
            return;
        }
        /* Wait until any frame data is available true(aligned) false(unaligned) */
        if (psm.AcquireFrame(true) != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            LogText.text = "Waiting...";
            return;
        }
        /* Retrieve a sample from the camera */
        PXCMCapture.Sample sample = psm.QuerySample();
        if (sample != null)
        {
            LogText.text = "Capturing...";
        }

        //-----UVMap-----//
        PXCMImage.ImageData imageData = new PXCMImage.ImageData();
        sample.depth.AcquireAccess(PXCMImage.Access.ACCESS_READ_WRITE, PXCMImage.PixelFormat.PIXEL_FORMAT_DEPTH, PXCMImage.Option.OPTION_ANY, out imageData);
        bool found = false;

        unsafe
        {
            UInt16 *ptr = (UInt16 *)imageData.planes[0].ToPointer();

            ulong length = (ulong)(sample.depth.info.width * sample.depth.info.height);
            for (ulong i = 0; ((i < length) && !found); i++, ptr++)
            {
                found = (*ptr > 0) && (*ptr < minimumDistanceMm);
            }
            a = ptr[120 * sample.depth.info.width + 320];
            b = ptr[360 * sample.depth.info.width + 320];
            c = ptr[240 * sample.depth.info.width + 160];
            d = ptr[240 * sample.depth.info.width + 480];
            //	indexer = row*width + column;
        }
        if (found)
        {
            Output.text = "Pass";
        }
        else
        {
            Output.text = "Fail";
        }
        //-----EOUVM-----//

        /* Release the frame to process the next frame */
        depthImage = sample.depth;
        psm.ReleaseFrame();
        //---------------------EORS--------------------
    }
Example #5
0
 pxcmStatus newIRFrame(int mid, PXCMCapture.Sample sample)
 {
     if (sample.ir != null && irImageForm != null && !irImageForm.IsDisposed)
     {
         PXCMImage.ImageData data = new PXCMImage.ImageData();
         sample.ir.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, out data);
         irImageForm.Image = data.ToBitmap(0, sample.ir.info.width, sample.ir.info.height);
         sample.ir.ReleaseAccess(data);
     }
     return(pxcmStatus.PXCM_STATUS_NO_ERROR);
 }
Example #6
0
        private unsafe void CopyImageWithStride(int width, int height, int scale, PXCMImage.ImageData data, IntPtr destination)
        {
            int   length = width * scale;
            byte *dest   = (byte *)destination;

            // one memcpy per line
            for (int y = 0; y < height; ++y)
            {
                byte *src = (byte *)data.planes[0] + y * data.pitches[0];
                memcpy(new IntPtr(dest), new IntPtr(src), new UIntPtr((uint)length));
                dest += length;
            }
        }
Example #7
0
        public static WriteableBitmap GetImage(this PXCMImage image)
        {
            PXCMImage.ImageData imageData   = null;
            WriteableBitmap     returnImage = null;
            int width  = 0;
            int height = 0;

            if (image.AcquireAccess(PXCMImage.Access.ACCESS_READ,
                                    PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32,
                                    out imageData).IsSuccessful())
            {
                width       = Convert.ToInt32(imageData.pitches[0] / 4);
                height      = image.info.height;
                returnImage = imageData.ToWritableBitmap(width, height, 96, 96);
                image.ReleaseAccess(imageData);
            }
            return(returnImage);
        }
Example #8
0
        pxcmStatus newHandFrame(PXCMHandModule hand)
        {
            if (hand != null)
            {
                PXCMHandData handData = hand.CreateOutput();
                handData.Update();

                PXCMHandData.IHand     iHandDataLeft = null, iHandDataRight = null;
                PXCMHandData.JointData jointData = null;
                PXCMImage image = null;

                handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_LEFT_HANDS, 0, out iHandDataLeft);
                handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_RIGHT_HANDS, 0, out iHandDataRight);
                if (handForm != null && !handForm.IsDisposed)
                {
                    this.handForm.HandCount = handData.QueryNumberOfHands();
                    if (iHandDataLeft != null)
                    {
                        iHandDataLeft.QuerySegmentationImage(out image);
                        if (image != null)
                        {
                            PXCMImage.ImageData data = new PXCMImage.ImageData();
                            image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, out data);
                            handForm.LeftHand = data.ToBitmap(0, image.info.width, image.info.height);
                            image.ReleaseAccess(data);
                        }
                    }
                    if (iHandDataRight != null)
                    {
                        iHandDataRight.QuerySegmentationImage(out image);
                        if (image != null)
                        {
                            PXCMImage.ImageData data = new PXCMImage.ImageData();
                            image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, out data);
                            handForm.RightHand = data.ToBitmap(0, image.info.width, image.info.height);
                            image.ReleaseAccess(data);
                        }
                    }
                }
                if (iHandDataLeft != null)
                {
                    if (jointData == null)
                    {
                        iHandDataLeft.QueryTrackedJoint(PXCMHandData.JointType.JOINT_INDEX_TIP, out jointData);
                    }
                }
                if (iHandDataRight != null)
                {
                    if (jointData == null)
                    {
                        iHandDataRight.QueryTrackedJoint(PXCMHandData.JointType.JOINT_INDEX_TIP, out jointData);
                    }
                }
                if (jointData != null && canTrack.Checked)
                {
                    Cursor.Position = new System.Drawing.Point(
                        (int)((640.0f - jointData.positionImage.x) * Screen.PrimaryScreen.Bounds.Width / 640.0f),
                        (int)(jointData.positionImage.y * Screen.PrimaryScreen.Bounds.Height / 480.0f));
                    PXCMHandData.GestureData gestureData = null;
                    if (handData.IsGestureFired("two_fingers_pinch_open", out gestureData))
                    {
                        Program.DoMouseClick();
                    }
                    Console.WriteLine("Z Position: " + jointData.positionWorld.z);
                }

                handData.Dispose();
            }
            return(pxcmStatus.PXCM_STATUS_NO_ERROR);
        }
Example #9
0
 public RealSenseEventArgs(PXCMImage.ImageData source, PXCMImage.ImageInfo info)
     : this()
 {
     this.source = source;
     this.info = info;
 }
        private Bitmap ConvertDepthToBitmap(PXCMImage.ImageData depthData, PXCMCapture.Sample sample)
        {
            Bitmap bmp = new Bitmap(sample.depth.info.width, sample.depth.info.height);

            var size = sample.depth.info.width * sample.depth.info.height;

            Int16[] values      = new Int16[size];
            var     depthValues = depthData.ToShortArray(0, values);

            var   minDistance = 500;  // mm
            var   maxDistance = 2000; // mm
            float scale       = 255.0f / (maxDistance - minDistance);

            var dataPoint = new DataPoint
            {
                nearest = new Coordinate {
                    x = -1, y = -1, z = short.MaxValue
                },
                farthest = new Coordinate {
                    x = -1, y = -1, z = short.MinValue
                }
            };
            var i      = 0;
            var sum    = 0.0;
            var width  = sample.depth.info.width;
            var height = sample.depth.info.height;

            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    var distance   = depthValues[i++]; // mm
                    var brightness = 0;

                    if (distance > 0 && distance < dataPoint.nearest.z)
                    {
                        dataPoint.nearest = new Coordinate {
                            x = (double)x / width, y = (double)y / height, z = distance
                        }
                    }
                    ;
                    if (distance > dataPoint.farthest.z)
                    {
                        dataPoint.farthest = new Coordinate {
                            x = (double)x / width, y = (double)y / height, z = distance
                        }
                    }
                    ;
                    sum += distance;

                    if (distance > minDistance && distance < maxDistance)
                    {
                        brightness = 255 - (int)((distance - minDistance) * scale);
                    }
                    System.Drawing.Color color = System.Drawing.Color.FromArgb(brightness, brightness, brightness);
                    bmp.SetPixel(x, y, color);
                }
            }

            if (dataPoint.nearest.z == short.MaxValue)
            {
                dataPoint.nearest = null;
            }
            if (dataPoint.farthest.z == short.MinValue)
            {
                dataPoint.farthest = null;
            }
            dataPoint.averageDepth = sum / size;
            dataPoint.outOfBed     = OutOfBed;
            dataPoint.timeStamp    = DateTime.UtcNow;
            SendDataPoint(dataPoint);

            return(bmp);
        }
Example #11
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     //deregister event handlers
     if(_movementController != null) _movementController.Dispose();
     colorData = null;
     if(colourBitMap != null) colourBitMap.Dispose();
     Environment.Exit(0);
 }