Help Center> Face Recognition Service> Getting Started> Using an SDK for Face Detection
Updated on 2022-07-28 GMT+08:00

Using an SDK for Face Detection

FRS SDKs provide a range of RESTful APIs to simplify development.

This section provides an example of how to use a Java SDK to call the Face Detection API. You can directly call APIs to use SDK functions.

To call an FRS API using an SDK, do the following:

Step 1: Subscribe to the Subservice

Step 2: Configure the Environment

Step 3: Modify the Configuration

Step 4: Call the Service API

Preparations

You have registered an account with HUAWEI CLOUD. Your account cannot be in arrears or frozen.

Step 1: Subscribe to the Subservice

  1. Log in to the FRS console.
  2. Click Authorization in the navigation pane on the left to authorize FRS to access data stored on OBS.
  3. Select and subscribe to your desired APIs.

    In this example, subscribe to the Face Detection API.

Step 2: Configure the Environment

  1. Download the FRS Java SDK.

    Select the huaweicloud-sdk-java-frs directory and choose Code > Download ZIP to download frs-sdk-demo.

  2. Prepare a Java development environment.
  3. Import the FRS Java SDK into the project.
    1. Copy the downloaded frs-sdk-demo file to the Eclipse project folder.
    2. Open the project in Eclipse, right-click the project, and choose Properties.
    3. In the displayed dialog box, click Java Build Path. On the Libraries tab, click Add JARs to add the downloaded JAR file.

Step 3: Modify the Configuration

In this demo, the AK/SK is used for authentication.

  1. Obtain an AK/SK.

    The AK/SK is the access key. To obtain the AK/SK, log in to the My Credentials page, choose Access Keys in the left navigation pane, and click Create Access Key in the right pane.

  2. Use the AK/SK for authentication.

    Change the values of AK and SK of the Main function in the frs-sdk-demo file of the demo project to the obtained AK/SK.

    Figure 1 Configuring the AK/SK
  3. Modify the frs-sdk-demo configuration file.
    Figure 2 frs-sdk-demo file
    Table 1 Parameters in the Main function

    Parameter

    Description

    Value

    ak

    Access Key ID (AK)

    Log in to the My Credentials page and choose Access Keys > Add Access Key to obtain it.

    sk

    Secret access key (SK)

    Log in to the My Credentials page and choose Access Keys > Add Access Key to obtain it.

    endpoint

    Endpoint

    Select the endpoint of the region where the service is enabled.

    region

    Region where the service locates

    Select the region where the service is enabled.

    projectId

    Project ID

    Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

    • The demo contains example calls of all FRS APIs. If you verify the Face Detection API only, you need to comment out or delete other APIs in the Main.java file.
    • Change the image path in detectFaceByObsUrl to the OBS bucket path of the image.

Step 4: Send API Calling Requests

Execute the Main.java file. If status code 200 is displayed on the console, the program is successfully executed.

The face detection result is returned in JSON format.

{
   "faces": [
     {
       "bounding_box": {
         "width": 174,
         "top_left_y": 37,
         "top_left_x": 22,
         "height": 174
       }
     }
   ] 
}