问题描述
我正在尝试创建一个小应用程序,它既可以检索深度数据,也可以从我的RGB相机中显示一些“预览”。 这是我的MainScreen类的代码:
private static final String TAG = MainScreen.class.getSimpleName();
public static TangoConfig mConfig;
public static Tango mTango;
public TangoCameraPreview preview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
preview = new TangoCameraPreview(this);
ViewGroup layout = (ViewGroup)findViewById(R.id.content_main_screen);
layout.addView(preview);
}
@Override
protected void onDestroy() {
super.onDestroy();
preview.disconnectFromTangoCamera();
mTango.disconnect();
}
@Override
protected void onPause() {
super.onPause();
preview.onPause();
synchronized (this) {
try {
mTango.disconnect();
} catch (TangoErrorException e) {
Log.e(TAG, getString(R.string.exception_tango_error), e);
}
}
}
@Override
protected void onResume() {
super.onResume();
mTango = new Tango(MainScreen.this, new Runnable() {
@Override
public void run() {
synchronized (MainScreen.this) {
try {
mConfig = setupTangoConfig(mTango);
mTango.connect(mConfig);
preview.connectToTangoCamera(mTango, TangoCameraIntrinsics.TANGO_CAMERA_COLOR);
startupTango();
} catch (TangoOutOfDateException e) {
Log.e(TAG, getString(R.string.exception_out_of_date), e);
} catch (TangoErrorException e) {
Log.e(TAG, getString(R.string.exception_tango_error), e);
} catch (TangoInvalidException e) {
Log.e(TAG, getString(R.string.exception_tango_invalid), e);
}
}
}
});
preview.onResume();
}
private TangoConfig setupTangoConfig(Tango tango) {
TangoConfig config = tango.getConfig(TangoConfig.CONFIG_TYPE_DEFAULT);
config.putBoolean(TangoConfig.KEY_BOOLEAN_LOWLATENCYIMUINTEGRATION, true);
config.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true);
config.putInt(TangoConfig.KEY_INT_DEPTH_MODE, TangoConfig.TANGO_DEPTH_MODE_POINT_CLOUD);
return config;
}
private void startupTango() {
final ArrayList<TangoCoordinateFramePair> framePairs =
new ArrayList<TangoCoordinateFramePair>();
mTango.connectListener(framePairs, new Tango.OnTangoUpdateListener() {
@Override
public void onPoseAvailable(final TangoPoseData pose) {
// We are not using TangoPoseData for this application.
}
@Override
public void onXyzIjAvailable(TangoXyzIjData xyzIj) {
// We are not using onXyzIjAvailable for this app.
}
@Override
public void onPointCloudAvailable(final TangoPointCloudData pointCloudData) {
logPointCloud(pointCloudData);
}
@Override
public void onTangoEvent(final TangoEvent event) {
// Ignoring TangoEvents.
}
@Override
public void onFrameAvailable(int cameraId) {
if(cameraId == TangoCameraIntrinsics.TANGO_CAMERA_COLOR) {
preview.onFrameAvailable();
}
}
});
}
private void logPointCloud(TangoPointCloudData pointCloudData) {
Log.i(TAG, String.format(getString(R.string.log_pointcloud_data),
pointCloudData.numPoints,
calculateAveragedDepth(pointCloudData.points, pointCloudData.numPoints)));
}
private float calculateAveragedDepth(FloatBuffer pointCloudBuffer, int numPoints) {
float totalZ = 0;
float averageZ = 0;
if (numPoints != 0) {
int numFloats = 4 * numPoints;
for (int i = 2; i < numFloats; i = i + 4) {
totalZ = totalZ + pointCloudBuffer.get(i);
}
averageZ = totalZ / numPoints;
}
return averageZ;
}
当我启动此代码时,TangoCameraPreview保持为空,并且永远不会调用onFrameAvailable() - Method。
我在我的Android清单xml中包含了Camera persmissions,但它仍然没有调用处理程序。
可悲的是,我没有找到关于这个主题的任何好的教程,因为这只是我项目的第一步,我不想写我自己的渲染器,如果有的话。
可能是什么问题呢?
1楼
在启动Tango之后调用'connectTextureId':
tango.ConnectTextureId(TangoCameraIntrinsics.TangoCameraColor, -1);