0

轻松构建表情符号制作应用程序

 1 year ago
source link: https://www.51cto.com/article/719217.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

轻松构建表情符号制作应用程序

作者:qaseven 2022-09-20 23:52:50
构建自定义表情符号制作应用程序,捕捉用户的面部表情并使对话更有趣。

​表情符号是当今在线交流中必不可少的工具,因为它们有助于为基于文本的聊天增添色彩,并允许用户更好地表达文字背后的情感。由于预设表情符号的数量总是有限的,许多应用程序现在允许用户创建自己的自定义表情符号,以保持新鲜和令人兴奋。

a15e9bd14a8f1fd866c51100287fa5861a22ff.jpg

例如,在社交媒体应用中,不想在视频通话时露脸的用户可以使用动画角色来保护自己的隐私,并将面部表情应用于角色;在直播或电子商务应用程序中,具有逼真面部表情的虚拟主播更有可能吸引观众;在视频或照片拍摄应用程序中,用户可以在自拍时控制动画角色的面部表情,然后通过社交媒体分享自拍;在儿童教育应用程序中,一个带有详细面部表情的可爱动画角色将使在线课程变得更加有趣和吸引学生。

我自己正在开发这样一个消息传递应用程序。当与朋友聊天并想以文字以外的方式表达自己时,我的应用程序的用户可以拍照以创建他们自己或他们选择的动画角色的表情符号。然后,该应用程序将识别用户的面部表情,并将他们的面部表情应用于表情符号。通过这种方式,用户可以创建无穷无尽的独特表情符号。在我的APP开发过程中,我利用HMS Core AR Engine提供的能力来跟踪用户的面部表情并将面部表情转换为参数,大大减少了开发工作量。现在我将向您展示我是如何做到这一点的。

AR Engine 为应用程序提供了实时跟踪和识别面部表情的能力,然后可以将其转换为面部表情参数,用于精确控制虚拟角色的面部表情。

目前,该套件提供了 64 种面部表情,包括眼睑、眉毛、眼球、嘴巴和舌头的动作。支持眼球运动、开闭眼等21种眼部动作;28 种嘴部动作,包括张开嘴巴、皱起、拉动或舔嘴唇,以及移动舌头;以及五个眉毛动作,包括抬眉或下眉。

  • 基于面部表情的表情符号
  • 对开发环境的要求
  • JDK:1.8.211 或更高版本
  • Android Studio:3.0 或更高版本
  • minSdkVersion:26 或更高版本
  • targetSdkVersion:29(推荐)
  • compileSdkVersion:29(推荐)
  • Gradle 版本:6.1.1 或更高版本(推荐)

确保您已从 AppGallery 下载 AR Engine APK 并将其安装在设备上。

如果您需要使用多个 HMS Core 套件,请使用这些套件所需的最新版本。

1. 开始之前,您需要注册成为华为开发者并完成身份验证。

2. 在开发之前,通过 Maven 仓库将 AR Engine SDK 集成到您的开发环境中。

3. 7.0之前的Gradle插件、7.0版本的Gradle插件、7.1及以上版本的Gradle插件,在Android Studio中配置Maven仓库地址的步骤各不相同。需要根据具体的 Gradle 插件版本进行配置。

4、以Gradle插件7.0为例:

在您的 Android Studio 项目中打开项目级build.gradle文件并配置 Maven 存储库地址。

转到buildscript > repositories并为 SDK 配置 Maven 存储库地址。

buildscript {
repositories {
google()
jcenter()
maven {url "https://developer.huawei.com/repo/" }
}
}

打开项目级settings.gradle文件,配置HMS Core SDK的Maven仓库地址。

buildscript {
repositories {
google()
jcenter()
maven {url "https://developer.huawei.com/repo/" }
}
}

5. 在依赖项块中添加以下构建依赖项。

dependencies {
implementation 'com.huawei.hms:arenginesdk:{version}
}

应用程序开发

1. 检查当前设备是否安装了AR Engine。如果是,您的应用程序可以正常运行。如果没有,您需要提示用户安装它,例如,通过将用户重定向到 AppGallery。示例代码如下:

boolean isInstallArEngineApk =AREnginesApk.isAREngineApkReady(this);
if (!isInstallArEngineApk) {
//ConnectAppMarketActivity.class is the activity for redirecting users to AppGallery.
startActivity(new Intent(this,com.huawei.arengine.demos.common.ConnectAppMarketActivity.class));
isRemindInstall = true;
}

2. 创建一个 AR 场景。AR Engine支持五种场景,包括运动追踪(ARWorldTrackingConfig)、人脸追踪(ARFaceTrackingConfig)、手部识别(ARHandTrackingConfig)、人体追踪(ARBodyTrackingConfig)和图像识别(ARImageTrackingConfig)。

下面以调用ARFaceTrackingConfig创建人脸跟踪场景为例。

// Create an ARSession object.
mArSession = new ARSession(this);
// Select a specific Config to initialize the ARSession object based on the application scenario.
ARFaceTrackingConfig config = new ARFaceTrackingConfig(mArSession);

使用config.set XXX方法设置场景参数。

// Set the camera opening mode, which can be external or internal. The external mode can only be used in ARFace. Therefore, you are advised to use the internal mode.
mArConfig.setImageInputMode(ARConfigBase.ImageInputMode.EXTERNAL_INPUT_ALL);

3.设置人脸跟踪的AR场景参数,启动人脸跟踪。

mArSession.configure(mArConfig);
mArSession.resume();

4、初始化FaceGeometryDisplay类,获取人脸几何数据,并将数据渲染到屏幕上。

public class FaceGeometryDisplay {
// Initialize the OpenGL ES rendering related to face geometry, including creating the shader program.
void init(Context context) {...
}
}

5、初始化FaceGeometryDisplay类中的onDrawFrame方法,调用face.getFaceGeometry()获取人脸网格。

public void onDrawFrame(ARCamera camera, ARFace face) {
ARFaceGeometry faceGeometry = face.getFaceGeometry();
updateFaceGeometryData(faceGeometry);
updateModelViewProjectionData(camera, face);
drawFaceGeometry();
faceGeometry.release();
}

6.在FaceGeometryDisplay类中初始化updateFaceGeometryData() 。

传递面部网格数据以进行配置并使用 OpenGL ES 设置面部表情参数。

private void updateFaceGeometryData (ARFaceGeometry faceGeometry) {
FloatBuffer faceVertices = faceGeometry.getVertices();
FloatBuffer textureCoordinates =faceGeometry.getTextureCoordinates();
// Obtain an array consisting of face mesh texture coordinates, which is used together with the vertex data returned by getVertices() during rendering.
}

7. 初始化FaceRenderManager类来管理人脸数据渲染。

public class FaceRenderManager implements GLSurfaceView.Renderer {
public FaceRenderManager(Context context, Activity activity) {
mContext = context;
mActivity = activity;
}
// Set ARSession to obtain the latest data.
public void setArSession(ARSession arSession) {
if (arSession == null) {
LogUtil.error(TAG, "Set session error, arSession is null!");
return;
}
mArSession = arSession;
}
// Set ARConfigBase to obtain the configuration mode.
public void setArConfigBase(ARConfigBase arConfig) {
if (arConfig == null) {
LogUtil.error(TAG, "setArFaceTrackingConfig error, arConfig is null.");
return;
}
mArConfigBase = arConfig;
}
// Set the camera opening mode.
public void setOpenCameraOutsideFlag(boolean isOpenCameraOutsideFlag) {
isOpenCameraOutside = isOpenCameraOutsideFlag;
}
...
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
mFaceGeometryDisplay.init(mContext);
}
}

8、在FaceActivity中调用FaceRenderManager的setArSession、setArConfigBase等方法实现人脸跟踪效果。

public class FaceActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
mFaceRenderManager = new FaceRenderManager(this, this);
mFaceRenderManager.setDisplayRotationManage(mDisplayRotationManager);
mFaceRenderManager.setTextView(mTextView);
glSurfaceView.setRenderer(mFaceRenderManager);
glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
}
}

表情符号允许用户以文字无法表达的方式表达他们的情绪和兴奋。您现在可以通过允许用户自己创建表情符号来让您的应用程序变得更有趣,而不是为用户提供已使用一百万次的相同旧的无聊预设表情符号!用户只需面对镜头,选择他们喜欢的动画角色并微笑,就可以轻松创建带有自己微笑的表情符号。有了这种自定义表情符号的能力,用户将能够以更加个性化和有趣的方式表达自己的感受。

如果您有兴趣开发这样的应用程序,AR 引擎是一个潜在的选择。它能够实时识别用户的面部表情,将面部表情转换为参数,然后应用到虚拟角色中。集成该功能可以帮助您显着简化应用程序开发过程,让您有更多时间专注于如何为用户提供更有趣的功能并改善应用程序的用户体验。​


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK