예제 #1
0
 /** exit and close manager */
 public void exit() {
   CAPTURE_MANAGER.CloseStreams();
   SENSE_MANAGER.Close();
   SENSE_MANAGER = null;
   SESSION.close();
   SESSION = null;
 }
예제 #2
0
  /**
   * Create a session to use realsense camera
   *
   * @throws Exception if no camera installed
   */
  public static void createSession() throws Input3DException {

    if (SESSION != null) {
      return;
    }

    // reset sense manager
    SENSE_MANAGER = null;

    try {
      // Create session
      SESSION = PXCMSession.CreateInstance();
    } catch (Throwable e) {
      throw new Input3DException(
          Input3DExceptionType.INSTALL,
          "RealSense: Failed to start session instance creation, maybe unsupported platform?");
    }
    if (SESSION == null) {
      throw new Input3DException(
          Input3DExceptionType.INSTALL, "RealSense: Failed to create a session instance");
    }
  }
예제 #3
0
  /**
   * Create a "Socket" for realsense camera
   *
   * @throws Exception when fails
   */
  public Socket() throws Input3DException {

    if (SESSION == null) {
      createSession();
    }

    if (SESSION == null) {
      throw new Input3DException(Input3DExceptionType.INSTALL, "RealSense: no session created");
    }

    if (SENSE_MANAGER != null) {
      throw new Input3DException(Input3DExceptionType.ALREADY_USED, "RealSense: already in use");
    }

    SENSE_MANAGER = SESSION.CreateSenseManager();
    if (SENSE_MANAGER == null) {
      throw new Input3DException(
          Input3DExceptionType.RUN, "RealSense: Failed to create a SenseManager instance");
    }

    CAPTURE_MANAGER = SENSE_MANAGER.QueryCaptureManager();
    CAPTURE_MANAGER.FilterByDeviceInfo("RealSense", null, 0);

    sts = SENSE_MANAGER.EnableHand(null);
    if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR) < 0) {
      throw new Input3DException(
          Input3DExceptionType.RUN, "RealSense: Failed to enable HandAnalysis");
    }

    dataSampler = new DataAverage(SAMPLES);

    sts = SENSE_MANAGER.Init();
    if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR) >= 0) {
      PXCMHandModule handModule = SENSE_MANAGER.QueryHand();
      PXCMHandConfiguration handConfig = handModule.CreateActiveConfiguration();

      handConfig.EnableAllAlerts();

      AlertHandler alertHandler =
          new AlertHandler() {

            @Override
            public void OnFiredAlert(intel.rssdk.PXCMHandData.AlertData data) {
              setAlert(data.handId, data.label);
            }
          };
      handConfig.SubscribeAlert(alertHandler);

      handConfig.ApplyChanges();
      handConfig.Update();

      handData = handModule.CreateOutput();
      hand = new PXCMHandData.IHand();

      handOut = OutOfField.YES;
      connected = true;
    }

    if (!connected) {
      throw new Input3DException(Input3DExceptionType.RUN, "RealSense: not connected");
    }

    Log.debug("RealSense: connected");
  }
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // Creating a session.
    PXCMSession session = PXCMSession.CreateInstance();

    // Querying the SDK version
    PXCMSession.ImplVersion sdkVersion = session.QueryVersion();
    System.out.println(
        String.format("RealSense SDK Version %d.%d", sdkVersion.major, sdkVersion.minor));

    // General information about Speech Recognition.
    // Creating an AudioSource
    PXCMAudioSource audioSource = session.CreateAudioSource();

    // Listing the audio devices
    audioSource.ScanDevices();
    int devicesCount = audioSource.QueryDeviceNum();

    if (devicesCount <= 0) {
      System.out.println("There is no audio device available.");
      return;
    }

    System.out.println("Listing audio devices:");

    for (int i = 0; i < devicesCount; i++) {
      PXCMAudioSource.DeviceInfo deviceInfo = new PXCMAudioSource.DeviceInfo();
      audioSource.QueryDeviceInfo(i, deviceInfo);
      System.out.println(String.format("\t%s: %s", deviceInfo.did, deviceInfo.name));
    }

    // Selecting the first device
    PXCMAudioSource.DeviceInfo deviceInfo = new PXCMAudioSource.DeviceInfo();
    audioSource.QueryDeviceInfo(0, deviceInfo);
    audioSource.SetDevice(deviceInfo);

    // Adjusting the audio recording volume.
    audioSource.SetVolume(0.2f);

    // Creating the SpeechRecognition instance
    PXCMSpeechRecognition speechRecognition = new PXCMSpeechRecognition();
    pxcmStatus speechRecognitionStatus = session.CreateImpl(speechRecognition);

    if (speechRecognitionStatus != pxcmStatus.PXCM_STATUS_NO_ERROR) {
      System.out.println("Failed to create the SpeechRecognition instance");
      return;
    }

    // Configuring the speech module
    List<PXCMSpeechRecognition.ProfileInfo> availableProfiles =
        new ArrayList<PXCMSpeechRecognition.ProfileInfo>();
    System.out.println("Listing the available profiles:");
    for (int i = 0; ; i++) {
      PXCMSpeechRecognition.ProfileInfo profileInfo = new PXCMSpeechRecognition.ProfileInfo();
      pxcmStatus profileQueryStatus = speechRecognition.QueryProfile(i, profileInfo);

      if (profileQueryStatus != pxcmStatus.PXCM_STATUS_NO_ERROR) {
        break;
      }
      System.out.println(String.format("\t%s", profileInfo.language));
      availableProfiles.add(profileInfo);
    }

    // Setting the first profile
    speechRecognition.SetProfile(availableProfiles.get(0));

    if (DemoRecognitionType
        == RecognitionType
            .DICTATION) // To change the recognition mode, please change the value of the
                        // DemoRecognitionType constant at the beginning of this file.
    {
      //  Seting the dictation mode
      pxcmStatus setDictationStatus = speechRecognition.SetDictation();

      if (setDictationStatus != pxcmStatus.PXCM_STATUS_NO_ERROR) {
        System.out.println("Failed to create the SpeechRecognition instance");
        return;
      }
    } else {
      // Building a list of commands
      String[] commandsGrammar1 = {"One", "Two", "Three"}; // English
      speechRecognition.BuildGrammarFromStringList(
          1, commandsGrammar1, null, commandsGrammar1.length);

      String[] commandsGrammar2 = {"Um", "Dois", "Três"};
      speechRecognition.BuildGrammarFromStringList(
          2, commandsGrammar2, null, commandsGrammar2.length);

      // Selecting the grammar
      speechRecognition.SetGrammar(1);
    }

    // Handling recognition events
    PXCMSpeechRecognition.Handler handler =
        new PXCMSpeechRecognition.Handler() {
          @Override
          public void OnAlert(PXCMSpeechRecognition.AlertData alertData) {
            System.out.println(alertData.label);
          }

          @Override
          public void OnRecognition(PXCMSpeechRecognition.RecognitionData recognitionData) {
            switch (DemoRecognitionType) { // To change the recognition mode, please change the
                                           // value of the DemoRecognitionType constant at the
                                           // beginning of this file.
              case DICTATION:
                processDictation(recognitionData);
                break;
              case COMMAND:
              default:
                processCommands(recognitionData);
                break;
            }
          }

          public void OnRecognized(PXCMSpeechRecognition.RecognitionData recognitionData) {
            OnRecognition(recognitionData);
          }
        };

    speechRecognition.StartRec(audioSource, handler);

    // Waiting a key to stop voice recognition
    // Console.ReadKey();
    speechRecognition.StopRec();
  }