Help Center> Huawei HiLens> SDK Reference> Resource Management> Example - Resource Management
Updated on 2023-06-15 GMT+08:00

Example - Resource Management

The following is an example of resource management:

#include <cstdio>
#include <hilens.h>
#include <string>

using namespace hilens;
using namespace cv;

void ResourceManage() {
  // Obtain the skill workspace path (with a slash (/) at the end).
  auto skill_path = hilens::GetWorkspacePath();

  // Obtain the skill model path (with a slash (/) at the end).
  auto model_path = hilens::GetModelDirPath();

  // Obtain the skill configuration. If no information is obtained, None is returned.
  auto skill_config = hilens::GetSkillConfig();
  // Assume that face_dataset is a skill configuration item and its value is the directory of face_dataset.zip in OBS.
  // Configure the skill by referring to User Guide.
  auto face_dataset_url = skill_config["face_dataset"]["value"].asString();
  // Download the file from OBS to the skill workspace directory, and check whether the file is successfully downloaded based on the return value.
  auto ret =
      hilens::DownloadFileFromOBS(face_dataset_url, hilens::GetWorkspacePath());
  if (ret != hilens::OK) {
    hilens::Error("Failed to download from obs");
  }

  // Create a folder in the skill workspace directory and decompress the downloaded file.
  std::string cmd = "mkdir " + hilens::GetWorkspacePath() + "face_dataset";
  auto result = system(cmd.c_str());
  if (result != 0) {
    hilens::Error("Failed to mkdir");
  }

  cmd = "unzip " + hilens::GetWorkspacePath() + "face_dataset.zip  -d " +
        hilens::GetWorkspacePath() + "face_dataset/";
  result = system(cmd.c_str());
  if (result != 0) {
    hilens::Error("Failed to unzip");
  }
}

int main() {
  auto ret = hilens::Init("hello");
  if (ret != hilens::OK) {
    hilens::Error("Failed to init");
    return -1;
  }

  ResourceManage();

  hilens::Terminate();
  return 0;
}