Help Center/ Huawei HiLens/ Best Practices/ Developing a Safety Helmet Detection Skill (with an External IPC)
Updated on 2023-06-15 GMT+08:00

Developing a Safety Helmet Detection Skill (with an External IPC)

A HiLens Kit device has a built-in camera. It can also connect to external Internet protocol cameras (IPCs) with a resolution of 1080p or lower.

This chapter uses the safety helmet detection skill template on the Huawei HiLens console as an example to describe how to connect an IPC to a HiLens Kit device, run the safety helmet detection skill on the HiLens Kit device, and use the POST method to output the results.

Before you start, make the preparations described in Preparations. To develop a skill, perform the following steps:

Preparations

  • Make sure your HUAWEI CLOUD account is not in arrears or frozen.
  • Purchase a HiLens Kit device and prepare the network cable, computer (PC), router, HDMI cable, and display.
  • Register the HiLens Kit device with the Huawei HiLens console. For details, see Registering HiLens Kit Devices in the Huawei HiLens User Guide.
  • Ensure that Python has been installed on the local PC.

Step 1: Connect an External IPC

Ensure that the IPC, local PC, and HiLens Kit device are in the same network segment. That is, the network segment configured for the IPC is the network segment where the HiLens Kit device is located in the networking. For details about the networking configuration, see User Guide > Wireless Network Configuration and User Guide > Wired Network Configuration.

  1. Use a network cable to connect the IPC to the PC, and connect the PC to a wireless network.
  2. Change the IP address of your PC so that it is in the same network segment as that of the IPC.

    1. Choose Network and Sharing Center > Change adapter settings on the PC.
    2. In the Network Connections window, right-click the Ethernet connection and choose Properties.
    3. Double-click Internet Protocol Version 4 and select Use the following IP address. Then, enter an IP address that is in the same network segment as the IPC and click the Subnet mask text box to automatically generate a subnet mask. Click OK.
      Figure 1 Changing the IP address of an IPC

      For example, if the default IP address of the IPC is 192.168.1.1 and the default gateway is 255.255.255.0, the IP address in the same network segment as that of the IPC is 192.168.1.X, where X is an integer from 2 to 255 except 111. In this case, you can change the local IP address of the PC to 192.168.1.55.

  3. Open the cmd window and enter the ipconfig command to check the IPv4 address, subnet mask, and default gateway of the wireless network connected to the PC. The IPv4 address is the network segment of the router connected to the PC.
  4. Open the browser, enter the IP address of the IPC, and change the IP address to be in the same network segment as the router.

    For example, assume that the IP address of the IPC is 192.168.1.1, and the IPv4 address of the wireless network connected to the PC queried in the previous step is 192.168.137.101. Enter 192.168.1.1 in the address box of the browser and change the IP address of the IPC to 192.168.137.7 in the basic settings page so that it is in the same network segment 192.168.137.X as the IP address of the wireless network connected to the PC.

  5. Disconnect the network cable between the IPC and the PC in step 1, use network cables to connect the IPC to the router and the HiLens Kit device to the PC, as shown in Figure 2.

    Figure 2 Connection with an external IPC

Step 2: Create a Skill

  1. Log in to the Huawei HiLens console (basic edition), and choose Skill Development > Skills.
  2. On the Basic Skills tab, click Create Skill in the upper right corner. The Create Skill page is displayed.
  3. Click Select Template for Skill Templates. The Select Skill Template dialog box is displayed.
  4. Select the Safety Helmet Detection template and click OK.

    The area for editing the skill content on the Create Skill page is displayed. The default configuration of the selected template is automatically loaded. You can view the related information on the right pane of the page.

  5. Specify Name, Skill Version, and Application Scenario based on User Guide > Create a Skill.
  6. Confirm the information, and click OK.

Step 3: Install the Skill

  1. Log in to the Huawei HiLens console, choose Skill Development > Skills in the left navigation pane. The Skills page is displayed.
  2. Select the skill created in Create a Skill and click Install in the Operation column.
  3. In the dialog box that is displayed, select the device to which the skill is to be installed and click Install.

    When the progress bar displays a message indicating that the installation is successful, the skill is successfully installed on the HiLens Kit device.

Step 4: Configure Cameras

  1. In the navigation pane, choose Device Management > HiLens Kit and select the card of the device where the skill is installed.

    The device details page is displayed.

  2. On the device details page, click Camera Management.

    The Camera Management tab page is displayed.

  3. Click Add Camera and enter information about the external IPC according to Table 1.

    Table 1 Camera configurations

    Parameter

    Description

    Name

    Name of a camera, which is used for identification. This parameter is user-defined.

    User Name

    Username for logging in to the IPC. You can obtain it from the camera's user manual.

    Password

    Password for logging in to the IPC.

    Protocol

    Protocol used by the camera to transmit videos. The default value is rtsp and cannot be changed.

    Path

    URL for accessing videos shot by the camera, for example, 192.168.0.1/root. Obtain the value from the camera's user manual (set it to the path provided by the IPC vendor).

  4. After entering and confirming the information, click OK to add the camera and deliver the configurations to the device. A row of camera information exists on the Camera Management page.
  5. On the device details page, click Manage Skill to switch to the Manage Skill tab page.
  6. Select the skill created in Create a Skill and click Runtime Configuration in the Operation column.
  7. Set runtime configuration parameters according to Table 2, and click Execute Configuration.

    Table 2 Runtime configuration parameters

    Parameter

    Description

    server_url

    Server IP address used to receive the POST data. You can run the config command in the cmd command-line interface (CLI) to query the address, which is IPv4 address + port of the wireless network connected to the PC in Step 1: Connect an External IPC.

    For example, if the IPv4 address of the PC wireless network is 192.168.137.101, enter http://192.168.137.101:8080 here.

    IPC_address

    Address of the IPC. In this example, enter the Name of the added camera. For details, see Table 1.

Step 5: View the Skill Output Data

If Python is not installed on the local PC, install Python on the local PC.

  1. Enter cmd to open the CLI and run the pip install flask command to install the flash library of Python on the local PC.
    Figure 3 Installing flask
  2. Log in to the Huawei HiLens console. In the navigation pane, choose Skill Development > Skill Templates.
  3. On the Skill Templates > All page, enter "safety helmet detection" in the search box and click the card of the Safety Helmet Detection template.
  4. On the details page of the Safety Helmet Detection template, click Download Template, save the template to the local PC, and decompress it.
  5. Open the cmd CLI, go to the ../safety helmet detection template/safety helmet detection template/server.py directory of the server.py file in the skill template, and run python server.py.
  6. On the Manage Skill tab page of the device details page, select the skill created in Create a Skill and click Start in the Operation column.

    After the skill is started, its status changes to Running.

  7. View the skill data output by POST.

    Method 1: In the CLI that runs python server.py in step 4, you can view the box information output by POST.

    Method 2: In the ../safety helmet detection template/safety helmet detection template directory where the server.py file resides in the downloaded Safety Helmet Detection template, you can view the images of faces not wearing safety helmets.

    Figure 4 Skill effect