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; } }
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; } }
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(); } } }