您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

(预览中安装并运行空间分析容器) Install and run the spatial analysis container (Preview)

利用空间分析容器,你可以分析实时流式处理视频,以了解人员之间的空间关系、移动和物理环境中对象之间的交互。The spatial analysis container enables you to analyze real-time streaming video to understand spatial relationships between people, their movement, and interactions with objects in physical environments. 容器非常适合用于满足特定的安全性和数据管理要求。Containers are great for specific security and data governance requirements.

先决条件Prerequisites

  • Azure 订阅 - 免费创建订阅Azure subscription - Create one for free
  • 拥有 Azure 订阅后,在 Azure 门户中创建计算机视觉资源 ,获取密钥和终结点。Once you have your Azure subscription, create a Computer Vision resource in the Azure portal to get your key and endpoint. 部署后,单击“转到资源”。After it deploys, click Go to resource.
    • 你将需要创建的资源的密钥和终结点来运行空间分析容器。You will need the key and endpoint from the resource you create to run the spatial analysis container. 稍后将使用密钥和终结点。You'll use your key and endpoint later.

空间分析容器要求Spatial analysis container requirements

若要运行空间分析容器,需要具有 NVIDIA Tesla T4 GPU的计算设备。To run the spatial analysis container, you need a compute device with a NVIDIA Tesla T4 GPU. 建议你使用 GPU 加速 Azure Stack 边缘 ,但该容器在满足最低要求的任何其他台式计算机上运行。We recommend that you use Azure Stack Edge with GPU acceleration, however the container runs on any other desktop machine that meets the minimum requirements. 我们会将此设备称为 "主计算机"。We will refer to this device as the host computer.

Azure Stack Edge 是一种硬件即服务解决方案,是一种支持 AI 的边缘计算设备,具有网络数据传输功能。Azure Stack Edge is a Hardware-as-a-Service solution and an AI-enabled edge computing device with network data transfer capabilities. 有关详细准备和设置说明,请参阅 Azure Stack Edge 文档For detailed preparation and setup instructions, see the Azure Stack Edge documentation.

要求Requirement 说明Description
照相机Camera 空间分析容器与特定相机品牌无关。The spatial analysis container is not tied to a specific camera brand. 照相机设备需要:支持 Real-Time 流式处理协议 (RTSP) 和 h.264 编码,主机计算机可以访问该设备,并可通过15FPS 和1080p 分辨率进行流式处理。The camera device needs to: support Real-Time Streaming Protocol(RTSP) and H.264 encoding, be accessible to the host computer, and be capable of streaming at 15FPS and 1080p resolution.
Linux OSLinux OS Ubuntu Desktop 18.04 LTS 必须安装在主计算机上。Ubuntu Desktop 18.04 LTS must be installed on the host computer.

请求批准以运行容器Request approval to run the container

填写并提交 请求表单 ,请求批准以运行容器。Fill out and submit the request form to request approval to run the container.

通过该表单请求有关你、你的公司以及要使用该容器的用户方案的信息。The form requests information about you, your company, and the user scenario for which you'll use the container. 提交该表单后,Azure 认知服务团队将会对其进行评审,并通过一种决定向你发送电子邮件。After you submit the form, the Azure Cognitive Services team will review it and email you with a decision.

重要

  • 在此表单上,必须使用与 Azure 订阅 ID 关联的电子邮件地址。On the form, you must use an email address associated with an Azure subscription ID.
  • 用于运行容器的计算机视觉资源必须已使用已批准的 Azure 订阅 ID 创建。The Computer Vision resource you use to run the container must have been created with the approved Azure subscription ID.

获得批准后,你将能够在从 Microsoft 容器注册表 (MCR) 下载容器后运行该容器,本文稍后将对此进行介绍。After you're approved, you will be able to run the container after downloading it from the Microsoft Container Registry (MCR), described later in the article.

如果你的 Azure 订阅尚未获得批准,你将无法运行该容器。You won't be able to run the container if your Azure subscription has not been approved.

设置主计算机Set up the host computer

建议为主计算机使用 Azure Stack Edge 设备。It is recommended that you use an Azure Stack Edge device for your host computer. 如果要配置其他设备,请单击 " 台式计算机 "。Click Desktop Machine if you're configuring a different device.

在 Azure Stack Edge 门户上配置计算Configure compute on the Azure Stack Edge portal

