예제 #1
0
        public static void getImage(byte[] outputImage, FubiUtils.ImageType type, FubiUtils.ImageNumChannels numChannels, FubiUtils.ImageDepth depth,
                                    uint renderOptions = (uint)FubiUtils.RenderOptions.Default,
                                    FubiUtils.DepthImageModification depthModifications = FubiUtils.DepthImageModification.UseHistogram,
                                    uint userId = 0, FubiUtils.SkeletonJoint jointOfInterest = FubiUtils.SkeletonJoint.NUM_JOINTS)
        {
            if (outputImage != null)
            {
                int size = outputImage.Length + 1;

                // allocate memory for resource data
                IntPtr ptr = Marshal.AllocHGlobal(size);

                // load resource
                FubiInternal.getImage(ptr, type, numChannels, depth, renderOptions, depthModifications, userId, jointOfInterest);

                // copy byte data into allocated memory
                Marshal.Copy(ptr, outputImage, 0, outputImage.Length);


                Marshal.WriteByte(ptr, size, 0x00);
                // free previously allocated memory
                Marshal.FreeHGlobal(ptr);

                return;
            }
        }
예제 #2
0
        public static bool saveImage(string fileName, int jpegQuality /*0-100*/,
                                     FubiUtils.ImageType type, FubiUtils.ImageNumChannels numChannels, FubiUtils.ImageDepth depth,
                                     uint renderOptions = (uint)FubiUtils.RenderOptions.Default,
                                     FubiUtils.DepthImageModification depthModifications = FubiUtils.DepthImageModification.UseHistogram,
                                     UInt32 userId = 0, FubiUtils.SkeletonJoint jointOfInterest = FubiUtils.SkeletonJoint.NUM_JOINTS)
        {
            IntPtr namePtr = Marshal.StringToHGlobalAnsi(fileName);
            bool   ret     = FubiInternal.saveImage(namePtr, jpegQuality, type, numChannels, depth, renderOptions, depthModifications, userId, jointOfInterest);

            Marshal.FreeHGlobal(namePtr);
            return(ret);
        }
예제 #3
0
        private void fubiMain(object filterOptions)
        {
            m_renderOptions  = 0;
            m_renderOptions |= (int)FubiUtils.RenderOptions.Shapes;
            //m_renderOptions |= (int)FubiUtils.RenderOptions.Skeletons;
            //m_renderOptions |= (int)FubiUtils.RenderOptions.UserCaptions;
            //m_renderOptions |= (int)FubiUtils.RenderOptions.Background;
            //m_renderOptions |= (int)FubiUtils.RenderOptions.SwapRAndB;
            // m_renderOptions |= (int)FubiUtils.RenderOptions.DetailedFaceShapes;
            //m_renderOptions |= (int)FubiUtils.RenderOptions.BodyMeasurements;
            // m_renderOptions |= (int)FubiUtils.RenderOptions.GlobalOrientCaptions; // or
            //m_renderOptions |= (int)FubiUtils.RenderOptions.LocalOrientCaptions;
            // m_renderOptions |= (int)FubiUtils.RenderOptions.GlobalPosCaptions;  // or
            //m_renderOptions |= (int)FubiUtils.RenderOptions.LocalPosCaptions;
            m_renderOptions |= (int)FubiUtils.RenderOptions.UseFilteredValues;

            var rgbOptions     = new FubiUtils.StreamOptions();
            var irOptions      = new FubiUtils.StreamOptions();
            var depthOptions   = new FubiUtils.StreamOptions();
            var invalidOptions = new FubiUtils.StreamOptions(-1);

            lock (LockFubiUpdate)
            {
                if (!Fubi.init(new FubiUtils.SensorOptions(depthOptions, rgbOptions, irOptions, m_selectedSensor),
                               (FubiUtils.FilterOptions)filterOptions))
                {   // the following for when the init fails
                    m_selectedSensor = FubiUtils.SensorType.NONE;
                    Fubi.init(new FubiUtils.SensorOptions(depthOptions, invalidOptions, invalidOptions, m_selectedSensor),
                              (FubiUtils.FilterOptions)filterOptions);
                    Dispatcher.BeginInvoke(new TwoStringDelegate(showWarnMsg),
                                           new object[]
                    {
                        "Error starting sensor! \nDid you connect the sensor and install the correct driver? \nTry selecting a different sensor.",
                        "Error starting sensor"
                    });
                    return;
                }
                Fubi.getDepthResolution(out m_width, out m_height);
                m_numChannels = FubiUtils.ImageNumChannels.C4;

                // All known combination recognizers will be started automatically for new users
                Fubi.setAutoStartCombinationRecognition(true);

                // Load XML with sample mouse control gestures
                if (Fubi.loadRecognizersFromXML("TutorialRecognizers.xml"))
                {
                    //    // This requires to update the gesture list used for selecting key/button bindings and for xml generation
                    //    Dispatcher.BeginInvoke(new NoArgDelegate(refreshGestureList), null);
                    //    // Now we can load the default bindings using the above recognizers
                    //    Dispatcher.BeginInvoke(new OneStringDelegate(m_fubiMouseKeyboard.Bindings.loadFromXML), "KeyMouseBindings.xml");
                }
            }

            Fubi.RecognitionStart += new Fubi.RecognitionHandler(recognitionStart);
            Fubi.RecognitionEnd   += new Fubi.RecognitionHandler(recognitionEnd);
            DispatcherOperation currentOp = null;

            videoFile.fileName = "trainingData/tempRecord2.vid";
            videoFile.startPlayback();

            while (m_running)
            {
                lock (LockFubiUpdate)
                {
                    // Now update the sensors
                    Fubi.updateSensor();

                    Fubi.getImage(s_buffer2, FubiUtils.ImageType.Depth, m_numChannels, FubiUtils.ImageDepth.D8, m_renderOptions,
                                  (int)FubiUtils.JointsToRender.ALL_JOINTS, m_selectedDepthMod);
                }

                // And trigger a GUI update event
                currentOp = Dispatcher.BeginInvoke(new NoArgDelegate(updateGUI), null);
                // Wait for the GUI update to finish
                while (currentOp.Status != DispatcherOperationStatus.Completed &&
                       currentOp.Status != DispatcherOperationStatus.Aborted)
                {
                    Thread.Sleep(5);
                }
            }
            // Wait for the last GUI update to really have finished
            while (currentOp != null && currentOp.Status != DispatcherOperationStatus.Completed &&
                   currentOp.Status != DispatcherOperationStatus.Aborted)
            {
                Thread.Sleep(2);
            }
            // Now we can release Fubi safely
            Fubi.release();
        }
