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 the Java SDK to call the Face Detection API. You can directly call APIs to use SDK functions.
To call an FRS API in an SDK, there are four steps:
Step 1: Subscribe to the Subservice
Step 2: Configure the Environment
Step 3: Modify the Configuration
Preparations
You have registered an account with HUAWEI CLOUD. Your account is not in arrears or frozen.
Step 1: Subscribe to the Subservice
- Log in to the FRS console.
- Click Authorization in the navigation pane on the left. Click Agree on the displayed page to authorize FRS to access data stored on OBS.
- On the displayed Subscription page, select and subscribe to your desired APIs.
In this example, subscribe to the Face Detection API.
Step 2: Configure the Environment
- Download the FRS Java SDK.
In the huaweicloud-sdk-java-frs directory, choose Code > Download ZIP to download frs-sdk-demo.
- Prepare the Java development environment.
- Download the JDK from the Oracle official website and install it.
- Download Eclipse IDE for Java Developers of the latest version from the Eclipse official website and install it.
- Import the FRS Java SDK into a project.
- Copy the downloaded frs-sdk-demo file to the Eclipse project folder.
- Open the project in Eclipse, right-click the project, and choose Properties.
- In the displayed dialog box, click Java Build Path. In the Libraries tab, click Add JARs to add the JAR file in the frs-sdk-demo folder.
Step 3: Modify the Configuration
In this demo, the AK/SK is used for authentication.
- 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.
- Use the AK/SK for authentication.
Change the values of AK and SK of the Main function of frs-sdk-demo to the obtained AK/SK.
Figure 1 Configuring the AK/SK
- 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
Log in to the My Credentials page and choose Access Keys > Add Access Key to obtain it.
sk
Secret access key)
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 need the Face Detection API only, 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 IDE 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 } } ] }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot