private void initFubi() { List <string> availableSensors = new List <string>(); availableSensors.Add(Enum.GetName(typeof(FubiUtils.SensorType), FubiUtils.SensorType.NONE)); FubiUtils.SensorType type = FubiUtils.SensorType.NONE; int avSensors = Fubi.getAvailableSensors(); if ((avSensors & (int)FubiUtils.SensorType.OPENNI2) != 0) { type = FubiUtils.SensorType.OPENNI2; availableSensors.Add(Enum.GetName(typeof(FubiUtils.SensorType), type)); } if ((avSensors & (int)FubiUtils.SensorType.KINECTSDK) != 0) { if (type == FubiUtils.SensorType.NONE) { type = FubiUtils.SensorType.KINECTSDK; } availableSensors.Add(Enum.GetName(typeof(FubiUtils.SensorType), FubiUtils.SensorType.KINECTSDK)); } if ((avSensors & (int)FubiUtils.SensorType.OPENNI1) != 0) { if (type == FubiUtils.SensorType.NONE) { type = FubiUtils.SensorType.OPENNI1; } availableSensors.Add(Enum.GetName(typeof(FubiUtils.SensorType), FubiUtils.SensorType.OPENNI1)); } string selectedName = Enum.GetName(typeof(FubiUtils.SensorType), type); foreach (string sType in availableSensors) { int index = sensorSelectionComboBox.Items.Add(sType); if (index > -1 && sType == selectedName) { sensorSelectionComboBox.SelectedIndex = index; } } switchSensorOnNextUpdate = false; Fubi.init(new FubiUtils.SensorOptions(new FubiUtils.StreamOptions(640, 480, 30), new FubiUtils.StreamOptions(640, 480), new FubiUtils.StreamOptions(-1, -1, -1), type)); Fubi.loadRecognizersFromXML("MouseControlRecognizers.xml"); }
private void button1_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.FileName = "SampleRecognizers"; // Default file name dlg.DefaultExt = ".xml"; // Default file extension dlg.Filter = "MXL documents (.xml)|*.xml"; // Filter files by extension // Show open file dialog box Nullable <bool> result = dlg.ShowDialog(); // Process open file dialog box results if (result == true && dlg.FileName != null) { // Open document Fubi.loadRecognizersFromXML(dlg.FileName); // Enable clear button if we have loaded some recognizers button3.IsEnabled = (Fubi.getNumUserDefinedCombinationRecognizers() > 0 || Fubi.getNumUserDefinedRecognizers() > 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(); }
// Initialization void Start() { //AA: Filter visalization related initializations filter = new Filter(); fv = new FilterVisualization(); fm = new FilterManager(); fv.filterOutputLocX = Screen.width / 3 - 50; fv.Initialise(); fv.DrawCircle(); m_colorTextureDictionary = new Dictionary <string, Texture2D>(); foreach (Texture2D tex in m_colorTextures) { m_colorTextureDictionary.Add(tex.name, tex); } LoadFilters(); // First set instance so Fubi.release will not be called while destroying old objects instance = this; // Remain this instance active until new one is created DontDestroyOnLoad(this); // Destroy old instance of Fubi object[] objects = GameObject.FindObjectsOfType(typeof(FubiUnity)); if (objects.Length > 1) { Destroy(((FubiUnity)objects[0])); } m_lastMouseClick = 0; m_lastGesture = 0; // Init FUBI if (!m_disableFubi) { // Only init if not already done if (!Fubi.isInitialized()) { Fubi.init(new FubiUtils.SensorOptions(new FubiUtils.StreamOptions(640, 480, 30), new FubiUtils.StreamOptions(640, 480, 30), new FubiUtils.StreamOptions(-1, -1, -1), FubiUtils.SensorType.OPENNI2), new FubiUtils.FilterOptions()); if (!Fubi.isInitialized()) { Debug.Log("Fubi: FAILED to initialize Fubi!"); } else { Debug.Log("Fubi: initialized!"); } } } else { m_disableTrackingImage = true; } // Initialize debug image // m_depthMapTexture = new Texture2D((int)(m_xRes / m_factor), (int)(m_yRes / m_factor), TextureFormat.RGBA32, false); // m_depthMapPixels = new Color[(int)((m_xRes / m_factor) * (m_yRes / m_factor))]; // m_rawImage = new byte[(int)(m_xRes * m_yRes * 4)]; m_userImageTexture = null; // Disable system cursor if (m_defaultCursor != null && m_disableFubi == false) { Screen.showCursor = false; } else { Screen.showCursor = true; } // Default mapping values m_mapping.x = -100.0f; m_mapping.y = 200.0f; m_mapping.height = 550.0f; // Get screen aspect m_aspect = (float)Screen.width / (float)Screen.height; // Calculated Map width with aspect m_mapping.width = m_mapping.height / m_aspect; if (Fubi.isInitialized()) { // Clear old gesture recognizers Fubi.clearUserDefinedRecognizers(); // And (re)load them if (Fubi.loadRecognizersFromXML("UnitySampleRecognizers.xml")) { Debug.Log("Fubi: gesture recognizers 'BarRecognizers.xml' loaded!"); } else { Debug.Log("Fubi: loading XML recognizers failed!"); } // load mouse control recognizers if (Fubi.loadRecognizersFromXML("MouseControlRecognizers.xml")) { Debug.Log("Fubi: mouse control recognizers loaded!"); } else { Debug.Log("Fubi: loading mouse control recognizers failed!"); } } }