Hello_Depth_Perception 任务二:Project Tango采集深度感知数据

 Java API Depth Perception Tutorial深度感知教程

Configuration 配置信息

In order to use depth perception, your TangoConfig must have KEY_BOOLEAN_DEPTH set to true. In the default TangoConfigKEY_BOOLEAN_DEPTH is set to false.

为了使用深度感知,你的TangoConfig必须将KEY_BOOLEAN_DEPTH设为真。

 
try {
    mConfig = new TangoConfig();
    mConfig = mTango.getConfig(TangoConfig.CONFIG_TYPE_CURRENT);
    mConfig.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true);
} catch (TangoErrorException e) {
    // handle exception
}

Define the callback定义回调

The caller is responsible for allocating memory, which will be released after the callback function has finished.

调用方负责分配内存空间,该空间将在该回调函数结束之后释放。

 
private void setTangoListeners() {
    final ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
    framePairs.add(new TangoCoordinateFramePair(
        TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
        TangoPoseData.COORDINATE_FRAME_DEVICE));

    // Listen for new Tango data
    mTango.connectListener(framePairs, new OnTangoUpdateListener() {

        @Override
        public void onXyzIjAvailable(TangoXyzIjData arg0) {
            byte[] buffer = new byte[xyzIj.xyzCount * 3 * 4]; //文件流输入缓冲区
            FileInputStream fileStream = new FileInputStream(
                     xyzIj.xyzParcelFileDescriptor.getFileDescriptor()); //xyzIj的定义在哪里?输入xyzIj的文件路径
            try {
                fileStream.read(buffer,
                        xyzIj.xyzParcelFileDescriptorOffset, buffer.length);
                fileStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            // Do not process the buffer inside the callback because不要处理该回调中的缓冲,因为
            // you will not receive any new data while it processes在处理中你接收不到任何新数据
        }

        @Override
        public void onPoseAvailable(final TangoPoseData pose) {
            // Process pose data from device with respect to start of service
        }

        @Override
        public void onTangoEvent(final TangoEvent event) {
            // This callback also has to be here
        }
    });
}

Define the onXYZijAvailable() callback. Do not do any expensive processing on the data within the callback; you will not receive new data until the callback returns.

定义onXYZijAvailable()回调。不要在回调中做任何高消耗的数据处理。你只有在回调返回时才能接收新数据。

原文地址:https://www.cnblogs.com/2008nmj/p/7218743.html