Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Send mediapipe data to unreal engine with livelink.

License

Notifications You must be signed in to change notification settings

liuyulvv/mediapipe-livelink

Repository files navigation

English

mediapipe-livelink

使用mediapipe进行面部捕捉,通过livelink传输数据至Unreal Engine。

mediapipe_blendshape_livelink

如何使用

  1. 配置好mediapipe的环境

  2. clone mediapipe-library:

git clone https://github.com/liuyulvv/mediapipe_library.git
  1. 获取动态链接库:
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.lib
  • release:mediapipe.dll,mediapipe.dll.if.lib

我习惯将mediapipe.if.lib重命名为mediapipe.lib,然后将mediapipe.lib复制到lib目录,mediapipe.dll复制到可执行程序的目录。

本项目的CMakeLists.txt将可执行程序输出的目录设置成项目目录。

mediapipe-library

mediapipe提供了face_blendshapestasks,我对tasks一无所知,因此将face_blendshapes改成了solution,你能像使用Holisticsolution一样使用face_blendshapes

由于face_blendshapes52个浮点数,难以可视化,因此你无法像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_blendshapesgraph路径,最后通过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();

退出时进行资源回收。

livelink传输

之前已经介绍了通过mediapipe-library提供的动态链接库如何调用face_blendshapes,获取blendshapes输出后需要通过livelink进行传输,本项目直接使用asio进行传输。由于Unreal EngineFace AR Sample中有61个blendshapes,并且顺序和face_blendshapes不同,因此你需要调整顺序,并且补充剩下10个blendshapes(mediapipe提供了52个blendshapes,但是第一个无用,所以有效的仅为51个)。

动态链接库依赖

dependencies

Demo src

livelink

开源许可

About

Send mediapipe data to unreal engine with livelink.

Topics

Resources

License

Stars

Watchers

Forks

Languages