1.适用于 HoloLens 2 的 Azure 云服务1. Azure Cloud Services for HoloLens 2

欢迎使用这一系列教程,这些教程重点介绍如何将 Azure 云服务引入 HoloLens 2 应用程序 。Welcome to this series of tutorials focused on bringing Azure Cloud services into a HoloLens 2 application. 本系列教程包含五个部分,介绍了如何将多个 Azure 云服务集成到 HoloLens 2 的 Unity 项目中 。In this five-part tutorial series, you will learn how to integrate several Azure Cloud services into a Unity project for HoloLens 2. 在每个连续的章节中,都将添加新的 Azure 云服务,以扩展应用程序功能和用户体验,同时还将介绍每种 Azure 云服务的基础知识 。With each consecutive chapter, you will add new Azure Cloud services to expand the application features and user experience, while teaching you the fundamentals of each Azure Cloud service.

备注

本系列教程将重点介绍 HoloLens 2,但由于 Unity 具有跨平台的特性,因此大多数知识也适用于桌面和智能手机应用程序。This tutorial series will focus on the HoloLens 2 but due the cross-platform nature of Unity, most of your learnings will also apply for Desktop and Smartphone applications.

第一个教程向你介绍本系列的目标和每个要使用的 Azure 云服务,以及如何设置初始 Unity 项目。In this first tutorial, you'll be introduced to the goals of the series and each Azure Cloud service you'll be using, as well as setting up the initial Unity project.

在第二个教程“集成 Azure 存储”中,首先介绍将 Azure 存储集成为演示应用程序的持久性解决方案。In the second tutorial, Integrating Azure Storage, you'll start off by integrating Azure Storage as the persistence solution for the demo application. 你还将了解 Blob 存储和表存储之间的差异,准备所需的项目资源并设置场景。You'll also learn the differences between Blob Storage and Table Storage, prepare the needed project resources, setup the scene. 最后,你将学习如何验证读取、更新和删除数据操作。Finally, you'll learn how to verify the read, update, and delete data operations.

继续学习第三个教程集成 Azure 自定义视觉,你将使用 Azure 自定义视觉在 HoloLens 2 应用程序中训练和检测图像。Continuing with the third tutorial, Integrating Azure Custom Vision, you will use Azure Custom Vision to train and detect images in the HoloLens 2 application. 本章首先设置你自己的 Azure 自定义视觉资源,准备场景组成部分,并通过在应用程序内部训练和检测自己的图像来使之付诸实践。The chapter starts off with setting up your own Azure Custom Vision resource, preparing the scene components and getting into action by training and detecting your own images from inside the application.

接下来,你将继续学习第四个教程集成 Azure 空间定位点,并了解 Azure 空间定位点服务以保存和查找位置,了解核心概念,准备必要的资源,设置场景并开始在应用程序中使用新功能。Next you advance in the fourth tutorial, Integrating Azure Spatial Anchors, with exploring Azure Spatial Anchors service to save and find locations, learn the core concepts, prepare necessary resources, setup the scene and start using the new feature in the application.

借助第五个教程将 Azure 机器人服务与 LUIS 集成,你可以通过为应用程序提供一种新的用户交互方法(即自然语言)来完成操作。With the fifth tutorial, Integrating Azure Bot Service with LUIS, you finalize by giving the application a new method of user interaction: natural language! 此功能将通过结合使用 Azure Bot Framework 和语言理解智能服务 (LUIS) 来实现。This feature will be realized by using the Azure Bot Framework together with Language Understanding (LUIS). 最后一章介绍 Azure 机器人服务的基础知识,为加快进程,可使用 Bot Framework Composer 作为零代码解决方案。This final chapter teaches you the basics of Azure Bot Service and to speed up the process you will be using the Bot Framework Composer as a zero code solution. 创建了机器人后,你就可以将其集成到场景中,并在 HoloLens 2 应用程序的最后阶段运行。Once the bot is created, you will integrate it into the scene and give it a run with the final stage of the HoloLens 2 application.

应用程序目标Application goals

在本系列教程中,你将构建一个 HoloLens 2 应用程序,该应用程序可检测图像中的对象并找到其空间位置。In this tutorial series, you will build a HoloLens 2 application that can detect objects from images and find its spatial location. 要设置域语言,请从现在被跟踪对象调用此类实体。To set a domain language, you call such entities from now Tracked Object. 用户可以创建被跟踪对象,以通过计算机视觉和/或空间位置来关联一组图像。The user can create a Tracked Object to either or both associate a set of images via computer vision and/or a spatial location. 所有数据都必须保存到云中。All data must be persisted into the cloud. 此外,应用程序的某些方面也可以通过机器人的自然语言来控制。Furthermore some aspects of the application will be optionally controlled by natural language assisted through a bot.