예제 #4
0
        private void updateFubi()
        {
            if (clearRecognizersOnNextUpdate)
            {
                Fubi.clearUserDefinedRecognizers();
                if (Fubi.getNumUserDefinedCombinationRecognizers() == 0 && Fubi.getNumUserDefinedRecognizers() == 0)
                {
                    button3.IsEnabled = false;
                }
                clearRecognizersOnNextUpdate = false;
            }

            if (switchSensorOnNextUpdate)
            {
                Fubi.switchSensor(new FubiUtils.SensorOptions(new FubiUtils.StreamOptions(), new FubiUtils.StreamOptions(), new FubiUtils.StreamOptions(-1, -1, -1),
                                                              (FubiUtils.SensorType)Enum.Parse(typeof(FubiUtils.SensorType), sensorSelectionComboBox.SelectedItem.ToString())));
                switchSensorOnNextUpdate = false;
            }

            label1.Content = "User Count : " + Fubi.getNumUsers().ToString();

            // Update Fubi and get the debug image
            int width = 0, height = 0;

            FubiUtils.ImageNumChannels channels = FubiUtils.ImageNumChannels.C4;
            FubiUtils.ImageType        type     = FubiUtils.ImageType.Depth;

            uint renderOptions = 0;

            if (shapeCheckBox.IsChecked == true)
            {
                renderOptions |= (uint)FubiUtils.RenderOptions.Shapes;
            }
            if (skeletonCheckBox.IsChecked == true)
            {
                renderOptions |= (uint)FubiUtils.RenderOptions.Skeletons;
            }
            if (userCaptionscheckBox.IsChecked == true)
            {
                renderOptions |= (uint)FubiUtils.RenderOptions.UserCaptions;
            }
            if (localOrientCheckBox.IsChecked == true)
            {
                renderOptions |= (uint)FubiUtils.RenderOptions.LocalOrientCaptions;
            }
            if (globalOrientCheckBox.IsChecked == true)
            {
                renderOptions |= (uint)FubiUtils.RenderOptions.GlobalOrientCaptions;
            }
            if (localPosCheckBox.IsChecked == true)
            {
                renderOptions |= (uint)FubiUtils.RenderOptions.LocalPosCaptions;
            }
            if (globalPosCheckBox.IsChecked == true)
            {
                renderOptions |= (uint)FubiUtils.RenderOptions.GlobalPosCaptions;
            }
            if (backgroundCheckBox.IsChecked == true)
            {
                renderOptions |= (uint)FubiUtils.RenderOptions.Background;
            }
            if (swapRAndBcheckBox.IsChecked == true)
            {
                renderOptions |= (uint)FubiUtils.RenderOptions.SwapRAndB;
            }
            if (fingerShapecheckBox.IsChecked == true)
            {
                renderOptions |= (uint)FubiUtils.RenderOptions.FingerShapes;
            }
            if (detailedFaceCheckBox.IsChecked == true)
            {
                renderOptions |= (uint)FubiUtils.RenderOptions.DetailedFaceShapes;
            }
            if (bodyMeasuresCheckBox.IsChecked == true)
            {
                renderOptions |= (uint)FubiUtils.RenderOptions.BodyMeasurements;
            }

            FubiUtils.DepthImageModification depthMods = (FubiUtils.DepthImageModification)Enum.Parse(typeof(FubiUtils.DepthImageModification), comboBox1.SelectedItem.ToString(), true);

            if (checkBox3.IsChecked == true)
            {
                Fubi.getRgbResolution(out width, out height);
                channels = FubiUtils.ImageNumChannels.C3;
                type     = FubiUtils.ImageType.Color;
            }
            else
            {
                Fubi.getDepthResolution(out width, out height);
                channels = FubiUtils.ImageNumChannels.C4;
                type     = FubiUtils.ImageType.Depth;
            }

            // Display the debug image
            if (width > 0 && height > 0)
            {
                WriteableBitmap wb = image1.Source as WriteableBitmap;
                if (wb != null && (wb.Width != width || wb.Height != height || wb.Format.BitsPerPixel != (int)channels * 8))
                {
                    wb            = null;
                    image1.Width  = width;
                    image1.Height = height;
                    buffer        = new byte[(int)channels * width * height];
                }
                if (wb == null)
                {
                    PixelFormat format = PixelFormats.Bgra32;
                    if (channels == FubiUtils.ImageNumChannels.C3)
                    {
                        format = PixelFormats.Rgb24;
                    }
                    else if (channels == FubiUtils.ImageNumChannels.C1)
                    {
                        format = PixelFormats.Gray8;
                    }
                    wb            = new WriteableBitmap(width, height, 0, 0, format, BitmapPalettes.Gray256);
                    image1.Source = wb;
                }

                Fubi.updateSensor();
                Fubi.getImage(buffer, type, channels, FubiUtils.ImageDepth.D8, renderOptions, depthMods);

                int stride = wb.PixelWidth * (wb.Format.BitsPerPixel / 8);
                wb.WritePixels(new Int32Rect(0, 0, wb.PixelWidth, wb.PixelHeight), buffer, stride, 0);
            }

            //Check postures for all users
            for (uint i = 0; i < Fubi.getNumUsers(); i++)
            {
                uint id = Fubi.getUserID(i);
                if (id > 0)
                {
                    bool changedSomething = false;
                    // Print postures
                    if (checkBox1.IsChecked == true)
                    {
                        // Only user defined postures
                        for (uint p = 0; p < Fubi.getNumUserDefinedRecognizers(); ++p)
                        {
                            if (Fubi.recognizeGestureOn(p, id) == FubiUtils.RecognitionResult.RECOGNIZED)
                            {
                                // Posture recognized
                                if (!currentPostures.ContainsKey(p) || !currentPostures[p])
                                {
                                    // Posture start
                                    textBox1.Text     += "User" + id + ": START OF " + Fubi.getUserDefinedRecognizerName(p) + " -->\n";
                                    currentPostures[p] = true;
                                    changedSomething   = true;
                                }
                            }
                            else if (currentPostures.ContainsKey(p) && currentPostures[p])
                            {
                                // Posture end
                                textBox1.Text     += "User" + id + ": --> END OF " + Fubi.getUserDefinedRecognizerName(p) + "\n";
                                currentPostures[p] = false;
                                changedSomething   = true;
                            }
                        }

                        if (PredefinedCheckBox.IsChecked == true)
                        {
                            for (int p = 0; p < (int)FubiPredefinedGestures.Postures.NUM_POSTURES; ++p)
                            {
                                if (Fubi.recognizeGestureOn((FubiPredefinedGestures.Postures)p, id) == FubiUtils.RecognitionResult.RECOGNIZED)
                                {
                                    if (!currentPostures1[p])
                                    {
                                        // Posture recognized
                                        textBox1.Text      += "User" + id + ": START OF" + FubiPredefinedGestures.getPostureName((FubiPredefinedGestures.Postures)p) + "\n";
                                        currentPostures1[p] = true;
                                        changedSomething    = true;
                                    }
                                }
                                else if (currentPostures1[p])
                                {
                                    textBox1.Text      += "User" + id + ": --> END OF " + FubiPredefinedGestures.getPostureName((FubiPredefinedGestures.Postures)p) + "\n";
                                    currentPostures1[p] = false;
                                    changedSomething    = true;
                                }
                            }
                        }

                        if (changedSomething)
                        {
                            textBox1.ScrollToEnd();
                        }
                    }

                    // Print combinations
                    for (uint pc = 0; pc < Fubi.getNumUserDefinedCombinationRecognizers(); ++pc)
                    {
                        // Only user defined postures
                        if (checkBox2.IsChecked == true)
                        {
                            if (Fubi.getCombinationRecognitionProgressOn(Fubi.getUserDefinedCombinationRecognizerName(pc), id) == FubiUtils.RecognitionResult.RECOGNIZED)
                            {
                                // Posture recognized
                                textBox2.Text += "User" + id + ": " + Fubi.getUserDefinedCombinationRecognizerName(pc) + "\n";
                            }
                            else
                            {
                                Fubi.enableCombinationRecognition(Fubi.getUserDefinedCombinationRecognizerName(pc), id, true);
                            }
                        }
                        //else
                        //    Fubi.enableCombinationRecognition(Fubi.getUserDefinedCombinationRecognizerName(pc), id, false);
                    }

                    for (uint pc = 0; pc < (uint)FubiPredefinedGestures.Combinations.NUM_COMBINATIONS; ++pc)
                    {
                        if (checkBox2.IsChecked == true && PredefinedCheckBox.IsChecked == true)
                        {
                            if (Fubi.getCombinationRecognitionProgressOn((FubiPredefinedGestures.Combinations)pc, id) == FubiUtils.RecognitionResult.RECOGNIZED)
                            {
                                // Posture recognized
                                textBox2.Text += "User" + id + ": " + FubiPredefinedGestures.getCombinationName((FubiPredefinedGestures.Combinations)pc) + "\n";
                            }
                            else
                            {
                                Fubi.enableCombinationRecognition((FubiPredefinedGestures.Combinations)pc, id, true);
                            }
                        }
                        //else
                        //    Fubi.enableCombinationRecognition((FubiPredefinedGestures.Combinations)pc, id, false);
                    }
                    if (checkBox2.IsChecked == true)
                    {
                        textBox2.ScrollToEnd();
                    }
                }
            }

            uint closestId = Fubi.getClosestUserID();

            if (closestId > 0)
            {
                // For printing the user orientation
                //float[] mat = new float[9];
                //float confidence;
                //double timeStamp;
                //Fubi.getCurrentSkeletonJointOrientation(closestId, FubiUtils.SkeletonJoint.Torso, mat, out confidence, out timeStamp);
                //float rx, ry, rz;
                //FubiUtils.Math.rotMatToRotation(mat, out rx, out ry, out rz);
                //label1.Content = "UserOrient:" + String.Format("{0:0.#}", rx) + "/" + String.Format("{0:0.#}", ry) + "/" + String.Format("{0:0.#}", rz);


                if (controlMouse)
                {
                    float x, y;
                    FubiMouse.applyHandPositionToMouse(closestId, out x, out y, leftHandRadioButton.IsChecked == true);
                    label2.Content = "X:" + x + " Y:" + y;
                }

                if (checkBox4.IsChecked == true)
                {
                    FubiPredefinedGestures.Combinations activationGesture = FubiPredefinedGestures.Combinations.WAVE_RIGHT_HAND_OVER_SHOULDER;
                    // TODO use left hand waving
                    if (Fubi.getCombinationRecognitionProgressOn(activationGesture, closestId, false) == FubiUtils.RecognitionResult.RECOGNIZED)
                    {
                        if (controlMouse)
                        {
                            stopMouseEmulation();
                        }
                        else
                        {
                            startMouseEmulation();
                        }
                    }
                    else
                    {
                        Fubi.enableCombinationRecognition(activationGesture, closestId, true);
                    }
                }
            }
        }
예제 #5
0
 internal static extern bool saveImage(IntPtr fileName, int jpegQuality /*0-100*/,
                                       FubiUtils.ImageType type, FubiUtils.ImageNumChannels numChannels, FubiUtils.ImageDepth depth,
                                       uint renderOptions = (uint)FubiUtils.RenderOptions.Default,
                                       FubiUtils.DepthImageModification depthModifications = FubiUtils.DepthImageModification.UseHistogram,
                                       UInt32 userId = 0, FubiUtils.SkeletonJoint jointOfInterest = FubiUtils.SkeletonJoint.NUM_JOINTS);
예제 #6
0
 internal static extern void getImage(IntPtr outputImage, FubiUtils.ImageType type, FubiUtils.ImageNumChannels numChannels, FubiUtils.ImageDepth depth,
                                      uint renderOptions = (uint)FubiUtils.RenderOptions.Default,
                                      FubiUtils.DepthImageModification depthModifications = FubiUtils.DepthImageModification.UseHistogram,
                                      UInt32 userId = 0, FubiUtils.SkeletonJoint jointOfInterest = FubiUtils.SkeletonJoint.NUM_JOINTS);