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