空间分析使用 Azure Stack 边缘的计算功能来运行 AI 解决方案。Spatial analysis uses the compute features of the Azure Stack Edge to run an AI solution. 若要启用计算功能,请确保:To enable the compute features, make sure that:

  • 连接并激活 Azure Stack Edge 设备。You've connected and activated your Azure Stack Edge device.
  • 你有运行 PowerShell 5.0 或更高版本的 Windows 客户端系统来访问设备。You have a Windows client system running PowerShell 5.0 or later, to access the device.
  • 若要部署 Kubernetes 群集,需要通过 Azure 门户上的 本地 UI 配置 Azure Stack Edge 设备:To deploy a Kubernetes cluster, you need to configure your Azure Stack Edge device via the Local UI on the Azure portal:
    1. 启用 Azure Stack 边缘设备上的计算功能。Enable the compute feature on your Azure Stack Edge device. 若要启用计算,请在设备的 web 界面中转到 计算 页。To enable compute, go to the Compute page in the web interface for your device.
    2. 选择要为计算启用的网络接口,然后单击 " 启用"。Select a network interface that you want to enable for compute, then click Enable. 这会在设备上的该网络接口上创建一个虚拟交换机。This will create a virtual switch on your device, on that network interface.
    3. 将 Kubernetes 测试节点 IP 地址和 Kubernetes 外部服务 IP 地址留空。Leave the Kubernetes test node IP addresses and the Kubernetes external services IP addresses blank.
    4. 单击“应用”。Click Apply. 此操作可能需要大约两分钟的时间。This operation may take about two minutes.

配置计算

设置边缘计算角色并创建 IoT 中心资源Set up an Edge compute role and create an IoT Hub resource

Azure 门户中,导航到 Azure Stack Edge 资源。In the Azure portal, navigate to your Azure Stack Edge resource. 在 " 概述 " 页或导航列表中,单击 "边缘计算 入门 " 按钮。On the Overview page or navigation list, click the Edge compute Get started button. 在 " 配置边缘计算   " 磁贴中,单击 "配置"。In the  Configure Edge compute tile, click Configure.

链接

在 " 配置边缘计算"   页上,选择现有的 IoT 中心,或选择创建一个新的 IoT 中心。In the Configure Edge compute page, choose an existing IoT Hub, or choose to create a new one. 默认情况下,将使用标准 (S1) 定价层创建 IoT 中心资源。By default, a Standard (S1) pricing tier is used to create an IoT Hub resource. 若要使用免费层 IoT 中心资源,请创建一个,然后选择它。To use a free tier IoT Hub resource, create one and then select it. IoT 中心资源使用的订阅和资源组与 Azure Stack Edge 资源使用的相同The IoT Hub resource uses the same subscription and resource group that is used by the Azure Stack Edge resource

单击“创建”。 Click Create. IoT 中心资源创建可能需要几分钟的时间。The IoT Hub resource creation may take a couple of minutes. 创建 IoT 中心资源后," 配置边缘计算 " 磁贴将更新以显示新的配置。After the IoT Hub resource is created, the Configure Edge compute tile will update to show the new configuration. 若要确认已配置边缘计算角色,请选择 " 配置计算" 磁贴上的 " 查看配置"   。To confirm that the Edge compute role has been configured, select View config on the Configure compute tile.

如果在 Edge 设备上设置了 Edge 计算角色,则会创建两个设备:一个 IoT 设备,一个 IoT Edge 设备。When the Edge compute role is set up on the Edge device, it creates two devices: an IoT device and an IoT Edge device. 可在 IoT 中心资源中查看这两个设备。Both devices can be viewed in the IoT Hub resource. Azure IoT Edge 运行时将已在 IoT Edge 设备上运行。The Azure IoT Edge Runtime will already be running on the IoT Edge device.

备注

在 Azure Stack 边缘上启用 MPSEnable MPS on Azure Stack Edge

  1. 以管理员身份运行 Windows PowerShell 会话。Run a Windows PowerShell session as an Administrator.

  2. 请确保 Windows 远程管理服务在客户端上运行。Make sure that the Windows Remote Management service is running on your client. 在 PowerShell 终端中,使用以下命令In the PowerShell terminal, use the following command

    winrm quickconfig
    

    如果你看到关于防火墙例外的警告,请检查你的网络连接类型,然后查看 Windows 远程管理 文档。If you see warnings about a firewall exception, check your network connection type, and see the Windows Remote Management documentation.

  3. 将变量分配给设备 IP 地址。Assign a variable to the device IP address.

    $ip = "" Replace with the IP address of your device. 
    
  4. 若要将设备的 IP 地址添加到客户端的受信任主机列表中,请使用以下命令:To add the IP address of your device to the client’s trusted hosts list, use the following command:

    Set-Item WSMan:\localhost\Client\TrustedHosts $ip -Concatenate -Force 
    
  5. 在设备上启动 Windows PowerShell 会话。Start a Windows PowerShell session on the device.

    Enter-PSSession -ComputerName $ip -Credential $ip\EdgeUser -ConfigurationName Minishell 
    
  6. 在出现提示时提供密码。Provide the password when prompted. 使用用于登录本地 web UI 的相同密码。Use the same password that is used to sign into the local web UI. 默认的本地 web UI 密码是 Password1The default local web UI password is Password1.