功能Features

  • 数据和图像的基本管理Basic managing of data and images
  • 图像训练和检测Image training and detection
  • 存储空间位置及其指南Storing a spatial location and guidance to it
  • 机器人助手通过自然语言使用某些功能Bot assistant to use some features via natural language

Azure 云服务Azure Cloud services

你将使用以下 Azure 云服务来实现上述功能:You'll use the following Azure Cloud services to implement the above features:

Azure 存储Azure Storage

使用 Azure 存储作为持久性解决方案。You will use Azure Storage for the persistence solution. 使用该解决方案,你可以将数据存储在表上并上传大型二进制文件(例如图像)。It allows you to store data on a table and upload large binaries like images.

Azure 自定义视觉Azure Custom Vision

借助 Azure 自定义视觉Azure 认知服务的一部分),你可以将被跟踪对象关联到一组图像、训练集上的机器学习模型并检测被跟踪对象 。With Azure Custom Vision (part of the Azure Cognitive Services) you can associate to Tracked Objects a set of images, train a machine learning model on the set and detect the Tracked Object.

Azure 空间定位点Azure Spatial Anchors

若要存储被跟踪对象的位置,并提供指导说明以找到该位置,请使用 Azure 空间定位点To store a Tracked Object location and give a guided directions to find it, you use Azure Spatial Anchors.

Azure 机器人服务Azure Bot Service

该应用程序主要由传统 UI 提供支持,因此你可以使用 Azure 机器人服务添加一些个性并充当新的交互方法。The application is mainly driven by traditional UI, so you use the Azure Bot Service to add some personality and act as a new interaction method.

必备条件Prerequisites

提示

如果你尚未完成入门教程系列,建议先完成这些教程。If you have not completed the Getting started tutorials series yet, it's recommended that you complete those tutorials first.

  • 一台 Windows 10 电脑,其中已安装并配置正确的工具A Windows 10 PC configured with the correct tools installed
  • Windows 10 SDK 10.0.18362.0 或更高版本Windows 10 SDK 10.0.18362.0 or later
  • 一些基本的 C# 编程功能Some basic C# programming ability
  • 一个针对开发配置的 HoloLens 2 设备A HoloLens 2 device configured for development
  • 一个联网的摄像头(如果要通过 Unity 编辑器进行测试)A connected webcam if you like to test from Unity editor
  • Unity Hub,其中已安装 Unity 2019 LTS 并添加了通用 Windows 平台生成支持模块Unity Hub with Unity 2019 LTS installed and the Universal Windows Platform Build Support module added

注意

建议对本系列教程使用 Unity 2019 LTS。The recommended Unity version for this tutorial series is Unity 2019 LTS. 这将取代上述链接的先决条件中所述的任何 Unity 版本要求或建议。This supersedes any Unity version requirements or recommendations stated in the prerequisites linked above.

创建和准备 Unity 项目Creating and preparing the Unity project

在本部分,你将创建一个新的 Unity 项目,并使其准备好用于 MRTK 开发。In this section, you will create a new Unity project and get it ready for MRTK development.

首先,请按照初始化项目和第一个应用程序进行操作,但请忽略在设备上生成应用程序说明;其中操作包括以下步骤:First, follow the Initializing your project and first application, excluding the Build your application to your device instructions, which includes the following steps:

  1. 创建 Unity 项目并为其指定适当的名称,例如 Azure 云教程Creating the Unity project and give it a suitable name, for example, Azure Cloud Tutorials
  2. 切换生成平台Switching the build platform
  3. 导入 TextMeshPro 基本资源Importing the TextMeshPro Essential Resources
  4. 导入混合现实工具包Importing the Mixed Reality Toolkit
  5. 配置 Unity 项目Configuring the Unity project
  6. 创建并设置场景,并为场景提供一个合适的名称,例如 AzureCloudServicesCreating and configuring the scene and give the scene a suitable name, for example, AzureCloudServices

然后,根据更改空间感知显示选项说明将场景的 MRTK 配置配置文件更改为“DefaultHoloLens2ConfigurationProfile”,并将空间感知网格的显示选项更改为“遮挡” 。Then follow the Changing the Spatial Awareness Display Option instructions to change the MRTK configuration profile for your scene to the DefaultHoloLens2ConfigurationProfile and change the display options for the spatial awareness mesh to Occlusion.

安装内置 Unity 包Installing inbuilt Unity packages

在 Unity 菜单中,选择“窗口” > “包管理器”打开“包管理器”窗口,然后选择“AR Foundation”并单击“安装”按钮以安装包 :In the Unity menu, select Window > Package Manager to open the Package Manager window, then select AR Foundation and click the Install button to install the package:

