首页 > 编程 > Java > 正文

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

2019-11-09 19:01:11
字体:
来源:转载
供稿:网友

配置定义回调以下是原文ConfigurationDefine the callback

原文链接: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.


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表