键入 Start-HcsGpuMPS 以在设备上启动 MPS 服务。Type Start-HcsGpuMPS to start the MPS service on the device.

若要帮助排查 Azure Stack Edge 设备的问题,请参阅 Azure Stack Edge 设备的疑难解答For help troubleshooting the Azure Stack Edge device, see Troubleshooting the Azure Stack Edge device

IoT 部署清单IoT Deployment manifest

若要简化多台主机计算机上的容器部署,可以创建部署清单文件来指定容器创建选项和环境变量。To streamline container deployment on multiple host computers, you can create a deployment manifest file to specify the container creation options, and environment variables. 可在 Github 上找到 Azure Stack 边缘其他台式计算机 的部署清单的示例。You can find an example of a deployment manifest for Azure Stack Edge and other desktop machines on Github.

下表显示 IoT Edge 模块使用的各种环境变量。The following table shows the various Environment Variables used by the IoT Edge Module. 你还可以使用中的属性在上面链接的部署清单中设置它们 env spatialanalysisYou can also set them in the deployment manifest linked above, using the env attribute in spatialanalysis:

设置名称Setting Name Value 说明Description
ARCHON_LOG_LEVELARCHON_LOG_LEVEL 信息详细Info; Verbose 日志记录级别,请选择以下两个值之一Logging level, select one of the two values
ARCHON_SHARED_BUFFER_LIMITARCHON_SHARED_BUFFER_LIMIT 377487360377487360 不修改Do not modify
ARCHON_PERF_MARKERARCHON_PERF_MARKER falsefalse 对于性能日志记录,将此值设置为 true,否则应为 falseSet this to true for performance logging, otherwise this should be false
ARCHON_NODES_LOG_LEVELARCHON_NODES_LOG_LEVEL 信息详细Info; Verbose 日志记录级别,请选择以下两个值之一Logging level, select one of the two values
OMP_WAIT_POLICYOMP_WAIT_POLICY 活动PASSIVE 不修改Do not modify
QT_X11_NO_MITSHMQT_X11_NO_MITSHM 11 不修改Do not modify
API_KEYAPI_KEY 你的 API 密钥your API Key 从计算机视觉资源 Azure 门户收集此值。Collect this value from Azure portal from your Computer Vision resource. 可以在资源的 " 密钥和终结点 " 部分中找到它。You can find it in the Key and endpoint section for your resource.
BILLING_ENDPOINTBILLING_ENDPOINT 终结点 URIyour Endpoint URI 从计算机视觉资源 Azure 门户收集此值。Collect this value from Azure portal from your Computer Vision resource. 可以在资源的 " 密钥和终结点 " 部分中找到它。You can find it in the Key and endpoint section for your resource.
EULAEULA acceptaccept 要使容器运行,需要将此值设置为 " 接受 "This value needs to be set to accept for the container to run
DISPLAYDISPLAY :1:1 此值需要与主计算机上的的输出相同 echo $DISPLAYThis value needs to be same as the output of echo $DISPLAY on the host computer. Azure Stack 边缘设备没有显示。Azure Stack Edge devices do not have a display. 此设置不适用This setting is not applicable

重要

必须指定 EulaBillingApiKey 选项运行容器;否则,该容器不会启动。The Eula, Billing, and ApiKey options must be specified to run the container; otherwise, the container won't start. 有关详细信息,请参阅计费For more information, see Billing.

使用你自己的设置和操作选择更新 Azure Stack Edge 设备台式计算机 的部署清单后,可以使用以下 Azure CLI 命令在主计算机上部署容器,如 IoT Edge 模块。Once you update the Deployment manifest for Azure Stack Edge devices or a desktop machine with your own settings and selection of operations, you can use the below Azure CLI command to deploy the container on the host computer, as an IoT Edge Module.

