Unreal 中的 QR 码QR codes in Unreal

概述Overview

HoloLens 2 可以使用网络摄像头查看世界空间中的 QR 码,这会在每个代码的实际位置使用坐标系统将其呈现为全息影像。The HoloLens 2 can see QR codes in world space using the webcam, which renders them as holograms using a coordinate system at each code's real-world position. 除了单个 QR 码,HoloLens 2 还可以在多个设备上的同一位置呈现全息影像,以创建共享体验。In addition to single QR codes, HoloLens 2 can also render holograms in the same location on multiple devices to create a shared experience. 请确保遵循将 QR 码添加到应用程序的最佳做法:Make sure you're following the best practices for adding QR codes to your applications:

  • 安静区域Quiet zones
  • 照明和背景Lighting and backdrop
  • 大小、距离和角度位置Size, distance, and angular position

将 QR 码置于应用中时,请特别注意环境注意事项Pay special attention to the environment considerations when QR codes are being placed in your app. 有关每个主题的详细信息以及下载所需 NuGet 包的说明,请参阅主 QR 码跟踪文档。You can find more information on each of these topics and instructions on how to download the required NuGet package in the main QR code tracking document.

启用 QR 检测Enabling QR detection

由于 HoloLens 2 需要使用网络摄像头来查看 QR 码,因此需要在项目设置中将其启用:Since the HoloLens 2 needs to use the webcam to see QR codes, you'll need to enable it in the project settings:

  • 打开“编辑”>“项目设置”,滚动到“平台”部分,然后单击“HoloLens”。Open Edit > Project Settings, scroll to the Platforms section and click HoloLens.
    • 展开“功能”部分,选中“网络摄像头”。Expand the Capabilities section and check Webcam.  

还需要通过添加 ARSessionConfig 资产来选择使用 QR 码跟踪。You'll also need to opt into QR code tracking by adding an ARSessionConfig asset.

使用之前,应调用 UHoloLensARFunctionLibrary::StartCameraCapture() 来手动启用跟踪。Right before the usage, you should manually enable the tracking by calling UHoloLensARFunctionLibrary::StartCameraCapture(). 结束 QR 码跟踪后,应通过 UHoloLensARFunctionLibrary::StopCameraCapture() 禁用它以节省设备资源。After ending the QR code tracking, you should disable it by UHoloLensARFunctionLibrary::StopCameraCapture() to save the device resources.

设置跟踪图像Setting up a tracked image

QR 码通过 Unreal 的 AR 跟踪几何系统显示为跟踪图像。QR codes are surfaced through Unreal’s AR tracked geometry system as a tracked image. 若要实现此操作,需执行以下操作:To get this working, you'll need to:

  1. 创建蓝图,并添加“ARTrackableNotify”组件。Create a Blueprint and add an ARTrackableNotify component.

QR AR 可跟踪通知

  1. 选择“ARTrackableNotify”,然后在“详细信息”面板中展开“事件”部分。Select ARTrackableNotify and expand the Events section in the Details panel.

QR 事件

  1. 单击“关于添加跟踪几何”旁的 +,将节点添加到事件图中。Click + next to On Add Tracked Geometry to add the node to the Event Graph.

向“关于添加跟踪几何”添加节点

使用跟踪图像Using a tracked image

下图中的事件图显示了 OnUpdateTrackedImage 事件,该事件用于呈现 QR 码中心的一个点并输出其数据。The Event Graph in the following image shows the OnUpdateTrackedImage event being used to render a point in the center of a QR code and print out its data.

QR 呈现示例

以下是具体过程:Here's what's going on:

  1. 首先,将跟踪图像转换为 ARTrackedQRCode,以检查当前更新的图像是否为 QR 码。First, the tracked image is cast to an ARTrackedQRCode to check that the current updated image is a QR code.
  2. 编码数据是从 QRCode 变量中检索的。The encoded data is retrieved from the QRCode variable. 可以从 GetLocalToWorldTransform 位置获取左上方的 QR 码,并在 GetEstimateSize 中获取维度。You can get the top-left of the QR code from the location of GetLocalToWorldTransform and the dimensions with GetEstimateSize.

还可以在代码中获取 QR 码的坐标系统You can also get the coordinate system for a QR code in code.

查找唯一 IDFinding the unique ID

每个 QR 码都具有一个唯一的 GUID ID,可以通过以下方式查找:Every QR code has a unique guid ID, which you can find by:

  • 拖放“作为 ARTracked QRCode”引脚并搜索“获取唯一 ID”。Dragging and dropping the As ARTracked QRCode pin and searching for Get Unique ID.

QR GUID

QR 码幕后还有很多内容等待挖掘,因此体验之旅并没有就此结束。There's a lot going on behind the scenes with QR codes, so this isn't the end of the road. 请务必查看下面的链接,以了解更多详细信息。Be sure to check out the following links for more details on what's under the hood.

下一个开发检查点Next Development Checkpoint

如果你遵循我们规划的 Unreal 开发检查点历程,则你处于探索混合现实平台功能和 API 的过程之中。If you're following the Unreal development checkpoint journey we've laid out, you're in the midst of exploring the Mixed Reality platform capabilities and APIs. 从这里,你可以进入下一主题:From here, you can proceed to the next topic:

或直接跳到在设备或模拟器上部署应用:Or jump directly to deploying your app on a device or emulator:

你可以随时返回到 Unreal 开发检查点You can always go back to the Unreal development checkpoints at any time.

另请参阅See also