2.開発の事前準備

2.1 命令集チェック

windowsの場合は、runtime_check.exeを用いてFMAとAVX命令集の存在有無を確認します。

FMAとAVX命令集をサポートしない場合は,SSE命令集の指定が必要です。

// システムがサポートする命令集を確認する
// FMA/AVXパラメーターを用いてruntime_check.exeを実行させます
// 返り値は"true"の場合は, FMA/AVXは利用可能です。
static bool runtime_check(bool *fma, bool *avx) {
    if (!fma || !avx) {
        return false;
    }
  *fma = true;
    *avx = true;
    char exe[] = "runtime_check.exe ";
    bool is_exist = false;
    if (_access(exe, 0) == 0) {
        is_exist = true;
    }
    if (is_exist) {
        char arg[2][4] = { "FMA", "AVX" };
        PROCESS_INFORMATION pi;
        STARTUPINFO si;
        memset(&pi, 0, sizeof(PROCESS_INFORMATION));
        memset(&si, 0, sizeof(STARTUPINFO));
        si.cb = sizeof(STARTUPINFO);
        si.dwFlags |= STARTF_USESTDHANDLES; // STARTF_USESTDHANDLES is Required.
        si.dwFlags |= STARTF_USESHOWWINDOW;
         si.wShowWindow = SW_HIDE;
        BOOL bSuccess;
        int i;
        for (i = 0; i < 2; i++) {
            SECURITY_ATTRIBUTES saAttr;
            saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
            saAttr.bInheritHandle = TRUE;
            saAttr.lpSecurityDescriptor = NULL;
            HANDLE hChildStdoutRd = NULL;
            HANDLE hChildStdoutWr = NULL; 
            if (!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) {
                printf("cannot create pipe\n");
                return false;
            }
            // Ensure the read handle to the pipe for STDOUT is not inherited.
            if (!SetHandleInformation(hChildStdoutRd, HANDLE_FLAG_INHERIT, 0)) {
                printf("Stdout SetHandleInformation");
                return false;
            }
            si.hStdOutput = hChildStdoutWr;
            si.hStdError = hChildStdoutWr;
            // Requires STARTF_USESTDHANDLES in dwFlags
            // Requires STARTF_USESTDHANDLES in dwFlags
            char *cmd = new char[strlen(exe) + strlen(arg[i]) + 1];
            strcpy(cmd, exe);
            strcat(cmd, arg[i]);
            bSuccess = CreateProcess(
                NULL,   // No module name (use command line)
                cmd,    // Command line
                NULL,   // Process handle not inheritable
                NULL,   // Thread handle not inheritable
                TRUE,   // Set handle inheritance to TRUE
                0,      // No creation flags
                NULL,   // Use parent's environment block
                NULL,   // Use parent's starting directory
                &si,    // Pointer to STARTUPINFO structure
                &pi);   // Pointer to PROCESS_INFORMATION structure
            delete[] cmd;
            if (bSuccess) {
                if (0 == i) *fma = false;
                if (1 == i) *avx = false;
                WaitForSingleObject(pi.hProcess, INFINITE);
            if (!CloseHandle(hChildStdoutWr)) {
            printf("cannot close handle");
            return false;
            }
            std::string strResult;
            // Read output from the child process.
            for (;;) {
                DWORD dwRead;
                char chBuf[64];
                // Read from pipe that is the standard output for child process.
                bSuccess = ReadFile(hChildStdoutRd, chBuf, 64, &dwRead, NULL);
                if (!bSuccess || 0 == dwRead) {
                break; 
                }
                strResult += std::string(chBuf, dwRead);
            }
            if (strResult.length() > 0) {
                std::size_t pos = strResult.find(":");
                strResult = strResult.substr(pos + 2, 4);
                if (strResult == "true") {
                    if (0 == i) *fma = true;
                    if (1 == i) *avx = true;
                }
            }
            CloseHandle(hChildStdoutRd);
            CloseHandle(pi.hProcess);
            CloseHandle(pi.hThread);
            }
            else {
            printf("CreateProcess failed: %d\n", GetLastError());
            *fma = false;
            *avx = false;
            return false;
            }     
        }
    if (bSuccess && (!(*fma) || !(*avx)))
        return false;
    }
    return true;
}

2.2 SDK のアクティベーション

SDK は、ライセンスファイルに従って、アルゴリズムライブラリの権限をチェックします。通常、アクティベーション完了後にのみ、SDK の機能を使用できます。

license_online.licファイルを実行ファイルと同じフォルダにコピーしてください。,check_license_online()メソッドはライセンス認証を行います。詳細は helper.hに参照してください。

アクティベーションコードの認証順番は以下の通り

(1)ライセンスファイルのコンテンツを読み込みます。

(2)ローカルコンピューターに保存されたアクティベーションコードを取得します。

(3)利用可能なアクティベーションコードがない場合は、生成します。

(4)checkActiveCode * コマンドを直接実行して、アクティベーションコードが有効であるかどうか確認します。

(5)確認に失敗した場合は、別のアクティベーションコードを生成します。

(6)生成に失敗した場合は、エラーメッセージが表示されます。成功すると、新しいアクティベーションコードが保存され、成功したことを示すメッセージが表示されます。

2.3 モデルファイルの利用

st_mobile_human_action_createとst_mobile_human_action_create_with_sub_modelsを用いてmodelファイルをロードします。詳細はSampleプロジェクトにhelper.hの中にmodelモデルファイルの利用方法に参照してください。

2.4 素材ファイルの利用

Sampleの素材ファイルはstickers,makeups,filtersフォルダに格納しています。

helper.h中のDfsFolderメソッドを用いて素材ファイルのパスをSDKに渡します。

Last updated