az login
az extension add --name azure-iot
az iot edge set-modules --hub-name "<IoT Hub name>" --device-id "<IoT Edge device name>" --content DeploymentManifest.json --subscription "<subscriptionId>"
参数Parameter 说明Description
--hub-name Azure IoT 中心名称。Your Azure IoT Hub name.
--content 部署文件的名称。The name of the deployment file.
--target-condition 主计算机的 IoT Edge 设备名称。Your IoT Edge device name for the host computer.
-–subscription 订阅 ID 或名称。Subscription ID or name.

此命令将启动部署。This command will start the deployment. 在 Azure 门户中导航到 Azure IoT 中心实例的页面,以查看部署状态。Navigate to the page of your Azure IoT Hub instance in the Azure portal to see the deployment status. 状态可能显示为 417 –设备的部署配置 在设备完成下载容器映像并开始运行之前未设置。The status may show as 417 – The device’s deployment configuration is not set until the device finishes downloading the container images and starts running.

验证部署是否成功Validate that the deployment is successful

有几种方法可用于验证容器是否正在运行。There are several ways to validate that the container is running. 在 Azure 门户上的 Azure IoT 中心实例中的 "空间分析" 模块 IoT Edge 模块设置 中找到 "运行时状态"。Locate the Runtime Status in the IoT Edge Module Settings for the spatial analysis module in your Azure IoT Hub instance on the Azure portal. 验证 运行时状态需的值报告的值 是否 正在运行Validate that the Desired Value and Reported Value for the Runtime Status is Running.

部署验证示例

部署完成并且容器运行后, 主机 会开始将事件发送到 Azure IoT 中心。Once the deployment is complete and the container is running, the host computer will start sending events to the Azure IoT Hub. 如果你使用了这些 .debug 操作的版本,你将看到你在部署清单中配置的每个照相机的可视化工具窗口。If you used the .debug version of the operations, you’ll see a visualizer window for each camera you configured in the deployment manifest. 你现在可以定义要在部署清单中监视的行和区域,然后按照说明重新部署。You can now define the lines and zones you want to monitor in the deployment manifest and follow the instructions to deploy again.

配置空间分析执行的操作Configure the operations performed by spatial analysis

你将需要使用 空间分析操作 来配置容器,使其使用连接相机、配置操作等。You will need to use spatial analysis operations to configure the container to use connected cameras, configure the operations, and more. 对于配置的每个照相机设备,空间分析的操作将生成 JSON 消息的输出流,并将其发送到 Azure IoT 中心的实例。For each camera device you configure, the operations for spatial analysis will generate an output stream of JSON messages, sent to your instance of Azure IoT Hub.

重新部署或删除部署Redeploy or delete the deployment

如果需要更新部署,需要确保已成功部署以前的部署,或者需要删除未完成 IoT Edge 设备部署。If you need to update the deployment, you need to make sure your previous deployments are successfully deployed, or you need to delete IoT Edge device deployments that did not complete. 否则,这些部署将继续,使系统处于错误的状态。Otherwise, those deployments will continue, leaving the system in a bad state. 您可以使用 Azure 门户或 Azure CLIYou can use the Azure portal, or the Azure CLI.

使用容器生成的输出Use the output generated by the container

如果要开始使用容器生成的输出,请参阅以下文章:If you want to start consuming the output generated by the container, see the following articles:

  • 使用所选编程语言的 Azure 事件中心 SDK 连接到 Azure IoT 中心终结点,并接收事件。Use the Azure Event Hub SDK for your chosen programming language to connect to the Azure IoT Hub endpoint and receive the events. 有关详细信息,请参阅 从内置终结点读取设备到云的消息See Read device-to-cloud messages from the built-in endpoint for more information.
  • 在 Azure IoT 中心设置消息路由,将事件发送到其他终结点,或者将事件保存到 Azure Blob 存储等。有关详细信息,请参阅 IoT 中心消息路由Set up Message Routing on your Azure IoT Hub to send the events to other endpoints or save the events to Azure Blob Storage, etc. See IoT Hub Message Routing for more information.

使用录制的视频文件运行空间分析Running spatial analysis with a recorded video file

可对录制的视频或实时视频使用空间分析。You can use spatial analysis with both recorded or live video. 若要对录制的视频使用空间分析,请尝试录制视频文件并将其保存为 "有文件" 文件。To use spatial analysis for recorded video, try recording a video file and save it as an mp4 file. 在 Azure 中创建 blob 存储帐户,或使用现有存储帐户。Create a blob storage account in Azure, or use an existing one. 然后,更新 Azure 门户中的以下 blob 存储设置:Then update the following blob storage settings in the Azure portal: 1. 更改 所需的安全传输 DisabledChange Secure transfer required to Disabled 2. 更改 允许 Blob 公共访问****已启用Change Allow Blob public access to Enabled

