Ejemplo n.º 1
0
        private void DisplayPicture(PXCMImage depth, PXCMGesture gesture)
        {
            PXCMImage image   = depth;
            bool      dispose = false;

            if (form.GetLabelmapState())
            {
                if (gesture.QueryBlobImage(PXCMGesture.Blob.Label.LABEL_SCENE, 0, out image) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    return;
                }
                dispose = true;
            }

            PXCMImage.ImageData data;
            if (image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.ColorFormat.COLOR_FORMAT_RGB32, out data) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                PXCMImage.ImageInfo imageInfo = image.imageInfo;
                form.DisplayBitmap(data.ToBitmap(imageInfo.width, imageInfo.height));
                image.ReleaseAccess(ref data);
            }

            if (dispose)
            {
                image.Dispose();
            }
        }
Ejemplo n.º 2
0
        public CaptureHand(CaptureForm form) : base()
        {
            pp = new UtilMPipeline();
            pp.EnableGesture();
            pp.EnableImage(PXCMImage.ColorFormat.COLOR_FORMAT_DEPTH);



            if (pp.Init())
            {
                pp.QueryCapture().SetFilter(PXCMCapture.Device.Property.PROPERTY_DEPTH_SMOOTHING, 100);
                do
                {
                    if (!pp.AcquireFrame(true))
                    {
                        MessageBox.Show("Failed to aquire a frame.", "Kwi-S", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        break;
                    }

                    gesture = pp.QueryGesture();


                    gesture.QueryBlobData(PXCMGesture.Blob.Label.LABEL_SCENE, 0, out bdata);

                    gesture.QueryBlobImage(PXCMGesture.Blob.Label.LABEL_SCENE, 0, out bimage);



                    bimage.AcquireAccess(PXCMImage.Access.ACCESS_READ, out data);
                    info = bimage.imageInfo;


                    color = (int)bdata.labelLeftHand;


                    form.setTextBox(color.ToString());


                    pp.ReleaseFrame();
                } while (color == -1);

                Coord[] locations = handLocation(data, (int)(info.width * info.height), (int)info.width);
                bitmap = createBitmap(locations, (int)info.width, (int)info.height);
                form.setImage(bitmap);
                form.bitmap = bitmap;
            }
        }
Ejemplo n.º 3
0
        public CaptureHand(CaptureForm form)
            : base()
        {
            pp = new UtilMPipeline();
            pp.EnableGesture();
            pp.EnableImage(PXCMImage.ColorFormat.COLOR_FORMAT_DEPTH);

            if (pp.Init())
            {

                pp.QueryCapture().SetFilter(PXCMCapture.Device.Property.PROPERTY_DEPTH_SMOOTHING, 100);
                do
                {
                    if (!pp.AcquireFrame(true))
                    {
                        MessageBox.Show("Failed to aquire a frame.", "Kwi-S", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        break;
                    }

                    gesture =  pp.QueryGesture();

                    gesture.QueryBlobData(PXCMGesture.Blob.Label.LABEL_SCENE, 0, out bdata);

                    gesture.QueryBlobImage(PXCMGesture.Blob.Label.LABEL_SCENE, 0, out bimage);

                    bimage.AcquireAccess(PXCMImage.Access.ACCESS_READ,out  data);
                    info = bimage.imageInfo;

                    color =(int) bdata.labelLeftHand;

                    form.setTextBox(color.ToString());

                    pp.ReleaseFrame();

                } while (color == -1);

                Coord[] locations = handLocation(data, (int)(info.width * info.height),(int) info.width);
                bitmap = createBitmap(locations, (int)info.width, (int)info.height);
                form.setImage(bitmap);
                form.bitmap = bitmap;

            }
        }
        private void DisplayPicture(PXCMImage depth, PXCMGesture gesture)
        {
            PXCMImage image = depth;
            bool dispose = false;
            if (form.GetLabelmapState())
            {
                if (gesture.QueryBlobImage(PXCMGesture.Blob.Label.LABEL_SCENE,0,out image)<pxcmStatus.PXCM_STATUS_NO_ERROR) return;
                dispose = true;
            }

            PXCMImage.ImageData data;
            if (image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.ColorFormat.COLOR_FORMAT_RGB32, out data) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                form.DisplayBitmap(data.ToBitmap(image.info.width,image.info.height));
                image.ReleaseAccess(ref data);
            }

            if (dispose) image.Dispose();
        }
Ejemplo n.º 5
0
        public GesturePipeline(Form1 form)
            : base()
        {
            //------------------------------
            // Creates datastructures for
            // the PCSDK
            //------------------------------
            UtilMPipeline pp;         //The pipeline

            PXCMGesture.Blob bdata;   //The intrepred blobs
            PXCMImage        bimage;  //The frame from the camera

            PXCMImage.ImageData data; //The data contained in the frame.
            PXCMImage.ImageInfo info; //Metadata about the frame.
            int color;                //The "color" for the hand in question.

            //------------------------------


            //------------------------------
            // Initilize the datastructures
            // defined above.
            //------------------------------
            Coord[] locations;
            pp = new UtilMPipeline();
            pp.EnableGesture();
            pp.EnableImage(PXCMImage.ColorFormat.COLOR_FORMAT_DEPTH);
            //-----------------------------

            //initilize the pointer for the WMC window.
            IntPtr handle = GetDesktopWindow();


            //----------------------------------
            // Create and initilize the bitmaps
            // that the frames will be comapred
            // against.
            //---------------------------------
            Bitmap pause       = convertBitmap(KwisStandalone.Properties.Resources.STOP);
            Bitmap fastForward = convertBitmap(KwisStandalone.Properties.Resources.FAST_FORWARD);
            Bitmap rewind      = convertBitmap(KwisStandalone.Properties.Resources.REWIND);
            Bitmap play        = convertBitmap(KwisStandalone.Properties.Resources.PLAY);
            Bitmap menu        = convertBitmap(KwisStandalone.Properties.Resources.MENU);
            Bitmap volUp       = convertBitmap(KwisStandalone.Properties.Resources.VOL_UP);
            Bitmap volDown     = convertBitmap(KwisStandalone.Properties.Resources.VOL_DOWN);

            //--------------------------------

            // initial the template matching algorithm.
            templateMatching = new ExhaustiveTemplateMatching(0.75f);


            /* If we were able to aquire a frame from the camera,
             * start the main application logic.
             * */
            if (pp.Init())
            {
                //Loop forever as long as the form is still open.
                while (!form.closing)
                {
                    if (!pp.AcquireFrame(true))
                    {
                        MessageBox.Show("Failed to aquire a frame.", "Kwi-S", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                        break;
                    }

                    //Aquire the gesture data for the frame.
                    using (PXCMGesture gesture = pp.QueryGesture())
                    {
                        //Load gesture data into respective data structures.
                        gesture.QueryBlobData(PXCMGesture.Blob.Label.LABEL_SCENE, 0, out bdata);
                        gesture.QueryBlobImage(PXCMGesture.Blob.Label.LABEL_SCENE, 0, out bimage);
                        bimage.AcquireAccess(PXCMImage.Access.ACCESS_READ, out data);
                        info = bimage.imageInfo;



                        /* Although this says left hand,
                         * this actually aquires the right hand.
                         * This is from trial and error and contradicts
                         * both the documentation and common sense.  A bug
                         * in the SDK?
                         * */
                        color = (int)bdata.labelLeftHand;

                        //Store the pixels that include the hand specified above.
                        locations = new Coord[info.width * info.height];
                        handLocation(ref locations, data, (int)info.width);

                        //create a new bitmap from this data.
                        Bitmap bitmap = createBitmap(ref locations, (int)info.width, (int)info.height);


                        /* Zero is the left hand (actuall right).  So, if we detected this,
                         * then lets see if it matches any of the stored reference images.
                         * */
                        if (color == 0)
                        {
                            try
                            {
                                if (compare(ref bitmap, ref pause))
                                {
                                    clickAndSendKey(RemoteKey.PLAY_PAUSE);
                                }
                                else if (compare(ref bitmap, ref play))
                                {
                                    clickAndSendKey(RemoteKey.PLAY);
                                }
                                else if (compare(ref bitmap, ref fastForward))
                                {
                                    clickAndSendKey(RemoteKey.FAST_FORWARD);
                                }

                                else if (compare(ref bitmap, ref rewind))
                                {
                                    clickAndSendKey(APPCOMMAND_MEDIA_REWIND, handle);
                                }
                                else if (compare(ref bitmap, ref menu))
                                {
                                    clickAndSendKey(RemoteKey.STOP);
                                }
                                else if (compare(ref bitmap, ref volUp))
                                {
                                    clickAndSendKey(RemoteKey.VOL_UP);
                                }
                                else if (compare(ref bitmap, ref volDown))
                                {
                                    clickAndSendKey(RemoteKey.VOL_DOWN);
                                }
                            }
                            catch (InvalidImagePropertiesException iipe)
                            {
                            }
                        }

                        //Clean up the datastructures in prep for a new frame.
                        bitmap.Dispose();
                        bimage.ReleaseAccess(ref data);
                        bimage.Dispose();
                        gesture.Dispose();
                    }

                    pp.ReleaseFrame();
                }
            }
        }