Project Tango Pythagoras:无法触发OnXYZijAvailable Callback

时间:2015-07-02 15:11:27

标签: java android vuforia google-project-tango

在Java API中开发Project Tango Android应用程序,我无法让平板电脑触发onXYZijAvailable回调,我真的很想在我的应用程序中使用深度数据。

这是我设置Tango并附加其听众的代码:

Tango初始化:

try {
            Log.d(TAG, "Creating TangoPoseHandler Object");
            this.main = main;
            mTango = new Tango(main);
            mConfig = new TangoConfig();
            mConfig = mTango.getConfig(TangoConfig.CONFIG_TYPE_CURRENT);
            mConfig.putBoolean(TangoConfig.KEY_BOOLEAN_MOTIONTRACKING, true);
            mConfig.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true);
            mConfig.putBoolean(TangoConfig.KEY_BOOLEAN_AUTORECOVERY, true);
            framePairs = new ArrayList<TangoCoordinateFramePair>();
        } catch (TangoErrorException e) {
            Log.d("TANGO ERROR", "TangoErrorException");
        }

活动期间onResume():

if (!isTangoConnected) {
            main.startActivityForResult(
                    Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_MOTION_TRACKING),
                    Tango.TANGO_INTENT_ACTIVITYCODE);
        }

根据活动结果:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d(MAIN_ACTIVITY, "Activity Result Triggered");
        if (Tango.TANGO_INTENT_ACTIVITYCODE == requestCode) {
            ((TangoPoseHandler)poseHandler).setup(requestCode, resultCode, data);
        }
    }

设置方法叫做:

 public void setup(int requestCode, int resultCode, Intent data) {
        if (requestCode == Tango.TANGO_INTENT_ACTIVITYCODE) {
            // Make sure the request was successful
            if (resultCode == android.app.Activity.RESULT_CANCELED) {
                Toast.makeText(main,
                        "This app requires Motion Tracking permission!",
                        Toast.LENGTH_LONG).show();
                main.finish();
                return;
            }

            try {
                setTangoListeners();
            } catch (TangoErrorException e) {
                Log.d(TAG, "TANGO ERROR WHEN SETTING LISTENERS");
                Toast.makeText(main, "Tango Error! Restart the app!",
                        Toast.LENGTH_SHORT).show();
                return;
            }
            try {
                mTango.connect(mConfig);
                isTangoConnected = true;
            } catch (TangoOutOfDateException e) {
                Toast.makeText(main.getApplicationContext(),
                        "Tango Service out of date!", Toast.LENGTH_SHORT)
                        .show();
            } catch (TangoErrorException e) {
                Toast.makeText(main.getApplicationContext(),
                        "Tango Error! Restart the app!", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    }

setTangoListeners()方法名为:

private void setTangoListeners() {
        // Select coordinate frame pairs
        framePairs.clear();
        framePairs.add(new TangoCoordinateFramePair(
                TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE ,
                TangoPoseData.COORDINATE_FRAME_DEVICE ));

        mTango.connectListener(framePairs, new Tango.OnTangoUpdateListener() {

            /**
             * Callback called when new pose data is made available from the Tango
             * @param tangoPoseData
             */
            @Override
            public void onPoseAvailable(final TangoPoseData tangoPoseData) {

                if (tangoPoseData.baseFrame == TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE &&
                        tangoPoseData.targetFrame == TangoPoseData.COORDINATE_FRAME_DEVICE ) {


                    float[] transform = new float[16];
                    Matrix.setIdentityM(transform, 0);

                    NVector translationData = new NVector(
                            SCALE_FACTOR * tangoPoseData.getTranslationAsFloats()[TangoPoseData.INDEX_TRANSLATION_X],
                            SCALE_FACTOR * tangoPoseData.getTranslationAsFloats()[TangoPoseData.INDEX_TRANSLATION_Y],
                            SCALE_FACTOR * tangoPoseData.getTranslationAsFloats()[TangoPoseData.INDEX_TRANSLATION_Z]);

                    rotationQuat = new NVector((float) tangoPoseData.rotation[TangoPoseData.INDEX_ROTATION_X],
                            tangoPoseData.getRotationAsFloats()[TangoPoseData.INDEX_ROTATION_Y],
                            tangoPoseData.getRotationAsFloats()[TangoPoseData.INDEX_ROTATION_Z],
                            tangoPoseData.getRotationAsFloats()[TangoPoseData.INDEX_ROTATION_W]);

                    float[] quatMat = new float[16];
                    Matrix.setIdentityM(quatMat, 0);
                    quatMat = quaternionToMatrix(rotationQuat);

                    Matrix.multiplyMM(transform, 0, openGLConversion, 0, quatMat, 0);

                    transform[12] = translationData.getX();
                    transform[13] = translationData.getZ();
                    transform[14] = -1.f * translationData.getY();

                    float[] invertedTransform = new float[16];
                    Matrix.setIdentityM(invertedTransform, 0);

                    Matrix.invertM(invertedTransform, 0, transform, 0);

                    //main.displayMat(invertedTransform);
                    SceneCamera.instance().setEye(translationData);
                    SceneCamera.instance().set(invertedTransform);

                    //main.displayVals(tempPosition, rotationQuat);
                }
            }

            /**
             * Callback called when new depth data is made available from the tango
             *
             * @param tangoXyzIjData
             */
            @Override
            public void onXyzIjAvailable(final TangoXyzIjData tangoXyzIjData) {
                Log.d("Depth Data", "Collected");
                pointCloudBuffer = tangoXyzIjData.xyz;
            }

            /**
             * Callback when new Image Frame is available for capture
             * @param cameraID      ID of the camera who has a fresh frame prepared
             */
            @Override
            public void onFrameAvailable(int cameraID) {
                Log.d(TAG, "onFrameAvailable Called");
                // Intentionally left empty
            }

            /**
             * Callback when tango has an issue that needs addressing
             * @param tangoEvent    the event storing the data of the issue
             */
            @Override
            public void onTangoEvent(final TangoEvent tangoEvent) {

            if (tangoEvent.eventKey.equals(TangoEvent.DESCRIPTION_FISHEYE_OVER_EXPOSED) ||
                    tangoEvent.eventKey.equals((TangoEvent.DESCRIPTION_COLOR_OVER_EXPOSED))) {
                sendMessage("The Camera is overexposed. Please try facing somewhere with less direct light.");
            }
            if (tangoEvent.eventKey.equals(TangoEvent.DESCRIPTION_FISHEYE_UNDER_EXPOSED) ||
                    tangoEvent.eventKey.equals((TangoEvent.DESCRIPTION_COLOR_UNDER_EXPOSED))) {
                sendMessage("Fisheye Lens is underexposed. Please try facing somewhere with more light.");
            }

        }
    });
}

我讨厌呕吐这样的代码,但是我已经尝试了几个星期才能让深度感应工作,但onXYZijAvailable回调只是拒绝被调用,而且我在我的绳索结束了。

可能存在的一个问题是该应用程序使用Vuforia进行一些额外的增强现实功能,并可以访问彩色相机和相机预览,但我没有在Tango文档中看到任何建议这可能会导致问题。

非常感谢能帮助我的人。

0 个答案:

没有答案