Skip to content

Latest commit

 

History

History
100 lines (69 loc) · 5.09 KB

海报换脸功能文档.md

File metadata and controls

100 lines (69 loc) · 5.09 KB

海报换脸接口文档

目录

[TOC]

1.功能介绍

海报换脸是将对模板图和输入图中的人脸进行人脸融合操作,并返回融合后的模板图片的一种技术。

2.接口介绍

接口参数

海报换脸的接口是基于道具的,除了tex_inputtex_template,其他输入参数都是通过fuItemSetParam来进行。

分为通用模板和预设模板,其中通用模板需要设置下述6个参数,预设模板需要设置输入图片相关的三个参数,模板图片的相关参数为预埋好的资源,并且预设模板无法从外部载入模板图片。

		input_width:0,    //输入图片的宽(默认为0,必须设置否则bundle直接返回)
		input_height:0,   //输入图片的高(默认为0,必须设置否则bundle直接返回)
		input_face_points:[]   //输入图片的特征点,75个点(默认为空,必须设置否则bundle直接返回)
		tex_input://输入图片的RGBA buffer数组(默认为空,必须设置否则bundle直接返回)
		template_width:0,  //模板图片的宽(如果为预设模板不需要设置)
		template_height:0, //模板图片的高(如果为预设模板不需要设置)
		template_face_points:template_face_points,//图片的特征点,75个点(如果为预设模板不需要设置)
		tex_template://模板图片的RGBA buffer数组(如果为预设模板不需要设置)
		warp_intensity:0.5,  //输入人脸五官自动变形调整, 0-1,0为关闭

现在先都使用通用模板,所有的参数都需要客户端传递进来。

注意事项

  1. 宽高的输入要在buffer传入之前进行
  2. fuRenderItems在render的时候,传入的buffer或texture大小要和模板图片保持一致。

tex_template tex_input 设置buffer方法

现在增加了nama层load texture的接口,可以使用更快的底层接口fuCreateTexForItem来传递RGBA buffer,也可以使用fuDeleteTexForItem来删除创建的texture。创建的texture会在道具销毁时删除掉。

/**
\brief create a texture for a rgba buffer and set tex as an item parameter
\param item specifies the item
\param name is the parameter name
\param value rgba buffer
\param width image width
\param height image height
\return zero for failure, non-zero for success
*/
FUNAMA_API int fuCreateTexForItem(int item, char* name, void* value, int width,int height);
/**
\brief delete the texture in item,only can be used to delete texutre create by fuCreateTexForItem
\param item specifies the item
\param name is the parameter name
\param value rgba buffer
\param width image width
\param height image height
\return zero for failure, non-zero for success
*/
FUNAMA_API int fuDeleteTexForItem(int item, char* name);

3.制作模板

常规模板制作

现在制作模板只需要用户自己找好能够识别到人脸的模板图片,并且设置好上述参数即可渲染得到结果。

制作固定模板步骤

需要再template.json文件中填好数据

模板图片文件需要放在跟template.json文件同级目录下

	{
	"template_face_points": [
		460.139, 281.099, 461.997, 334.7, 459.649, 385.568, 448.089, 437.361, 430.167, 486.138, 398.534, 527.839, 360.802, 562.826, 312.593, 576.788, 264.112, 561.675, 225.451, 527.808, 192.342, 485.628, 173.934, 436.938, 164.193, 386.593, 160.835, 335.335, 163.762, 281.267, 193.272, 297.45, 216.613, 277.846, 262.568, 282.069, 284.586, 301.035, 260.418, 301.47, 218.988, 298.087, 439.266, 296.759, 413.345, 278.199, 373.41, 281.171, 350.822, 301.532, 376.127, 300.13, 408.986, 296.957, 418.946, 331.056, 387.135, 317.712, 359.314, 338.212, 389.232, 343.398, 212.428, 330.969, 244.416, 316.241, 272.514, 338.615, 245.014, 345.151, 334.888, 340.615, 340.9, 389.47, 355.585, 426.563, 347.802, 444.577, 315.822, 447.835, 292.118, 444.427, 276.656, 432.457, 288.952, 387.826, 296.36, 343.664, 338.114, 436.746, 296.302, 435.068, 369.892, 480.999, 355.128, 477.993, 334.882, 475.55, 316.562, 477.348, 299.655, 475.351, 280.735, 479.365, 261.091, 483.426, 277.095, 498.78, 298.445, 510.575, 316.022, 511.99, 337.413, 509.556, 355.038, 496.534, 343.342, 491.777, 317.451, 493.385, 294.024, 490.553, 290.918, 487.843, 317.57, 487.565, 345.398, 487.097, 314.939, 427.406, 403.707, 320.587, 403.866, 340.725, 373.28, 342.136, 371.249, 324.301, 259.266, 321.968, 258.617, 344.345, 226.549, 340.722, 226.828, 318.887, 386.426, 329.619, 246.64, 329.785
	],//长度150,为75个landmark点
	"template_width": 1080,//模板图片的宽
	"template_height": 1920,//模板图片的高
	"image": "mdnl.png"//模板图片,跟json文件放在同级目录下
}

注意事项

固定模板无法通过设置参数更新模板图片和数据,只能更新输入数据

4.需要注意的问题

  1. 模板图片中如果有阴阳脸的情况会影响最终效果,建议选择肤色均匀的模板图片。如果模板肤色不均匀可以使用ps进行处理。
  2. 现在对于夸张表情和大角度的模板和输入图支持不太好,建议使用正常表情的正脸图。