Hello_Area_Description 任务三:Project Tango采集区域描述数据
Permission Dialogs for Users in Java在Java中用户使用的权限对话框
Tango works by using visual cues from the device's cameras. We want users to understand when and why the cameras are being used, so you must ask users for permission prior to using area learning or displaying the camera preview.
Tango通过使用设备的摄像头中的视觉信号来工作。我们希望用户能理解摄像头什么时候和为什么被使用,因此在使用区域学习或者展示摄像头预览之前你必须请求用户权限许可。
TangoService will not work without the user's permission in these cases.
TangoService在这些例子中如果没有用户的许可将无法工作。
How to request user permission如何请求用户许可
Android Camera permission安卓摄像头许可
Applications that intend to use depth perception or show the camera preview must request the Android Camerapermission in their manifest to get access to the camera feed through the Tango API.要使用深度感知或者显示摄像头预览的应用必须在manifest中请求Android Camera许可来通过Tango API获得摄像头反馈。
ADF permissionsADF文件许可
ADF Load/Save intent ADF加载/保存意图
To request load/save permission, call the following Android permission intent. If the user hasn't given permission, this intent will show a popup asking for the permission. If you call this intend and the user already gave permission, no popup will be shown.
要请求加载/保存许可,必须调用下面的Android的许可意图。如果用户没有给出许可,该意图将显示一个弹出框请求该许可。如果你调用该意图并且用户已经给出许可,那么将不会显示弹出框。
startActivityForResult(
Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_ADF_LOAD_SAVE),
Tango.TANGO_INTENT_ACTIVITYCODE);
ADF Import intent ADF导入意图
Use Tango.importAreaDescriptionFile()
to import an ADF from the filesystem. A permission screen will appear each time you call the method.
使用Tango.importAreaDescriptionFile()从文件系统中导入ADF文件。每当你调用该方法时将会出现一个许可屏幕。
You can also create the intent yourself:
你还可以创自己建意图。
private static final String INTENT_CLASSPACKAGE = "com.projecttango.tango";
private static final String INTENT_IMPORTEXPORT_CLASSNAME = "com.google.atap.tango.RequestImportExportActivity";
// startActivityForResult requires a code number.
private static final String EXTRA_KEY_SOURCEFILE = "SOURCE_FILE";
Intent importIntent = new Intent();
importIntent.setClassName(INTENT_CLASSPACKAGE, INTENT_IMPORTEXPORT_CLASSNAME);
importIntent.putExtra(EXTRA_KEY_SOURCEFILE, filepath);
thisActivity.startActivityForResult(importIntent, Tango.TANGO_INTENT_ACTIVITYCODE);
ADF Export intent ADF导出意图
Use Tango.exportAreaDescriptionFile()
to export an ADF to the filesystem. A permission screen will appear for each intent you send.
使用Tango.exportAreaDescriptionFile()导出ADF到文件系统。一个许可屏幕将在每次你发送的意图时出现。
You can also create the intent yourself:
你也可以创建你自己的意图:
private static final String INTENT_CLASSPACKAGE = "com.projecttango.tango";
private static final String INTENT_IMPORTEXPORT_CLASSNAME = "com.google.atap.tango.RequestImportExportActivity";
// startActivityForResult requires a code number.
private static final String EXTRA_KEY_SOURCEUUID = "SOURCE_UUID";
private static final String EXTRA_KEY_DESTINATIONFILE = "DESTINATION_FILE";
Intent exportIntent = new Intent();
exportIntent.setClassName(INTENT_CLASSPACKAGE, INTENT_IMPORTEXPORT_CLASSNAME);
exportIntent.putExtra(EXTRA_KEY_SOURCEUUID, mUUIDList[info.position]);
exportIntent.putExtra(EXTRA_KEY_DESTINATIONFILE, mAppSpaceADFFolder);
thisActivity.startActivityForResult(exportIntent, Tango.TANGO_INTENT_ACTIVITYCODE);
API exceptions API例外
If you try to call a method that requires a permission that has not been granted, the Java API throws aSecurityException with a detailed message corresponding to the permission that failed.
如果你试着调用一个方法,它需要一个许可但是却并没有被授予,那么Java API将会抛出一个安全例外带有跟许可失败相关的详细信息。
API calls that require permission需要许可的API调用
The following calls in the Java API require the user's permission.
下面的调用都需要用户许可。
API calls that require Tango.PERMISSIONTYPE_ADF_LOAD_SAVE需要Tango.PERMISSIONTYPE_ADF_LOAD_SAVE的API调用
Tango.saveAreaDescription
Tango.deleteAreaDescription
Tango.listAreaDescriptions
Tango.loadAreaDescriptionMetaData
Tango.saveAreaDescriptionMetadata
API calls that require Android Camera permissions需要Android Camera许可的API调用
Tango.getCameraIntrinsics
onXYZijAvailable
callback ofTango.OnTangoUpdateListener
onFrameAvailable
callback ofTango.OnTangoUpdateListener
Tango.connectTextureId
Tango.disconnectCamera
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
上次更新日期:六月 10, 2016
代码
public class HelloAreaDescriptionActivity extends Activity implements
SetAdfNameDialog.CallbackListener,
SaveAdfTask.SaveAdfListener { private static final String TAG = HelloAreaDescriptionActivity.class.getSimpleName();
private static final int SECS_TO_MILLISECS = 1000;
private Tango mTango;
private TangoConfig mConfig;
private TextView mUuidTextView;
private TextView mRelocalizationTextView; private Button mSaveAdfButton; private double mPreviousPoseTimeStamp;
private double mTimeToNextUpdate = UPDATE_INTERVAL_MS; private boolean mIsRelocalized;
private boolean mIsLearningMode;
private boolean mIsConstantSpaceRelocalize; // Long-running task to save the ADF.
private SaveAdfTask mSaveAdfTask; private static final double UPDATE_INTERVAL_MS = 100.0; private final Object mSharedLock = new Object(); @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_area_learning);
Intent intent = getIntent();
mIsLearningMode = intent.getBooleanExtra(StartActivity.USE_AREA_LEARNING, false);
mIsConstantSpaceRelocalize = intent.getBooleanExtra(StartActivity.LOAD_ADF, false);
} @Override
protected void onResume() {
super.onResume(); // Initialize Tango Service as a normal Android Service. Since we call mTango.disconnect()
// in onPause, this will unbind Tango Service, so every time onResume gets called we
// should create a new Tango object.每次resume,都会创建一个Tango对象
mTango = new Tango(HelloAreaDescriptionActivity.this, new Runnable() {
@Override
public void run() {
synchronized (HelloAreaDescriptionActivity.this) {
try {
mConfig = setTangoConfig(
mTango, mIsLearningMode, mIsConstantSpaceRelocalize); //设置Tango配置信息
mTango.connect(mConfig); //连接配置信息
startupTango(); //开始Tango()
} catch (TangoOutOfDateException e) {
Log.e(TAG, getString(R.string.tango_out_of_date_exception), e);
showsToastAndFinishOnUiThread(R.string.tango_out_of_date_exception);
} catch (TangoErrorException e) {
Log.e(TAG, getString(R.string.tango_error), e);
showsToastAndFinishOnUiThread(R.string.tango_error);
} catch (TangoInvalidException e) {
Log.e(TAG, getString(R.string.tango_invalid), e);
showsToastAndFinishOnUiThread(R.string.tango_invalid);
} catch (SecurityException e) {
// Area Learning permissions are required. If they are not available,
// SecurityException is thrown.
Log.e(TAG, getString(R.string.no_permissions), e);
showsToastAndFinishOnUiThread(R.string.no_permissions);
}
} runOnUiThread(new Runnable() {
@Override
public void run() {
synchronized (HelloAreaDescriptionActivity.this) {
setupTextViewsAndButtons(mTango, mIsLearningMode,
mIsConstantSpaceRelocalize);
}
}
});
}
});
} @Override
protected void onPause() {
super.onPause(); // 清除重定位状态;我们不知道我们的设备将会在哪里,因为我们的app将会暂停
mIsRelocalized = false;
synchronized (this) {
try {
mTango.disconnect();
} catch (TangoErrorException e) {
Log.e(TAG, getString(R.string.tango_error), e);
}
}
} /**
* Sets Texts views to display statistics of Poses being received. This also sets the buttons
* used in the UI. Note that this needs to be called after TangoService and Config
* objects are initialized since we use them for the SDK-related stuff like version number,
* etc.
*/
private void setupTextViewsAndButtons(Tango tango, boolean isLearningMode, boolean isLoadAdf) {
mSaveAdfButton = (Button) findViewById(R.id.save_adf_button);
mUuidTextView = (TextView) findViewById(R.id.adf_uuid_textview);
mRelocalizationTextView = (TextView) findViewById(R.id.relocalization_textview); if (isLearningMode) {
// Disable save ADF button until Tango relocalizes to the current ADF.
mSaveAdfButton.setEnabled(false);
} else {
// Hide to save ADF button if leanring mode is off.
mSaveAdfButton.setVisibility(View.GONE);
} if (isLoadAdf) {
ArrayList<String> fullUuidList;
// Returns a list of ADFs with their UUIDs.
fullUuidList = tango.listAreaDescriptions();
if (fullUuidList.size() == 0) {
mUuidTextView.setText(R.string.no_uuid);
} else {
mUuidTextView.setText(getString(R.string.number_of_adfs) + fullUuidList.size()
+ getString(R.string.latest_adf_is)
+ fullUuidList.get(fullUuidList.size() - 1));
}
}
} /**
* Sets up the Tango configuration object. Make sure mTango object is initialized before
* making this call.
*/
private TangoConfig setTangoConfig(Tango tango, boolean isLearningMode, boolean isLoadAdf) {
// Use default configuration for Tango Service.
TangoConfig config = tango.getConfig(TangoConfig.CONFIG_TYPE_DEFAULT);
// Check if learning mode.
if (isLearningMode) {
// Set learning mode to config.
config.putBoolean(TangoConfig.KEY_BOOLEAN_LEARNINGMODE, true); }
// Check for Load ADF/Constant Space relocalization mode.
if (isLoadAdf) {
ArrayList<String> fullUuidList;
// Returns a list of ADFs with their UUIDs.
fullUuidList = tango.listAreaDescriptions();
// Load the latest ADF if ADFs are found.
if (fullUuidList.size() > 0) {
config.putString(TangoConfig.KEY_STRING_AREADESCRIPTION,
fullUuidList.get(fullUuidList.size() - 1));
}
}
return config;
} /**
* Set up the callback listeners for the Tango Service and obtain other parameters required
* after Tango connection.
*/
private void startupTango() {
// Set Tango listeners for Poses Device wrt Start of Service, Device wrt
// ADF and Start of Service wrt ADF.
ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
framePairs.add(new TangoCoordinateFramePair(
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_DEVICE));
framePairs.add(new TangoCoordinateFramePair(
TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION,
TangoPoseData.COORDINATE_FRAME_DEVICE));
framePairs.add(new TangoCoordinateFramePair(
TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION,
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE)); mTango.connectListener(framePairs, new OnTangoUpdateListener() { @Override
public void onPoseAvailable(TangoPoseData pose) {
// Make sure to have atomic access to Tango data so that UI loop doesn't interfere
// while Pose call back is updating the data.
synchronized (mSharedLock) {
// Check for Device wrt ADF pose, Device wrt Start of Service pose, Start of
// Service wrt ADF pose (this pose determines if the device is relocalized or
// not).
if (pose.baseFrame == TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION
&& pose.targetFrame == TangoPoseData
.COORDINATE_FRAME_START_OF_SERVICE) {
if (pose.statusCode == TangoPoseData.POSE_VALID) {
mIsRelocalized = true;
} else {
mIsRelocalized = false;
}
}
} final double deltaTime = (pose.timestamp - mPreviousPoseTimeStamp) *
SECS_TO_MILLISECS;
mPreviousPoseTimeStamp = pose.timestamp;
mTimeToNextUpdate -= deltaTime; if (mTimeToNextUpdate < 0.0) {
mTimeToNextUpdate = UPDATE_INTERVAL_MS; runOnUiThread(new Runnable() {
@Override
public void run() {
synchronized (mSharedLock) {
mSaveAdfButton.setEnabled(mIsRelocalized);
mRelocalizationTextView.setText(mIsRelocalized ?
getString(R.string.localized) :
getString(R.string.not_localized));
}
}
});
}
} @Override
public void onXyzIjAvailable(TangoXyzIjData xyzIj) {
// We are not using onXyzIjAvailable for this app.
} @Override
public void onPointCloudAvailable(TangoPointCloudData xyzij) {
// We are not using onPointCloudAvailable for this app.
} @Override
public void onTangoEvent(final TangoEvent event) {
// Ignoring TangoEvents.
} @Override
public void onFrameAvailable(int cameraId) {
// We are not using onFrameAvailable for this application.
}
});
} /**
* Implements SetAdfNameDialog.CallbackListener.
*/
@Override
public void onAdfNameOk(String name, String uuid) {
saveAdf(name);
} /**
* Implements SetAdfNameDialog.CallbackListener.
*/
@Override
public void onAdfNameCancelled() {
// Continue running.
} /**
* The "Save ADF" button has been clicked.
* Defined in {@code activity_area_description.xml}
*/
public void saveAdfClicked(View view) {
showSetAdfNameDialog();
} /**
* Save the current Area Description File.
* Performs saving on a background thread and displays a progress dialog.
*/
private void saveAdf(String adfName) {
mSaveAdfTask = new SaveAdfTask(this, this, mTango, adfName);
mSaveAdfTask.execute();
} /**
* Handles failed save from mSaveAdfTask.
*/
@Override
public void onSaveAdfFailed(String adfName) {
String toastMessage = String.format(
getResources().getString(R.string.save_adf_failed_toast_format),
adfName);
Toast.makeText(this, toastMessage, Toast.LENGTH_LONG).show();
mSaveAdfTask = null;
} /**
* 保存Adf成功处理
*/
@Override
public void onSaveAdfSuccess(String adfName, String adfUuid) {
String toastMessage = String.format(
getResources().getString(R.string.save_adf_success_toast_format),
adfName, adfUuid);
Toast.makeText(this, toastMessage, Toast.LENGTH_LONG).show();
mSaveAdfTask = null;
finish();
} /**
* 显示设置ADF名字的对话框
*/
private void showSetAdfNameDialog() {
Bundle bundle = new Bundle();
bundle.putString(TangoAreaDescriptionMetaData.KEY_NAME, "New ADF");
// ADF保存之后UUID产生
bundle.putString(TangoAreaDescriptionMetaData.KEY_UUID, ""); FragmentManager manager = getFragmentManager();
SetAdfNameDialog setAdfNameDialog = new SetAdfNameDialog();
setAdfNameDialog.setArguments(bundle);
setAdfNameDialog.show(manager, "ADFNameDialog");
} /**
* Display toast on UI thread.在UI线程显示文字
*
* @param resId The resource id of the string resource to use. Can be formatted text. 字符串资源id
*/
private void showsToastAndFinishOnUiThread(final int resId) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(HelloAreaDescriptionActivity.this,
getString(resId), Toast.LENGTH_LONG).show();
finish();
}
});
}
}
ADF里面都有什么 Area Descriptor File区域描述文件
Hello_Area_Description 任务三:Project Tango采集区域描述数据的更多相关文章
- Hello_Motion_Tracking 任务一:Project Tango采集运动追踪数据
我们来看一下中的几个基本的例子 (区域描述.深度感知.运动追踪.视频4个) 参考:Google Tango初学者教程 1. hello_motion_tracking package com.proj ...
- Hello_Depth_Perception 任务二:Project Tango采集深度感知数据
Java API Depth Perception Tutorial深度感知教程 Configuration 配置信息 In order to use depth perception, your T ...
- UE4在Android调用Project Tango
Project Tango应该说是Google一试水AR的设备,其中Project Tango主要二个功能,一个是获取深度信息,如MS的Kinect,有相当多的设备都有这个功能,二是第一人称相对定位, ...
- 巧用 Img / JavaScript 采集页面数据
摘要: 当我们有一个新内容时(例如新功能.新活动.新游戏.新文章),作为运营人员总是迫不及待地希望能尽快传达到用户,因为这是获取用户的第一步.也是最重要的一步. 点此查看原文:http://click ...
- Django项目:CMDB(服务器硬件资产自动采集系统)--07--06CMDB测试Linux系统采集硬件数据的命令02
#settings.py """ Django settings for AutoCmdb project. Generated by 'django-admin sta ...
- C#+HtmlAgilityPack+XPath带你采集数据(以采集天气数据为例子)
第一次接触HtmlAgilityPack是在5年前,一些意外,让我从技术部门临时调到销售部门,负责建立一些流程和寻找潜在客户,最后在阿里巴巴找到了很多客户信息,非常全面,刚开始是手动复制到Excel, ...
- Gobblin采集kafka数据
作者:Syn良子 出处:http://www.cnblogs.com/cssdongl 转载请注明出处 找时间记录一下利用Gobblin采集kafka数据的过程,话不多说,进入正题 一.Gobblin ...
- google project tango 学习笔记
google io 2015上 project tango 的演示视频
- API例子:用Python驱动Firefox采集网页数据
1,引言 本文讲解怎样用Python驱动Firefox浏览器写一个简易的网页数据采集器.开源Python即时网络爬虫项目将与Scrapy(基于twisted的异步网络框架)集成,所以本例将使用Scra ...
随机推荐
- Linux环境安装jdk10
一. 下载jdk 下载方式一:直接在linux上下载 wget --no-check-certificate --no-cookies --header "Cookie: oraclelic ...
- CentOS之NTP服务器配置
本文使用CentOS 6.5作为搭建环境 一.服务器端配置 1.安装所需软件包 yum -y install ntp ntpdate---------------------------------- ...
- Erlang ets -- something about cache continue
上一次说到了实现一个简单cache 的基本思路和想法, http://www.cnblogs.com/--00/p/erlang_ets_something_about_cache.html 在文末, ...
- 使用sublime text3手动安装插件
众所周知,由于网络问题,使用install package可能会连不上服务器,这时候就不得不手动安装插件了. 其实sublime安装插件的原理就是当你搜索一个插件并安装的时候,它回去github找到这 ...
- C++ is-a关系
首先举一个例子: 在日常生活中,我们所说的眼镜大都是带框的眼镜,但是当提起隐形眼镜时,我们想一下它属不属于眼镜呢?答案肯定是属于的.这里的隐形眼镜和眼镜就是属于 is-a 的关系. 在面向对象编程过程 ...
- phpcms 实现动态价格
什么是动态价格(自命名)?—— 一般来说商品有个固定的价格,随着节假日或者促销活动可能会发生价格变化,结束后又恢复原价,如果每次价格变化都需要修改价格,那么不仅在时间上不好把握,也需要消耗更多的人力 ...
- 好记性不如烂笔头-linux学习笔记6keepalived实现主备操作
Keepalived的作用是检测服务器的状态,如果有一台web服务器宕机,或工作出现故障,Keepalived将检测到,并将有故障的服务器从系统中剔除,同时使用其他服务器代替该服务器的工作,当服务器工 ...
- ES6系列_7之箭头函数和扩展
1.默认值 在ES6中给我们增加了默认值的操作相关代码如下: function add(a,b=1){ return a+b; } console.log(add(1)); 可以看到现在只需要传递一个 ...
- Sql语句在线转java bean https://www.bejson.com/othertools/sql2pojo/
https://www.bejson.com/othertools/sql2pojo/
- 关于hibernate4.3版本之后org.hibernate.service.ServiceRegistryBuilder被弃用
之前一直都是使用hibernate4.2.21的我,有一天突然没有使用本地的jar包而是让IDEA自动下载最新版本的hibernate5.2.2之后,发现有几个经常使用的方法报错了. -这真是让我惊了 ...