FaceHandler.java
3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package com.rd.ve.demo;
import android.content.Context;
import android.content.res.AssetManager;
import android.os.AsyncTask;
import com.cnlive.veuisdk.CNSdkEntry;
import com.cnlive.veuisdk.CNSdkService;
import com.cnlive.veuisdk.manager.CNFaceuConfig;
import com.rd.ve.demo.utils.SDKUtils;
import java.io.File;
/**
* 导入人脸贴纸资源
*
* @author JIAN
* @date 2017-3-18 上午11:36:37
*/
public class FaceHandler {
private Context context;
private String root = null;
private CNFaceuConfig config = null;
// 自定义网络化加载人脸贴纸资源
private final String URL = "http://dianbook.17rd.com/api/shortvideo/getfaceprop";
public FaceHandler(Context _context) {
context = _context;
new AsyncTask<Integer, Integer, Integer>() {
AssetManager asset;
@Override
protected void onPreExecute() {
asset = context.getAssets();
root = context.getExternalCacheDir() + "/faceu/";
File f = new File(root);
if (!f.exists()) {
f.mkdirs();
}
}
;
@Override
protected Integer doInBackground(Integer... params) {
config = new CNFaceuConfig();
// 设置开启美颜时美白的等级 (参数值0.0f-1.0f,开启人脸识别且开启美颜之后生效)
config.setColor_level(0.48f);
// 设置开启美颜时磨皮的等级(参数值0.0f-4.0f,开启人脸识别且开启美颜之后生效)
config.setBlur_level(4.0f);
// 设置开启美颜时瘦脸的等级 (有效参数值0.0f-2.0f,开启人脸识别且开启美颜之后生效)
config.setCheek_thinning(0.68f);
// 设置美颜时大眼的等级(有效参数值0.0f-4.0f,开启人脸识别且开启美颜之后生效)
config.setEye_enlarging(1.53f);
// 方式一: 加载本地资源
String dog = root + "BeagleDog.mp3", dogIcon = root
+ "beagledog.png";
String yellowEar = root + "YellowEar.mp3", YellowEarIcon = root
+ "yellowear.png";
addItem(asset, dog, "BeagleDog.mp3", dogIcon, "beagledog.png",
"BeagleDog");
addItem(asset, yellowEar, "YellowEar.mp3", YellowEarIcon,
"yellowear.png", "YellowEar");
// 方式二:加载网络资源,设置网络化的人脸贴纸数据接口
config.enableNetFaceu(true, URL);
return null;
}
@Override
protected void onPostExecute(Integer result) {
CNSdkService service = CNSdkEntry.getSdkService();
if (null != service) {
service.initFaceuConfig(config);
}
}
;
}.execute();
}
/**
* 新增
*
* @param asset
* @param path
* @param assMp3
* @param Icon
* @param assIcon
* @param title
*/
@SuppressWarnings("unused")
private void addItem(AssetManager asset, String path, String assMp3,
String Icon, String assIcon, String title) {
if (!new File(path).exists()) {
SDKUtils.assetRes2File(asset, "faceu/" + assMp3, path);
}
if (!new File(Icon).exists()) {
SDKUtils.assetRes2File(asset, "faceu/" + assIcon, Icon);
}
config.addFaceu(path, Icon, title);
}
}