使用mediapipe进行面部捕捉,通过livelink传输数据至Unreal Engine。
-
配置好mediapipe的环境
-
clone mediapipe-library:
git clone https://github.com/liuyulvv/mediapipe_library.git- 获取动态链接库:
bazel build -c dbg --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="D://Python//python.exe" mediapipe/library:mediapipe
bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="D://Python//python.exe" mediapipe/library:mediapipe根据你的需要获取debug(dbg)或release(opt)的动态链接库。你可以再bazel-bin\mediapipe\library中找到以下文件:
debug:mediapipe.dll,mediapipe.pdb,mediapipe.if.librelease:mediapipe.dll,mediapipe.dll.if.lib
我习惯将mediapipe.if.lib重命名为mediapipe.lib,然后将mediapipe.lib复制到lib目录,mediapipe.dll复制到可执行程序的目录。
本项目的CMakeLists.txt将可执行程序输出的目录设置成项目目录。
mediapipe提供了face_blendshapes的tasks,我对tasks一无所知,因此将face_blendshapes改成了solution,你能像使用Holistic等solution一样使用face_blendshapes。
由于face_blendshapes是52个浮点数,难以可视化,因此你无法像Holistic一样通过窗口进行直观的可视化。
通过mediapipe-library,你可以获得mediapipe的动态链接库。
在此仅介绍如何使用face_blendshapes。
#include "mediapipe_library.h"首先你需要包含mediapipe_library头文件。
size_t blend_shape_size = 52;
float* blend_shape_list = new float[blend_shape_size];
const std::string GRAPH_PATH = "mediapipe/graphs/face_blendshape/face_blendshape_desktop_live.pbtxt";
CreateFaceBlendShapeInterface(GRAPH_PATH.c_str());
AddFaceBlendShapePoller();
StartFaceBlendShape();然后为blend_shape提供一个缓冲区域,大小为52,接着设置face_blendshapes的graph路径,最后通过CreateFaceBlendShapeInterface进行初始化。
AddFaceBlendShapePoller允许你通过同步的方式获取face_blendshapes(尽管提供了异步的方式,但是目前提倡使用同步的方式)。
StartFaceBlendShape开始face_blendshapes流程。
FaceBlendShapeProcess(&camera_rgb_frame);
GetFaceBlendShapeOutput(blend_shape_list, blend_shape_size);通过opencv读取一帧数据,FaceBlendShapeProcess处理这一帧图像(mediapipe需要RGB格式,opencv默认为BGR)。
通过GetFaceBlendShapeOutput``同步地获取mediapipe输出的face_blendshapes。
delete[] blend_shape_list;
cv::destroyAllWindows();
StopFaceBlendShape();
ReleaseFaceBlendShapeInterface();退出时进行资源回收。
之前已经介绍了通过mediapipe-library提供的动态链接库如何调用face_blendshapes,获取blendshapes输出后需要通过livelink进行传输,本项目直接使用asio进行传输。由于Unreal Engine的Face AR Sample中有61个blendshapes,并且顺序和face_blendshapes不同,因此你需要调整顺序,并且补充剩下10个blendshapes(mediapipe提供了52个blendshapes,但是第一个无用,所以有效的仅为51个)。

