FaceEngineFactory.java
2.03 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
package com.itboyst.facedemo.factory;
import com.arcsoft.face.EngineConfiguration;
import com.arcsoft.face.FaceEngine;
import com.arcsoft.face.enums.DetectMode;
import com.arcsoft.face.enums.DetectOrient;
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
public class FaceEngineFactory extends BasePooledObjectFactory<FaceEngine> {
private String appId;
private String sdkKey;
private String sdkLibPath;
private EngineConfiguration engineConfiguration;
private Integer detectFaceMaxNum = 10;
private Integer detectFaceScaleVal = 16;
private DetectMode detectMode = DetectMode.ASF_DETECT_MODE_IMAGE;
private DetectOrient detectFaceOrientPriority = DetectOrient.ASF_OP_0_ONLY;
public FaceEngineFactory(String sdkLibPath, String appId, String sdkKey, EngineConfiguration engineConfiguration) {
this.sdkLibPath = sdkLibPath;
this.appId = appId;
this.sdkKey = sdkKey;
this.engineConfiguration = engineConfiguration;
}
@Override
public FaceEngine create() throws Exception {
FaceEngine faceEngine = new FaceEngine(sdkLibPath);
//-=======================
int activeCode = faceEngine.activeOnline(appId, sdkKey);
System.out.println("faceEngineActiveCode:" + activeCode + "==========================");
int initCode = faceEngine.init(engineConfiguration);
System.out.println("faceEngineInitCode:" + initCode + "==========================");
return faceEngine;
}
@Override
public PooledObject<FaceEngine> wrap(FaceEngine faceEngine) {
return new DefaultPooledObject<>(faceEngine);
}
@Override
public void destroyObject(PooledObject<FaceEngine> p) throws Exception {
FaceEngine faceEngine = p.getObject();
int unInitCode = faceEngine.unInit();
System.out.println("faceEngineUnInitCode:" + unInitCode + "==========================");
super.destroyObject(p);
}
}