导航到 " 容器 " 部分,并创建新容器或使用现有容器。Navigate to the Container section, and either create a new container or use an existing one. 然后将视频文件上传到该容器。Then upload the video file to the container. 展开已上传文件的文件设置,然后选择 " 生成 SAS"。Expand the file settings for the uploaded file, and select Generate SAS. 请确保将 到期日期 设置为足够长的时间以涵盖测试期间。Be sure to set the Expiry Date long enough to cover the testing period. ) 不支持将 允许的协议 设置为 HTTP (HTTPSSet Allowed Protocols to HTTP (HTTPS is not supported).

单击 " 生成 SAS 令牌和 URL " 并复制 "BLOB SAS URL"。Click on Generate SAS Token and URL and copy the Blob SAS URL. 将开头的替换为 https http ,并在支持视频播放的浏览器中测试 URL。Replace the starting https with http and test the URL in a browser that supports video playback.

VIDEO_URL Azure Stack 边缘设备 或其他 桌面计算机 的部署清单中的替换为所有关系图。Replace VIDEO_URL in the deployment manifest for your Azure Stack Edge device or another desktop machine with the URL you created, for all of the graphs. 设置 VIDEO_IS_LIVEfalse ,然后重新部署具有更新清单的空间分析容器。Set VIDEO_IS_LIVE to false, and redeploy the spatial analysis container with the updated manifest. 请参阅以下示例。See the example below.

空间分析模块将开始使用视频文件,并且还会持续自动重放。The spatial analysis module will start consuming video file and will continuously auto replay as well.

"zonecrossing": {
  "operationId" : "cognitiveservices.vision.spatialanalysis-personcrossingpolygon",
  "version": 1,
  "enabled": true,
  "parameters": {
      "VIDEO_URL": "Replace http url here",
      "VIDEO_SOURCE_ID": "personcountgraph",
      "VIDEO_IS_LIVE": false,
        "VIDEO_DECODE_GPU_INDEX": 0,
      "DETECTOR_NODE_CONFIG": "{ \"gpu_index\": 0 }",
      "SPACEANALYTICS_CONFIG": "{\"zones\":[{\"name\":\"queue\",\"polygon\":[[0.3,0.3],[0.3,0.9],[0.6,0.9],[0.6,0.3],[0.3,0.3]], \"threshold\":35.0}]}"
    }
  },

疑难解答Troubleshooting

如果在启动或运行容器时遇到问题,请参阅 遥测和故障排除 ,了解常见问题的步骤。If you encounter issues when starting or running the container, see telemetry and troubleshooting for steps for common issues. 本文还包含有关生成和收集日志以及收集系统运行状况的信息。This article also contains information on generating and collecting logs and collecting system health.

计费Billing

空间分析容器使用 Azure 帐户上的计算机视觉资源将计费信息发送到 Azure。The spatial analysis container sends billing information to Azure, using a Computer Vision resource on your Azure account. 目前可免费使用公共预览版中的空间分析。The use of spatial analysis in public preview is currently free.

Azure 认知服务容器未获得许可,无需连接到计量/计费终结点。Azure Cognitive Services containers aren't licensed to run without being connected to the metering / billing endpoint. 必须始终让容器可以向计费终结点传送计费信息。You must enable the containers to communicate billing information with the billing endpoint at all times. 认知服务容器不会将客户数据(例如正在分析的视频或图像)发送给 Microsoft。Cognitive Services containers don't send customer data, such as the video or image that's being analyzed, to Microsoft.

总结Summary

本文介绍了用于下载、安装和运行空间分析容器的概念和工作流。In this article, you learned concepts and workflow for downloading, installing, and running the spatial analysis container. 综上所述:In summary:

  • 空间分析是适用于 Docker 的 Linux 容器。Spatial analysis is a Linux container for Docker.
  • 将从 Microsoft 容器注册表下载容器映像。Container images are downloaded from the Microsoft Container Registry.
  • 容器映像作为 IoT 模块在 Azure IoT Edge 中运行。Container images run as IoT Modules in Azure IoT Edge.
  • 如何配置容器并将其部署在主机上。How to configure the container and deploy it on a host machine.

后续步骤Next steps