已选择“AR Foundation”的 Unity 包管理器窗口

备注

你要安装 AR Foundation 包,因为在下一部分中导入 Azure 空间定位点 SDK 时必须使用它。You are installing the AR Foundation package because the Azure Spatial Anchors SDK requires it, which you will import in the next section.

导入教程资产Importing the tutorial assets

下载以下 Unity 自定义包,并 按其列出顺序 将其 导入Download and import the following Unity custom packages in the order they are listed:

提示

有关如何导入 Unity 自定义包的提示,可参阅导入混合现实工具包中的说明。For a reminder on how to import a Unity custom package, you can refer to the Import the Mixed Reality Toolkit instructions.

导入教程资产后,“项目”窗口应如下所示:After you have imported the tutorial assets your Project window should look similar to this:

导入教程资产后的 Unity“层次结构”、“场景”和“项目”窗口

备注

如果看到任何有关“WorldAnchor.SetNativeSpatialAnchorPtr(IntPtr)”和“WorldAnchor.GetNativeSpatialAnchorPtr()”即将过时的 CS0618 警告,可忽略这些警告。If you see any CS0618 warnings regarding 'WorldAnchor.SetNativeSpatialAnchorPtr(IntPtr)' and 'WorldAnchor.GetNativeSpatialAnchorPtr()' being obsolete, you can ignore these warnings.

创建和准备场景Creating and preparing the scene

在本部分,你将通过添加一些教程预制件来准备场景。In this section, you will prepare the scene by adding some of the tutorial prefabs.

在“项目”窗口中,导航到“资产” > “MRTK.Tutorials.AzureCloudServices” > “预制件” > “管理器”文件夹 。In the Project window, navigate to Assets > MRTK.Tutorials.AzureCloudServices > Prefabs > Manager folder. 按住 Ctrl 按钮并单击“SceneController”、“RootMenu”和“DataManager”以选择这三个预制件 :While holding down the CTRL button, click on SceneController, RootMenu and DataManager to select the three prefabs:

已选中 SceneController、RootMenu 和 DataManager 预制件的 Unity

SceneController (预制件)包含两个脚本:SceneController (脚本)和 UnityDispatcher (脚本) 。The SceneController (prefab) contains two scripts, SceneController (script) and UnityDispatcher (script). “SceneController”脚本组件包含多个 UX 函数,并简化了照片捕获功能,而 UnityDispatcher 是一个帮助程序类,允许在 Unity 主线程上执行操作 。The SceneController script component contains several UX functions and facilitates the photo capture functionality while UnityDispatcher is a helper class to allow execute actions on the Unity main thread.

“RootMenu (预制件)”是主要的 UI 预制件,它包含通过各种小型脚本组件相互连接的所有 UI 窗口,并控制应用程序的一般 UX 流程。The RootMenu (prefab) is the primary UI prefab that holds all UI windows that are connected to each other through various small script components and control the general UX flow of the application.

“DataManager (预制件)”负责与 Azure 存储通信,下一教程将进一步介绍此内容。The DataManager (prefab) is responsible for talking to Azure storage and will be explained further in the next tutorial.

现在,在仍选中了这三个预制件的情况下,将其拖动到“层次结构”窗口中,以将其添加到场景:Now with the three prefabs still selected, drag them into the Hierarchy window to add them to the scene:

仍然选中新增的 SceneController、RootMenu 和 DataManager 预制件的 Unity

若要将焦点置于场景中的对象上,可以双击“RootMenu”对象,然后再次稍微缩小:To focus in on the objects in the scene, you can double-click on the RootMenu object, and then zoom slightly out again:

已选中 RootMenu 对象的 Unity

提示

如果在场景中看到很大的图标(例如,框住的“T”图标会分散注意力),可以通过将调节器 (Gizmos) 切换到关闭位置来隐藏这些图标。If you find the large icons in your scene, for example, the large framed 'T' icons distracting, you can hide these by toggling the Gizmos to the off position.

配置场景Configuring the scene

在本节中,需要将 SceneManager、DataManager 和 RootMenu 连接在一起,为下面的集成 Azure 存储准备好工作场景 。In this section, you will connect SceneManager, DataManager and RootMenu together to have a working scene to be ready for the following Integrating Azure storage tutorial.

连接对象Connect the objects

在“层次结构”窗口中,选择“DataManager”对象:In the Hierarchy window, select the DataManager object:

已选中 DataManager 对象的 Unity

