Explorar el Código

feature: 人脸功能 信创版

xiari hace 1 año
padre
commit
50f84c78fd

+ 1 - 1
ruoyi-modules/ruoyi-backstage/pom.xml

@@ -165,7 +165,7 @@
         <dependency>
             <groupId>com.arcsoft.face</groupId>
             <artifactId>arcsoft-sdk-face</artifactId>
-            <version>3.0.0.0</version>
+            <version>1.1.1.0</version>
         </dependency>
 
 

+ 11 - 0
ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/config/ArcFaceConfig.java

@@ -26,6 +26,9 @@ public class ArcFaceConfig {
 
     public Integer comparePooSize = 5;
 
+    // 离线激活文件
+    public String activeFile = "";
+
     public String getSdkLibPath() {
         return sdkLibPath;
     }
@@ -65,4 +68,12 @@ public class ArcFaceConfig {
     public void setComparePooSize(Integer comparePooSize) {
         this.comparePooSize = comparePooSize;
     }
+
+    public String getActiveFile() {
+        return activeFile;
+    }
+
+    public void setActiveFile(String activeFile) {
+        this.activeFile = activeFile;
+    }
 }

+ 5 - 2
ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/config/FaceEngineFactory.java

@@ -24,20 +24,23 @@ public class FaceEngineFactory extends BasePooledObjectFactory<FaceEngine> {
 	private String activeKey;
 	private EngineConfiguration engineConfiguration;
 
+    private String activeFile;
+
 	public FaceEngineFactory(String libPath, String appId, String sdkKey, String activeKey,
-                             EngineConfiguration engineConfiguration) {
+                             EngineConfiguration engineConfiguration, String activeFile) {
 		this.appId = appId;
 		this.sdkKey = sdkKey;
 		this.activeKey = activeKey;
 		this.libPath = libPath;
 		this.engineConfiguration = engineConfiguration;
+        this.activeFile = activeFile;
 	}
 
 	@Override
 	public FaceEngine create() {
 
 		FaceEngine faceEngine = new FaceEngine(libPath);
-		int activeCode = faceEngine.activeOnline(appId, sdkKey);
+		int activeCode = faceEngine.activeOffline(activeFile);
 		if (activeCode != ErrorInfo.MOK.getValue() && activeCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
 			log.error("引擎激活失败" + activeCode);
             throw new ServiceException("引擎激活失败: "+ activeCode);

+ 3 - 3
ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/payment/controller/PtUserAccountController.java

@@ -158,13 +158,13 @@ public class PtUserAccountController extends BaseController {
 
             //1. 拼接文件完整路径
             String path = uploadPath + userPath;
-            String newFileName = UUID.randomUUID() + "." + extension;
+            String newFileName = userId + "." + extension;
             //2. 保存照片
             FileUtils.upload(file, path, newFileName);
 
             //4.保存图片路径到数据库
-            String photoUrl = userPath + newFileName;
-            ptUserAccountService.updateByBo(PtUserAccountBo.builder().userId(userId).photo(photoUrl).build());
+//            String photoUrl = userPath + newFileName;
+            ptUserAccountService.updateByBo(PtUserAccountBo.builder().userId(userId).photo(newFileName).build());
 
             return R.ok("上传图片成功");
         }

+ 3 - 3
ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/wx/service/impl/FaceEngineServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.codec.Base64;
 import com.arcsoft.face.*;
 import com.arcsoft.face.enums.DetectMode;
 import com.arcsoft.face.enums.DetectOrient;
+import com.arcsoft.face.enums.ExtractType;
 import com.arcsoft.face.toolkit.ImageInfo;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -60,7 +61,7 @@ public class FaceEngineServiceImpl implements FaceEngineService {
 		detectCfg.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);// 图片检测模式,如果是连续帧的视频流图片,那么改成VIDEO模式
 		detectCfg.setDetectFaceOrientPriority(DetectOrient.ASF_OP_0_ONLY);// 人脸旋转角度
 		faceEngineGeneralPool = new GenericObjectPool(new FaceEngineFactory(arcFaceConfig.getSdkLibPath(),
-				arcFaceConfig.getAppId(), arcFaceConfig.getSdkKey(), null, detectCfg), detectPoolConfig);// 底层库算法对象池
+				arcFaceConfig.getAppId(), arcFaceConfig.getSdkKey(), null, detectCfg,arcFaceConfig.activeFile), detectPoolConfig);// 底层库算法对象池
 
 	}
 
@@ -114,8 +115,7 @@ public class FaceEngineServiceImpl implements FaceEngineService {
 					imageInfo.getImageFormat(), faceInfoList);
 			if (code == 0 && faceInfoList.size() > 0) {
 				FaceFeature faceFeature = new FaceFeature();
-				faceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(),
-						imageInfo.getImageFormat(), faceInfoList.get(0), faceFeature);
+                faceEngine.extractFaceFeature(imageInfo,faceInfoList.get(0), ExtractType.REGISTER,0, faceFeature);
 				String featureData = Base64.encode(faceFeature.getFeatureData());
 				return featureData;
 			}

+ 1 - 1
ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/wx/service/impl/WxServiceImpl.java

@@ -231,7 +231,7 @@ public class WxServiceImpl implements IWxService {
         }
 
         //2.保存图片路径到数据库
-        String photoUrl = userPath + userId + ".jpg";
+        String photoUrl = userId + ".jpg";
         PtUserAccountBo bo = PtUserAccountBo.builder().userId(userId).photo(photoUrl).build();
         accountMapper.updateById(MapstructUtils.convert(bo, PtUserAccount.class));
     }