Tango 开发指南 — 深度感知 API (Java 描述)

原文链接:https://developers.google.com/tango/apis/java/java-depth-perception

配置

要使用深度感知技术,TangoConfig.KEY_BOOLEAN_DEPTH 配置项必须为 true,该项默认为 false。

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

定义回调

调用方负责分配内存空间,回调方法执行完毕之后该空白将被释放。

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());
            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
        }
    });
}

onXYZijAvailable() 即为回调方法。切勿在回调方法中对数据做繁重的计算操作;回调执行完毕后,才会接收到新的数据。

以下是原文

Configuration

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

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());
            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.

public class TangoPointCloudData implements Parcelable {
    public double timestamp;
    public int numPoints;
    public FloatBuffer points;
}

3个核心字段:

  • timestamp,获得4元组的时间戳;
  • numPoints,4元组的数量;
  • points,4元组集合,(x, y, z, c),竖直方向放置设备时,x 为正表示用户的右手方向,y 为正表示屏幕底部方向,z 为正表示摄像头焦距方向且垂直于摄像头平面,近似取 z 为某点距离,c 为置信系数,区间[0, 1],1 表示完全可信;

参考:https://developers.google.com/tango/apis/java/reference/TangoPointCloudData

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值