在“检查器”窗口中,找到“DataManager (脚本)”组件,你将在“On Data Manager Ready ()”事件上看到一个空槽 。In the Inspector window, locate the DataManager (Script) component and you will see an empty slot on the On Data Manager Ready () event. 现在,从“层次结构”窗口将“SceneController”对象拖到“On Data Manager Ready ()”事件 。Now from the Hierarchy window drag the SceneController object into the On Data Manager Ready () event.

添加了 DataManager 事件侦听器的 Unity

你将注意到该事件的下拉菜单变为活动状态,单击下拉菜单并导航到 SceneController,然后在子菜单中选择“Init ()”选项 :You will notice that the dropdown menu of the event became active, click on the dropdown menu and navigate to SceneController and in the sub menu select the Init () option:

添加了 DataManager 事件操作的 Unity

从“层次结构”窗口选择“SceneController”对象,你将在检查器中找到“SceneController (脚本)”组件 。From the Hierarchy window, select the SceneController object, there in the Inspector you will find the SceneController (script) component.

已选中 SceneController 的 Unity

你将看到有几个未填充的字段,让我们对其进行更改。You will see that there are several unpopulated fields, let's change that. 将 DataManager 对象从层次结构移到“数据管理器”字段,并将 RootMenu GameObject 从层次结构移动到“主菜单”字段。Move the DataManager object from the Hierarchy into the Data Manager field and move the RootMenu GameObject from the Hierarchy into the Main Menu field.

已配置 SceneController 的 Unity

现在,你的场景已经准备就绪,可用于下一个教程。Now your scene is ready for the upcoming tutorials. 不要忘记将其保存到你的项目中。Don't forget to save it into your project.

准备项目生成管道Prepare project build pipeline

尽管项目尚未填充内容,但你必须执行一些准备工作,以便项目准备好构建 HoloLens 2。While the project yet has to be filled with content, you have to perform some preparations, so the project is ready for building for HoloLens 2.

1.添加其他所需功能1. Add additional required capabilities

在 Unity 菜单中选择“编辑” > “项目设置...”,打开“项目设置”窗口: In the Unity menu, select Edit > Project Settings... to open the Project Settings window:

Unity 打开“项目设置”

在“项目设置”窗口中,依次选择“播放器”、“发布设置” :In the Project Settings window, select Player and then Publishing Settings:

Unity 的“发布设置”

在“发布设置”中,向下滚动到“功能”部分,仔细检查在教程中最初创建项目时启用的“InternetClient”、“Microphone”和“SpatialPerception”功能是否确实已启用。 In the Publishing Settings, scroll down to the Capabilities section and double-check that the InternetClient, Microphone and SpatialPerception capabilities, which you enabled when you created the project at the beginning of the tutorial, are enabled. 然后启用“InternetClientServer”、“PrivateNetworkClientServer”和“Webcam”功能 :Then, enable the InternetClientServer, PrivateNetworkClientServer, and Webcam capabilities:

Unity 功能

2.将应用部署到 HoloLens 22. Deploy the app to your HoloLens 2

并非你将在本系列教程中使用的所有功能都可以在 Unity 编辑器中运行,这意味着你需要熟悉如何将应用程序部署到 HoloLens 2 设备上。Not all features that you will use in this tutorial series can run inside the Unity editor, this means that you need to be familiar with deploying the application to your HoloLens 2 device.

提示

有关如何生成 Unity 项目并将其部署到 HoloLens 2 的提示,可参阅入门教程 - 在设备上生成应用程序中的说明。For a reminder on how to build and deploy your Unity project to HoloLens 2, you can refer to the Getting started tutorials - Build your application to your device instructions.

3.在 HoloLens 2 上运行该应用,并按照应用中的说明进行操作3. Run the app on your HoloLens 2 and follow the in-app instructions

注意

所有 Azure 服务都使用 Internet,因此请确保你的设备已连接到 Internet。All Azure Services uses the internet, so make sure your device is connected to the internet.

当应用程序在设备上运行时,请接受对以下请求功能的访问权限:When the application is running on your device, accept access to the following requested capabilities:

  • 麦克风Microphone
  • 照相机Camera

聊天机器人和自定义视觉等服务需要上述功能才能正常运行 。These capabilities are required for services like Chat Bot and Custom Vision to function properly.

祝贺Congratulations

本教程介绍了一系列教程,其中介绍了将实现的功能以及如何将 Azure 云服务与 HoloLens 2 应用程序关联。In this tutorial, you were introduced to the tutorial series, learned about the features you will implement and how Azure Cloud services tie in to making your HoloLens 2 application happen. 你已将所需的组件添加到项目中,并为系列本教程准备了场景。You added the required components into the project and prepared the scene for this tutorial series.

下一课将使用 Azure 存储作为基于云的持久性解决方案来存储数据和图像。In the next lesson, you will use Azure storage as a cloud based persistence solution for storing data and images.