Exemple #1
0
  /**
   * get data from camera
   *
   * @return true if data have been produced
   */
  public boolean getData() {

    if (!connected) return false;

    sts = SENSE_MANAGER.AcquireFrame(true);
    if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR) < 0) {
      gotMessage = false;
      SENSE_MANAGER.ReleaseFrame();
      return false;
    }

    // Query and Display Joint of Hand or Palm
    handData.Update();

    sts = handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_NEAR_TO_FAR, 0, hand);

    if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR) >= 0) {
      PXCMPoint3DF32 world = hand.QueryMassCenterWorld();
      PXCMPoint4DF32 palmOrientation = hand.QueryPalmOrientation();
      BodySideType handSide = hand.QueryBodySide();

      dataSampler.addData(
          handSide,
          world.x,
          world.y,
          world.z,
          palmOrientation.x,
          palmOrientation.y,
          palmOrientation.z,
          palmOrientation.w);

      handX = dataSampler.getWorldX();
      handY = dataSampler.getWorldY();
      handZ = dataSampler.getWorldZ();

      switch (dataSampler.getSide()) {
        case BODY_SIDE_RIGHT:
          handX -= SIDE_OFFSET;
          break;
        case BODY_SIDE_LEFT:
          handX += SIDE_OFFSET;
          break;
        case BODY_SIDE_UNKNOWN:
        default:
          handX -= SIDE_OFFSET;
          break;
      }

      handOrientationX = dataSampler.getHandOrientationX();
      handOrientationY = dataSampler.getHandOrientationY();
      handOrientationZ = dataSampler.getHandOrientationZ();
      handOrientationW = dataSampler.getHandOrientationW();

      gotMessage = true;

    } else {
      gotMessage = false;
    }

    SENSE_MANAGER.ReleaseFrame();

    return true;
  }
Exemple #2
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");
  }