Visual Studioのプロジェクトを開き,SDK中のLicenseファイル(ファイル名は「license_online.lic」
に変更してください)、runtime_check.exe
、opengl_check.exe
、st_mobile.dll
およびst_mobile.lib
をビルドして、生成した実行(exe)ファイルのフォルダにコピーします。
実行ファイルの上位フォルダにモデルフォルダ、ステッカーフォルダ、フィルターフォルダおよびメークアップフォルダをそれぞれ作成し、該当素材をフォルダにコピーしてください。
Visual Studio 2013またはそれ以上のバージョン、OpenCV 2.4.11または2.4.13。
日付
バージョン番号
リリースノート
2022/01/01
VSenseAR_v7.6.5 (HumanAction)
・LiveShowなどを実現するFace3DMesh機能を搭載 ・バグフィックス
2021/04/22
SenseAR_v7.3.0 (HumanAction)
・パフォーマンスを最適化 ・バグフィックス
2020/12/27
SenseAR_v7.0.0 (HumanAction)
・耳点の検出機能の追加
・額点検出機能の追加
・画像分類機能の追加
・上肢点検出モデルの更新
・背景分割効果の更新
・240モデルの更新
2019/09/03
SenseME_v6.0.0 (HumanAction)
・ジェスチャー検出の最適化 ・手の骨の検出の追加
・3Dモデルの手の骨の検出
・240モデルと研究追跡の最適化
一部のコードが資料の都合上、途切れている部分があります。こちらはサンプルコードと同じ内容で記載していますので、詳しく知りたい場合は、該当サンプルコードを確認してください。
//HumanAction ハンドルを初期化します
//モデルのパスを取得します
NSString *strModelPath = [[NSBundle mainBundle]
pathForResource:@"M_SenseME_Action" ofType:@"model"];
//HumanAction ハンドルを作成します
//注記: 本 SDK の API では、2 種類の HumanAction ハンドル作成方法を提供します。
//検知対象がビデオである場合は ST_MOBILE_HUMAN_ACTION_DEFAULT_CONFIG_CREATE
//に設定し、画像である場合は ST_MOBILE_HUMAN_ACTION_DEFAULT_CONFIG_IMAGE に
//設定します。詳細については、st_mobile_human_action.h ファイルをご参照ください。
//ハンドル作成用の config コマンドと、人間の動作を検知するための config コマンドを
//区別するように注意してください。動作を検知するための config コマンドは、config
//コマンドを使用してハンドルを作成できる場合にのみ有効になります。
iRet = st_mobile_human_action_create(
strModelPath.UTF8String,
ST_MOBILE_HUMAN_ACTION_DEFAULT_CONFIG_VIDEO,
&_hDetector
);
//他のモデルをロードして、st_mobile_human_action_add_sub_model を呼び出します
NSString *strEyeCenter = [[NSBundle mainBundle]
pathForResource:@"xx" ofType:@"model"];
iRet = st_mobile_human_action_add_sub_model(
_hDetector,
strEyeCenter.UTF8String
);
//アバタースタンプは、目の輪郭点モデルと専用のアバターモデル (avatar_core.model)
// を一緒に読み込む必要があることに注意してください
//モデルを削除します。必要に応じて、動的にモデルを追加、または削除できます。
//詳細についてはサンプルをご参照ください。
iRet = st_mobile_human_action_remove_model_by_config(
_hDetector,
ST_MOBILE_ENABLE_FACE_EXTRA_DETECT
);
//人間の動作用のパラメーターを設定します。2 フレームごとに 1 回ジェスチャを検知するよう
//に設定しています。必要に応じて設定できます。
//他のパラメーターに関しては、st_mobile_human_action.h ファイルをご参照ください。
iRet = st_mobile_human_action_setparam(
_hDetector,
ST_HUMAN_ACTION_PARAM_HAND_PROCESS_INTERVAL,
2
);
//顔属性ハンドルを初期化します
//顔属性モデルのパスを取得します
NSString *strAttriModelPath = [[NSBundle mainBundle]
pathForResource:@"face_attribute" ofType:@"model"];
//顔属性ハンドルを作成します
iRet = st_mobile_face_attribute_create(
strAttriModelPath.UTF8String,
&_hAttribute
);
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;
}
SDK はライセンスファイルに従って、アルゴリズムライブラリの権限をチェックします。通常、アクティベーション完了後にのみ、SDK の機能を使用できます。
license_online.lic
ファイルを実行ファイルと同じフォルダにコピーしてください。,check_license_online()
メソッドはライセンス認証を行います。詳細は helper.h
に参照してください。
アクティベーションコードの認証手順は以下の通りです。
ライセンスファイルのコンテンツを読み込みます。
ローカルコンピュータに保存されたアクティベーションコードを取得します。
利用可能なアクティベーションコードがない場合は、生成します。
checkActiveCode *
コマンドを直接実行して、アクティベーションコードが有効であるかどうか確認します。
確認に失敗した場合、別のアクティベーションコードを生成します。生成に失敗した場合、エラーメッセージが表示されます。成功すると、新しいアクティベーションコードが保存され、成功したことを示すメッセージが表示されます。
static int check_license_online() {
// generate and check active code
char activate_buf[10000] = { 0 };
int activate_buf_len = sizeof(activate_buf);
const char* license_path = "license_online.lic";
const char* activate_path = "activate_code.lic";
std::ifstream in(activate_path);
if (!in.eof()) {
in >> activate_buf;
in.close();
}
int ret = st_mobile_check_activecode(license_path, activate_buf, strlen(activate_buf));
if (ret != ST_OK){
printf("we will generate new activate_code %d\n", ret);
ret = st_mobile_generate_activecode(license_path, activate_buf, &activate_buf_len);
if (ret == ST_OK) {
std::ofstream out(activate_path);
out << activate_buf;
out.close();
} else{
printf("fail to generate activate_code %d\n", ret);
return -1;
}
}
return 0;
}
st_mobile_human_action_create
とst_mobile_human_action_create_with_sub_models
を用いてmodelファイルをロードします。詳細はSampleプロジェクトのhelper.h
に記載されているmodelモデルファイルの利用方法を参照してください。
const char* face_model = "M_SenseME_Face_Video_7.0.3.model";
const char* face_282_model = "M_SenseME_Face_Extra_Advanced_6.0.8.model";
const char* hand_model = "M_SenseME_Hand_6.0.8.model";
const char* segment_model = "M_SenseME_Segment_4.12.8.model";
const char* body14_model = "M_SenseME_Body_5.5.6.model";
const char* body_contour_model = "M_SenseME_Body_Contour_77_1.2.2.model";
const char* face_extra_model = "M_SenseME_Face_Extra_Advanced_6.0.8.model";
const char* mouth_parse_model = "M_SenseME_MouthOcclusion_1.0.0.model";
const char* eyeball_model = "M_SenseME_Iris_2.0.0.model";
const char* ear_model = "M_SenseME_Ear_1.0.1.model";
const char* body4_model = "M_SenseME_Body_Four_1.0.0.model";
const char* body8_model = "body8.model";
const char* hair_model = "M_SenseME_Segment_Hair_1.3.4.model";
const char* tongue_model = "M_SenseME_Tongue_1.0.0.model";
const char* face_mesh_model = "M_SenseME_3Dmesh_1.4.0.model";
const char* avatar_helper_model = "M_SenseME_Avatar_Help_2.2.0.model";
const char* gaze_model = "M_SenseME_GazeTracking_2.1.3.model";
const char* dynamic_gesture_model = "M_SenseME_Hand_Dynamic_Gesture_1.0.0.model";
const char* hand_skeleton_model = "M_SenseME_Hand_Skeleton_2d3d_1.0.0.model";
const char* multi_segment_model = "M_SenseME_Segment_Multiclass_1.0.0.model";
const char* attribute_model = "M_SenseME_Attribute_2.2.0.model";
const char* animal_model = "M_SenseME_CatFace_3.0.0.model";
const char* classify_model = "M_SenseME_Classify_3.4.10.model";
const char* verify_model = "M_SenseME_Verify_3.91.0.model";
const char* p_db_path = "M_SenseME_Classify_Table_1.0.7.db";
const char* p_custom_db_path = "M_SenseME_Classify_Custom_Table_1.0.7.db";
const char* upbody_model = "M_SenseME_Upper_Body_0.0.42.model";
static std::string g_ModelDir = "../models/";
画像の形式やエラーコードなどを定義するファイルです。また関連するメソッドも含まれます。
//// @brief Blink動作の閾値設定。[0,1]の範囲内で設定可能であり,デフォルト設定値は0.5である
ST_SDK_API void
st_mobile_set_eyeblink_threshold(
float threshold
);
/// @brief 口開ける動作の閾値設定。[0,1]の範囲内で設定可能であり,デフォルト設定値は0.5である
ST_SDK_API void
st_mobile_set_mouthah_threshold(
float threshold
);
/// @brief 頭振る動作の閾値設定。[0,1]の範囲内で設定可能であり,デフォルト設定値は0.5である
ST_SDK_API void
st_mobile_set_headyaw_threshold(
float threshold
);
/// @brief 頷く動作の閾値設定。[0,1]の範囲内で設定可能であり,デフォルト設定値は0.5である
ST_SDK_API void
st_mobile_set_headpitch_threshold(
float threshold
);
/// @brief 眉毛動く動作の閾値設定。[0,1]の範囲内で設定可能であり,デフォルト設定値は0.5である
ST_SDK_API void
st_mobile_set_browjump_threshold(
float threshold
);
/// @brief 顔識別のスムーズさを設定する。デフォルトは0.8である
ST_SDK_API void
st_mobile_set_smooth_threshold(
float threshold
);
/// @brief 顔識別の3D回転角度を設定する。デフォルトは0.8である
ST_SDK_API void
st_mobile_set_headpose_threshold(
float threshold
);
/// @brief SSE命令集のみ利用可能の設定
ST_SDK_API void st_mobile_set_sse_only(
bool sse_only
);
/// @brief 画像色の転換
ST_SDK_API st_result_t
st_mobile_color_convert(
const unsigned char *image_src,
unsigned char *image_dst,
int image_width,
int image_height,
st_color_convert_type type
);
/// @brief 画像の回転
ST_SDK_API st_result_t st_mobile_image_rotate(
const unsigned char *image_src,
unsigned char *image_dst,
int image_width,
int image_height,
int image_stride,
st_pixel_format pixel_format,
st_rotate_type rotate_type
);
/// @brief st_mobileのカレントログレベルを設定
/// ST_LOG_DISABLEで設定した場合はログを禁止する
///
@param[in] level ログレベルを設定する
///
@return 正常の場合はST_OKで返す、異常の場合はエラーで返す
ST_SDK_API st_result_t
st_mobile_set_log_level(
st_log_level_t level
);
/// @brief ログのレベルを取得する
/// @param[out] p_level カレントログレベルの結果
/// @return 正常の場合はST_OKで返す、異常の場合はエラーで返す
ST_SDK_API st_result_t
st_mobile_get_log_level(
st_log_level_t* p_level
);
/// @brief ログパスを設定する
/// @param[in] p_file_path ログファイルのパスを設定する
/// @param[in] b_tranc_file ファイル内容削除可否,true - 削除可,false - 削除不可
/// @return 正常の場合はST_OKで返す、異常の場合はエラーで返す
ST_SDK_API st_result_t
st_mobile_redirect_log_to_file(
const char* p_file_path, bool b_tranc_file
);
/// @brief sdkバージョンを取得する
ST_SDK_API
const char* st_mobile_get_version();
ライセンス認証関連メソッドが含まれます。
/// @brief 根据授权文件生成激活码, 在使用新的license文件时使用. Android建议使用
st_mobile_generate_activecode_from_buffer
ST_SDK_API
st_result_t
st_mobile_generate_activecode(
const char* license_path,
char* activation_code,
int* activation_code_len
);
/// @brief 检查激活码, 必须在所有接口之前调用. Android建议使用
st_mobile_check_activecode_from_buffer
ST_SDK_API
st_result_t
st_mobile_check_activecode(
const char* license_path,
const char* activation_code,
int activation_code_len
);
/// @brief 根据授权文件缓存生成激活码, 在使用新的license文件时调用
ST_SDK_API st_result_t st_mobile_generate_activecode_from_buffer(
const char* license_buf,
int license_size,
char* activation_code,
int* activation_code_len
);
/// @brief 检查激活码, 必须在所有接口之前调用
ST_SDK_API st_result_t st_mobile_check_activecode_from_buffer(
const char* license_buf,
int license_size,
const char* activation_code,
int activation_code_len
);
/// @brief 根据授权文件在线生成激活码, 需要使用在线license和联网
ST_SDK_API st_result_t st_mobile_generate_activecode_online(
const char* license_path,
char* activation_code,
int* activation_code_len
);
/// @brief 根据授权文件buffer在线生成激活码, 需要使用在线license和联网
ST_SDK_API st_result_t st_mobile_generate_activecode_from_buffer_online(
const char* license_buf,
int license_size,
char* activation_code,
int* activation_code_len
);
st_mobile_human_action
のAPI関連設定が含まれます。
/// @brief 创建人体行为检测句柄. Android建议使用st_mobile_human_action_create_from_buffer ST_SDK_API st_result_t
st_mobile_human_action_create(
const char *model_path,
unsigned int config,
st_handle_t *handle
);
/// @brief 添加子模型. Android建议使用st_mobile_human_action_add_sub_model_from_buffer ST_SDK_API st_result_t
st_mobile_human_action_add_sub_model(
st_handle_t handle,
const char *model_path
);
/// @brief 释放人体行为检测句柄 ST_SDK_API
void st_mobile_human_action_destroy(
st_handle_t handle
);
/// @brief 人体行为检测 ST_SDK_API st_result_t st_mobile_human_action_detect(
st_handle_t handle,
const unsigned char *image,
st_pixel_format pixel_format,
int image_width,
int image_height,
int image_stride,
st_rotate_type orientation,
unsigned long long detect_config,
st_mobile_human_action_t *p_human_action
);
/// @brief 镜像human_action检测结果. 隔帧检测时, 需要将检测结果拷贝出来再镜像 ST_SDK_API void
st_mobile_human_action_mirror(
int image_width,
st_mobile_human_action_t *p_human_action
);
/// @brief 旋转human_action检测结果. ST_SDK_API void st_mobile_human_action_rotate(
int image_width,
int image_height,
st_rotate_type orientation,
bool b_rotate_image,
st_mobile_human_action_t* p_human_action
);
st_mobile_face_attribute
のAPI関連設定が含まれます。
/// @brief 创建人脸属性检测句柄 ST_SDK_API st_result_t st_mobile_face_attribute_create(
const char *model_path,
st_handle_t *handle
);
/// @brief 销毁已初始化的人脸属性检测句柄 ST_SDK_API void st_mobile_face_attribute_destroy(
st_handle_t handle
);
ST_SDK_API st_result_t
st_mobile_face_attribute_detect_ext2(
st_handle_t handle,
const unsigned char *image,
st_pixel_format pixel_format,
int image_width,
int image_height,
int image_stride,
const st_mobile_face_t *p_face_array,
int face_count,
float** p_attribute_array
);