Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
smart_gov_platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
smart_gov_platform
Commits
19b65bc5
Commit
19b65bc5
authored
Mar 02, 2023
by
廖旭伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
基础平台人脸识别代码恢复
parent
abff60b6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
857 additions
and
857 deletions
+857
-857
base-manager/pom.xml
base-manager/pom.xml
+2
-2
base-manager/src/main/java/com/mortals/xhx/common/utils/FaceUtil.java
.../src/main/java/com/mortals/xhx/common/utils/FaceUtil.java
+110
-110
base-manager/src/main/java/com/mortals/xhx/face/ArcsoftFaceUtil.java
...r/src/main/java/com/mortals/xhx/face/ArcsoftFaceUtil.java
+236
-236
base-manager/src/main/java/com/mortals/xhx/face/factory/FaceEnginePoolFactory.java
...a/com/mortals/xhx/face/factory/FaceEnginePoolFactory.java
+121
-121
base-manager/src/main/java/com/mortals/xhx/module/identity/service/impl/SysFaceServiceImpl.java
.../xhx/module/identity/service/impl/SysFaceServiceImpl.java
+248
-248
base-manager/src/main/java/com/mortals/xhx/module/identity/web/SysFaceController.java
...om/mortals/xhx/module/identity/web/SysFaceController.java
+140
-140
No files found.
base-manager/pom.xml
View file @
19b65bc5
...
@@ -214,11 +214,11 @@
...
@@ -214,11 +214,11 @@
</dependency>
</dependency>
<!-- 虹软人脸解析 -->
<!-- 虹软人脸解析 -->
<!--
<dependency>
<dependency>
<groupId>
com.arcsoft.face
</groupId>
<groupId>
com.arcsoft.face
</groupId>
<artifactId>
arcsoft-sdk-face
</artifactId>
<artifactId>
arcsoft-sdk-face
</artifactId>
<version>
3.0.0.0
</version>
<version>
3.0.0.0
</version>
</dependency>
-->
</dependency>
<dependency>
<dependency>
<groupId>
net.coobird
</groupId>
<groupId>
net.coobird
</groupId>
<artifactId>
thumbnailator
</artifactId>
<artifactId>
thumbnailator
</artifactId>
...
...
base-manager/src/main/java/com/mortals/xhx/common/utils/FaceUtil.java
View file @
19b65bc5
//
package com.mortals.xhx.common.utils;
package
com.mortals.xhx.common.utils
;
//
//
import com.arcsoft.face.*;
import
com.arcsoft.face.*
;
//
import com.arcsoft.face.enums.DetectMode;
import
com.arcsoft.face.enums.DetectMode
;
//
import com.arcsoft.face.enums.DetectOrient;
import
com.arcsoft.face.enums.DetectOrient
;
//
import com.arcsoft.face.enums.ErrorInfo;
import
com.arcsoft.face.enums.ErrorInfo
;
//
import com.arcsoft.face.toolkit.ImageInfo;
import
com.arcsoft.face.toolkit.ImageInfo
;
//
import com.mortals.framework.exception.AppException;
import
com.mortals.framework.exception.AppException
;
//
import lombok.extern.slf4j.Slf4j;
import
lombok.extern.slf4j.Slf4j
;
//
import org.springframework.stereotype.Component;
import
org.springframework.stereotype.Component
;
//
//
import java.util.ArrayList;
import
java.util.ArrayList
;
//
import java.util.List;
import
java.util.List
;
//
//
import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;
import
static
com
.
arcsoft
.
face
.
toolkit
.
ImageFactory
.
getRGBData
;
//
//
@Slf4j
@Slf4j
//
@Component
@Component
//
public class FaceUtil {
public
class
FaceUtil
{
//
//
public FaceEngine initFace(String appId, String sdkKey) {
public
FaceEngine
initFace
(
String
appId
,
String
sdkKey
)
{
//
FaceEngine faceEngine = new FaceEngine(getClass().getResource(getOsName()).getPath());
FaceEngine
faceEngine
=
new
FaceEngine
(
getClass
().
getResource
(
getOsName
()).
getPath
());
//
//激活引擎
//激活引擎
//
int errorCode = faceEngine.activeOnline(appId, sdkKey);
int
errorCode
=
faceEngine
.
activeOnline
(
appId
,
sdkKey
);
//
isTrue(!(errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()), "引擎激活失败");
isTrue
(!(
errorCode
!=
ErrorInfo
.
MOK
.
getValue
()
&&
errorCode
!=
ErrorInfo
.
MERR_ASF_ALREADY_ACTIVATED
.
getValue
()),
"引擎激活失败"
);
//
ActiveFileInfo activeFileInfo = new ActiveFileInfo();
ActiveFileInfo
activeFileInfo
=
new
ActiveFileInfo
();
//
errorCode = faceEngine.getActiveFileInfo(activeFileInfo);
errorCode
=
faceEngine
.
getActiveFileInfo
(
activeFileInfo
);
//
isTrue(!(errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()), "获取激活文件信息失败");
isTrue
(!(
errorCode
!=
ErrorInfo
.
MOK
.
getValue
()
&&
errorCode
!=
ErrorInfo
.
MERR_ASF_ALREADY_ACTIVATED
.
getValue
()),
"获取激活文件信息失败"
);
//
//引擎配置
//引擎配置
//
EngineConfiguration engineConfiguration = new EngineConfiguration();
EngineConfiguration
engineConfiguration
=
new
EngineConfiguration
();
//
engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);
engineConfiguration
.
setDetectMode
(
DetectMode
.
ASF_DETECT_MODE_IMAGE
);
//
engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_ALL_OUT);
engineConfiguration
.
setDetectFaceOrientPriority
(
DetectOrient
.
ASF_OP_ALL_OUT
);
//
engineConfiguration.setDetectFaceMaxNum(10);
engineConfiguration
.
setDetectFaceMaxNum
(
10
);
//
engineConfiguration.setDetectFaceScaleVal(16);
engineConfiguration
.
setDetectFaceScaleVal
(
16
);
//
//功能配置
//功能配置
//
FunctionConfiguration functionConfiguration = new FunctionConfiguration();
FunctionConfiguration
functionConfiguration
=
new
FunctionConfiguration
();
//
functionConfiguration.setSupportAge(true);
functionConfiguration
.
setSupportAge
(
true
);
//
functionConfiguration.setSupportFace3dAngle(true);
functionConfiguration
.
setSupportFace3dAngle
(
true
);
//
functionConfiguration.setSupportFaceDetect(true);
functionConfiguration
.
setSupportFaceDetect
(
true
);
//
functionConfiguration.setSupportFaceRecognition(true);
functionConfiguration
.
setSupportFaceRecognition
(
true
);
//
functionConfiguration.setSupportGender(true);
functionConfiguration
.
setSupportGender
(
true
);
//
functionConfiguration.setSupportLiveness(true);
functionConfiguration
.
setSupportLiveness
(
true
);
//
functionConfiguration.setSupportIRLiveness(true);
functionConfiguration
.
setSupportIRLiveness
(
true
);
//
engineConfiguration.setFunctionConfiguration(functionConfiguration);
engineConfiguration
.
setFunctionConfiguration
(
functionConfiguration
);
//
//初始化引擎
//初始化引擎
//
errorCode = faceEngine.init(engineConfiguration);
errorCode
=
faceEngine
.
init
(
engineConfiguration
);
//
isTrue(errorCode == ErrorInfo.MOK.getValue(), "初始化引擎失败");
isTrue
(
errorCode
==
ErrorInfo
.
MOK
.
getValue
(),
"初始化引擎失败"
);
//
return faceEngine;
return
faceEngine
;
//
}
}
//
//
//
/**
/**
//
* 人脸检测、特征提取
* 人脸检测、特征提取
//
*
*
//
* @param faceEngine
* @param faceEngine
//
* @param bytes
* @param bytes
//
* @return
* @return
//
*/
*/
//
public byte[] featureData(FaceEngine faceEngine, byte[] bytes) {
public
byte
[]
featureData
(
FaceEngine
faceEngine
,
byte
[]
bytes
)
{
//
//人脸检测
//人脸检测
//
ImageInfo imageInfo = getRGBData(bytes);
ImageInfo
imageInfo
=
getRGBData
(
bytes
);
//
List<FaceInfo> faceInfoList = new ArrayList<FaceInfo>();
List
<
FaceInfo
>
faceInfoList
=
new
ArrayList
<
FaceInfo
>();
//
faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
faceEngine
.
detectFaces
(
imageInfo
.
getImageData
(),
imageInfo
.
getWidth
(),
imageInfo
.
getHeight
(),
imageInfo
.
getImageFormat
(),
faceInfoList
);
//
//特征提取
//特征提取
//
FaceFeature faceFeature = new FaceFeature();
FaceFeature
faceFeature
=
new
FaceFeature
();
//
faceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList.get(0), faceFeature);
faceEngine
.
extractFaceFeature
(
imageInfo
.
getImageData
(),
imageInfo
.
getWidth
(),
imageInfo
.
getHeight
(),
imageInfo
.
getImageFormat
(),
faceInfoList
.
get
(
0
),
faceFeature
);
//
return faceFeature.getFeatureData();
return
faceFeature
.
getFeatureData
();
//
}
}
//
//
//
/**
/**
//
* 特征比对
* 特征比对
//
*
*
//
* @param targeFace
* @param targeFace
//
* @param sourceFace
* @param sourceFace
//
* @return
* @return
//
*/
*/
//
public boolean featureComparison(FaceEngine faceEngine, byte[] targeFace, byte[] sourceFace) {
public
boolean
featureComparison
(
FaceEngine
faceEngine
,
byte
[]
targeFace
,
byte
[]
sourceFace
)
{
//
//特征比对
//特征比对
//
FaceFeature targetFaceFeature = new FaceFeature();
FaceFeature
targetFaceFeature
=
new
FaceFeature
();
//
targetFaceFeature.setFeatureData(targeFace);
targetFaceFeature
.
setFeatureData
(
targeFace
);
//
FaceFeature sourceFaceFeature = new FaceFeature();
FaceFeature
sourceFaceFeature
=
new
FaceFeature
();
//
sourceFaceFeature.setFeatureData(sourceFace);
sourceFaceFeature
.
setFeatureData
(
sourceFace
);
//
FaceSimilar faceSimilar = new FaceSimilar();
FaceSimilar
faceSimilar
=
new
FaceSimilar
();
//
faceEngine.compareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);
faceEngine
.
compareFaceFeature
(
targetFaceFeature
,
sourceFaceFeature
,
faceSimilar
);
//
float score = faceSimilar.getScore();
float
score
=
faceSimilar
.
getScore
();
//
if (score > 0.8) {
if
(
score
>
0.8
)
{
//
return true;
return
true
;
//
}
}
//
return false;
return
false
;
//
}
}
//
//
public void unInit(FaceEngine faceEngine) {
public
void
unInit
(
FaceEngine
faceEngine
)
{
//
faceEngine.unInit();
faceEngine
.
unInit
();
//
}
}
//
//
public String getOsName() {
public
String
getOsName
()
{
//
String os = System.getProperty("os.name");
String
os
=
System
.
getProperty
(
"os.name"
);
//
String osName = os.toLowerCase().startsWith("win") ? "/face_lib/win64" : "/face_lib/linux";
String
osName
=
os
.
toLowerCase
().
startsWith
(
"win"
)
?
"/face_lib/win64"
:
"/face_lib/linux"
;
//
return osName;
return
osName
;
//
}
}
//
//
//
private void isTrue(boolean b, String errorMsg) {
private
void
isTrue
(
boolean
b
,
String
errorMsg
)
{
//
if (!b) {
if
(!
b
)
{
//
throw new AppException(errorMsg);
throw
new
AppException
(
errorMsg
);
//
}
}
//
}
}
//
//
}
}
base-manager/src/main/java/com/mortals/xhx/face/ArcsoftFaceUtil.java
View file @
19b65bc5
//
package com.mortals.xhx.face;
package
com.mortals.xhx.face
;
//
//
import com.arcsoft.face.*;
import
com.arcsoft.face.*
;
//
import com.arcsoft.face.toolkit.ImageInfo;
import
com.arcsoft.face.toolkit.ImageInfo
;
//
import com.google.common.collect.Lists;
import
com.google.common.collect.Lists
;
//
import com.mortals.xhx.face.factory.FaceEnginePoolFactory;
import
com.mortals.xhx.face.factory.FaceEnginePoolFactory
;
//
import com.mortals.xhx.module.identity.model.SysFaceEntity;
import
com.mortals.xhx.module.identity.model.SysFaceEntity
;
//
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import
com.sun.org.apache.xerces.internal.impl.dv.util.Base64
;
//
import lombok.extern.slf4j.Slf4j;
import
lombok.extern.slf4j.Slf4j
;
//
import org.apache.commons.pool2.impl.AbandonedConfig;
import
org.apache.commons.pool2.impl.AbandonedConfig
;
//
import org.apache.commons.pool2.impl.GenericObjectPool;
import
org.apache.commons.pool2.impl.GenericObjectPool
;
//
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import
org.apache.commons.pool2.impl.GenericObjectPoolConfig
;
//
import org.springframework.beans.factory.annotation.Value;
import
org.springframework.beans.factory.annotation.Value
;
//
import org.springframework.stereotype.Component;
import
org.springframework.stereotype.Component
;
//
//
import javax.imageio.ImageIO;
import
javax.imageio.ImageIO
;
//
import java.awt.image.BufferedImage;
import
java.awt.image.BufferedImage
;
//
import java.io.ByteArrayOutputStream;
import
java.io.ByteArrayOutputStream
;
//
import java.io.IOException;
import
java.io.IOException
;
//
import java.io.InputStream;
import
java.io.InputStream
;
//
import java.math.BigDecimal;
import
java.math.BigDecimal
;
//
import java.util.ArrayList;
import
java.util.ArrayList
;
//
import java.util.List;
import
java.util.List
;
//
//
import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;
import
static
com
.
arcsoft
.
face
.
toolkit
.
ImageFactory
.
getRGBData
;
//
//
@Slf4j
@Slf4j
//
@Component
@Component
//
public class ArcsoftFaceUtil {
public
class
ArcsoftFaceUtil
{
//
//
@Value(value = "${faceAppId}")
@Value
(
value
=
"${faceAppId}"
)
//
private String appId;
private
String
appId
;
//
//
@Value(value = "${winSdkKey}")
@Value
(
value
=
"${winSdkKey}"
)
//
private String winSdkKey;
private
String
winSdkKey
;
//
//
@Value(value = "${linuxSdkkey}")
@Value
(
value
=
"${linuxSdkkey}"
)
//
private String linuxSdkKey;
private
String
linuxSdkKey
;
//
//
//
public Integer threadPoolSize=5;
public
Integer
threadPoolSize
=
5
;
//
//
private GenericObjectPool<FaceEngine> faceEngineGenericObjectPool;
private
GenericObjectPool
<
FaceEngine
>
faceEngineGenericObjectPool
;
//
//
public ArcsoftFaceUtil(){
public
ArcsoftFaceUtil
(){
//
//
String sdkLibPath = getClass().getResource(getOsName()).getPath();
String
sdkLibPath
=
getClass
().
getResource
(
getOsName
()).
getPath
();
//
String sdkKey = getSdkKey(sdkLibPath);
String
sdkKey
=
getSdkKey
(
sdkLibPath
);
//
// 对象池工厂
// 对象池工厂
//
FaceEnginePoolFactory personPoolFactory = new FaceEnginePoolFactory(appId,sdkKey,sdkLibPath);
FaceEnginePoolFactory
personPoolFactory
=
new
FaceEnginePoolFactory
(
appId
,
sdkKey
,
sdkLibPath
);
//
// 对象池配置
// 对象池配置
//
GenericObjectPoolConfig<FaceEngine> objectPoolConfig = new GenericObjectPoolConfig<>();
GenericObjectPoolConfig
<
FaceEngine
>
objectPoolConfig
=
new
GenericObjectPoolConfig
<>();
//
objectPoolConfig.setMaxTotal(threadPoolSize);
objectPoolConfig
.
setMaxTotal
(
threadPoolSize
);
//
AbandonedConfig abandonedConfig = new AbandonedConfig();
AbandonedConfig
abandonedConfig
=
new
AbandonedConfig
();
//
//在Maintenance的时候检查是否有泄漏
//在Maintenance的时候检查是否有泄漏
//
abandonedConfig.setRemoveAbandonedOnMaintenance(true);
abandonedConfig
.
setRemoveAbandonedOnMaintenance
(
true
);
//
//borrow 的时候检查泄漏
//borrow 的时候检查泄漏
//
abandonedConfig.setRemoveAbandonedOnBorrow(true);
abandonedConfig
.
setRemoveAbandonedOnBorrow
(
true
);
//
//如果一个对象borrow之后10秒还没有返还给pool,认为是泄漏的对象
//如果一个对象borrow之后10秒还没有返还给pool,认为是泄漏的对象
//
abandonedConfig.setRemoveAbandonedTimeout(10);
abandonedConfig
.
setRemoveAbandonedTimeout
(
10
);
//
// 对象池
// 对象池
//
faceEngineGenericObjectPool = new GenericObjectPool<>(personPoolFactory, objectPoolConfig);
faceEngineGenericObjectPool
=
new
GenericObjectPool
<>(
personPoolFactory
,
objectPoolConfig
);
//
faceEngineGenericObjectPool.setAbandonedConfig(abandonedConfig);
faceEngineGenericObjectPool
.
setAbandonedConfig
(
abandonedConfig
);
//
faceEngineGenericObjectPool.setTimeBetweenEvictionRunsMillis(5000); //5秒运行一次维护任务
faceEngineGenericObjectPool
.
setTimeBetweenEvictionRunsMillis
(
5000
);
//5秒运行一次维护任务
//
log.info("引擎池开启成功");
log
.
info
(
"引擎池开启成功"
);
//
}
}
//
//
private String getOsName() {
private
String
getOsName
()
{
//
String os = System.getProperty("os.name");
String
os
=
System
.
getProperty
(
"os.name"
);
//
String osName = os.toLowerCase().startsWith("win") ? "/face_lib/win64" : "/face_lib/linux";
String
osName
=
os
.
toLowerCase
().
startsWith
(
"win"
)
?
"/face_lib/win64"
:
"/face_lib/linux"
;
//
return osName;
return
osName
;
//
}
}
//
//
private String getSdkKey(String sdkLibPath) {
private
String
getSdkKey
(
String
sdkLibPath
)
{
//
return sdkLibPath.equals("/face_lib/win64") ? winSdkKey : linuxSdkKey;
return
sdkLibPath
.
equals
(
"/face_lib/win64"
)
?
winSdkKey
:
linuxSdkKey
;
//
}
}
//
//
/**
/**
//
* 人脸检测
* 人脸检测
//
*
*
//
* @param fileInputStream
* @param fileInputStream
//
* @return
* @return
//
*/
*/
//
public List<FaceInfo> faceFind(InputStream fileInputStream) throws IOException {
public
List
<
FaceInfo
>
faceFind
(
InputStream
fileInputStream
)
throws
IOException
{
//
FaceEngine faceEngine = null;
FaceEngine
faceEngine
=
null
;
//
try {
try
{
//
faceEngine = faceEngineGenericObjectPool.borrowObject();
faceEngine
=
faceEngineGenericObjectPool
.
borrowObject
();
//
ImageInfo imageInfo = getRGBData(fileInputStream);
ImageInfo
imageInfo
=
getRGBData
(
fileInputStream
);
//
List<FaceInfo> faceInfoList = new ArrayList<FaceInfo>();
List
<
FaceInfo
>
faceInfoList
=
new
ArrayList
<
FaceInfo
>();
//
int errorCode = faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
int
errorCode
=
faceEngine
.
detectFaces
(
imageInfo
.
getImageData
(),
imageInfo
.
getWidth
(),
imageInfo
.
getHeight
(),
imageInfo
.
getImageFormat
(),
faceInfoList
);
//
return faceInfoList;
return
faceInfoList
;
//
} catch (Exception e) {
}
catch
(
Exception
e
)
{
//
log.error("人脸检测出现了异常");
log
.
error
(
"人脸检测出现了异常"
);
//
e.printStackTrace();
e
.
printStackTrace
();
//
return new ArrayList<FaceInfo>();
return
new
ArrayList
<
FaceInfo
>();
//
} finally {
}
finally
{
//
fileInputStream.close();
fileInputStream
.
close
();
//
// 回收对象到对象池
// 回收对象到对象池
//
if (faceEngine != null) {
if
(
faceEngine
!=
null
)
{
//
faceEngineGenericObjectPool.returnObject(faceEngine);
faceEngineGenericObjectPool
.
returnObject
(
faceEngine
);
//
}
}
//
}
}
//
//
}
}
//
//
/**
/**
//
* 人脸截取
* 人脸截取
//
*
*
//
* @param fileInputStream
* @param fileInputStream
//
* @param rect
* @param rect
//
* @return
* @return
//
*/
*/
//
public String faceCrop(InputStream fileInputStream, Rect rect) {
public
String
faceCrop
(
InputStream
fileInputStream
,
Rect
rect
)
{
//
try {
try
{
//
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ByteArrayOutputStream
stream
=
new
ByteArrayOutputStream
();
//
BufferedImage bufImage = ImageIO.read(fileInputStream);
BufferedImage
bufImage
=
ImageIO
.
read
(
fileInputStream
);
//
int height = bufImage.getHeight();
int
height
=
bufImage
.
getHeight
();
//
int width = bufImage.getWidth();
int
width
=
bufImage
.
getWidth
();
//
int top = rect.getTop();
int
top
=
rect
.
getTop
();
//
int bottom = rect.getBottom();
int
bottom
=
rect
.
getBottom
();
//
int left = rect.getLeft();
int
left
=
rect
.
getLeft
();
//
int right = rect.getRight();
int
right
=
rect
.
getRight
();
//
//System.out.println(top + "-" + bottom + "-" + left + "-" + right);
//System.out.println(top + "-" + bottom + "-" + left + "-" + right);
//
try {
try
{
//
BufferedImage subimage = bufImage.getSubimage(left, top, right - left, bottom - left);
BufferedImage
subimage
=
bufImage
.
getSubimage
(
left
,
top
,
right
-
left
,
bottom
-
left
);
//
ImageIO.write(subimage, "png", stream);
ImageIO
.
write
(
subimage
,
"png"
,
stream
);
//
String base64 = Base64.encode(stream.toByteArray());
String
base64
=
Base64
.
encode
(
stream
.
toByteArray
());
//
return base64;
return
base64
;
//
}catch (Exception e){
}
catch
(
Exception
e
){
//
return null;
return
null
;
//
}finally {
}
finally
{
//
stream.close();
stream
.
close
();
//
fileInputStream.close();
fileInputStream
.
close
();
//
}
}
//
} catch (IOException e) {
}
catch
(
IOException
e
)
{
//
e.printStackTrace();
e
.
printStackTrace
();
//
}finally {
}
finally
{
//
//
}
}
//
return null;
return
null
;
//
}
}
//
//
/**
/**
//
* 人脸特征值提取
* 人脸特征值提取
//
*/
*/
//
public byte[] faceFeature(byte[] bytes) {
public
byte
[]
faceFeature
(
byte
[]
bytes
)
{
//
FaceEngine faceEngine = null;
FaceEngine
faceEngine
=
null
;
//
//
try {
try
{
//
faceEngine = faceEngineGenericObjectPool.borrowObject();
faceEngine
=
faceEngineGenericObjectPool
.
borrowObject
();
//
ImageInfo imageInfo = getRGBData(bytes);
ImageInfo
imageInfo
=
getRGBData
(
bytes
);
//
//人脸检测得到人脸列表
//人脸检测得到人脸列表
//
List<FaceInfo> faceInfoList = new ArrayList<FaceInfo>();
List
<
FaceInfo
>
faceInfoList
=
new
ArrayList
<
FaceInfo
>();
//
faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
faceEngine
.
detectFaces
(
imageInfo
.
getImageData
(),
imageInfo
.
getWidth
(),
imageInfo
.
getHeight
(),
imageInfo
.
getImageFormat
(),
faceInfoList
);
//
FaceFeature faceFeature = new FaceFeature();
FaceFeature
faceFeature
=
new
FaceFeature
();
//
faceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList.get(0), faceFeature);
faceEngine
.
extractFaceFeature
(
imageInfo
.
getImageData
(),
imageInfo
.
getWidth
(),
imageInfo
.
getHeight
(),
imageInfo
.
getImageFormat
(),
faceInfoList
.
get
(
0
),
faceFeature
);
//
byte[] featureData = faceFeature.getFeatureData();
byte
[]
featureData
=
faceFeature
.
getFeatureData
();
//
return featureData;
return
featureData
;
//
} catch (Exception e) {
}
catch
(
Exception
e
)
{
//
log.error("人脸特征值提取出现了异常");
log
.
error
(
"人脸特征值提取出现了异常"
);
//
e.printStackTrace();
e
.
printStackTrace
();
//
return new byte[0];
return
new
byte
[
0
];
//
} finally {
}
finally
{
//
// 回收对象到对象池
// 回收对象到对象池
//
if (faceEngine != null) {
if
(
faceEngine
!=
null
)
{
//
faceEngineGenericObjectPool.returnObject(faceEngine);
faceEngineGenericObjectPool
.
returnObject
(
faceEngine
);
//
}
}
//
}
}
//
}
}
//
//
/**
/**
//
* 人脸对比
* 人脸对比
//
*/
*/
//
public float faceCompared(byte [] source,byte [] des) throws IOException {
public
float
faceCompared
(
byte
[]
source
,
byte
[]
des
)
throws
IOException
{
//
FaceEngine faceEngine = null;
FaceEngine
faceEngine
=
null
;
//
try {
try
{
//
faceEngine = faceEngineGenericObjectPool.borrowObject();
faceEngine
=
faceEngineGenericObjectPool
.
borrowObject
();
//
FaceFeature targetFaceFeature = new FaceFeature();
FaceFeature
targetFaceFeature
=
new
FaceFeature
();
//
targetFaceFeature.setFeatureData(source);
targetFaceFeature
.
setFeatureData
(
source
);
//
FaceFeature sourceFaceFeature = new FaceFeature();
FaceFeature
sourceFaceFeature
=
new
FaceFeature
();
//
sourceFaceFeature.setFeatureData(des);
sourceFaceFeature
.
setFeatureData
(
des
);
//
FaceSimilar faceSimilar = new FaceSimilar();
FaceSimilar
faceSimilar
=
new
FaceSimilar
();
//
faceEngine.compareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);
faceEngine
.
compareFaceFeature
(
targetFaceFeature
,
sourceFaceFeature
,
faceSimilar
);
//
float score = faceSimilar.getScore();
float
score
=
faceSimilar
.
getScore
();
//
return score;
return
score
;
//
} catch (Exception e) {
}
catch
(
Exception
e
)
{
//
log.error("人脸对比出现了异常");
log
.
error
(
"人脸对比出现了异常"
);
//
e.printStackTrace();
e
.
printStackTrace
();
//
return 0;
return
0
;
//
} finally {
}
finally
{
//
// 回收对象到对象池
// 回收对象到对象池
//
if (faceEngine != null) {
if
(
faceEngine
!=
null
)
{
//
faceEngineGenericObjectPool.returnObject(faceEngine);
faceEngineGenericObjectPool
.
returnObject
(
faceEngine
);
//
}
}
//
}
}
//
}
}
//
//
/**
/**
//
* 人脸搜索
* 人脸搜索
//
*/
*/
//
public List<SysFaceEntity> faceSearch(FaceFeature targetFaceFeature,List<SysFaceEntity> sourceList) throws IOException {
public
List
<
SysFaceEntity
>
faceSearch
(
FaceFeature
targetFaceFeature
,
List
<
SysFaceEntity
>
sourceList
)
throws
IOException
{
//
FaceEngine faceEngine = null;
FaceEngine
faceEngine
=
null
;
//
List<SysFaceEntity> resultFaceInfoList = Lists.newLinkedList();//识别到的人脸列表
List
<
SysFaceEntity
>
resultFaceInfoList
=
Lists
.
newLinkedList
();
//识别到的人脸列表
//
try {
try
{
//
faceEngine = faceEngineGenericObjectPool.borrowObject();
faceEngine
=
faceEngineGenericObjectPool
.
borrowObject
();
//
//
for(SysFaceEntity faceUserInfo : sourceList) {
for
(
SysFaceEntity
faceUserInfo
:
sourceList
)
{
//
FaceFeature sourceFaceFeature = new FaceFeature();
FaceFeature
sourceFaceFeature
=
new
FaceFeature
();
//
sourceFaceFeature.setFeatureData(faceUserInfo.getFaceFeature());
sourceFaceFeature
.
setFeatureData
(
faceUserInfo
.
getFaceFeature
());
//
FaceSimilar faceSimilar = new FaceSimilar();
FaceSimilar
faceSimilar
=
new
FaceSimilar
();
//
faceEngine.compareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);
faceEngine
.
compareFaceFeature
(
targetFaceFeature
,
sourceFaceFeature
,
faceSimilar
);
//
float score = faceSimilar.getScore();
float
score
=
faceSimilar
.
getScore
();
//
if(score > 0.8){
if
(
score
>
0.8
){
//
faceUserInfo.setSimilarValue(plusHundred(score));
faceUserInfo
.
setSimilarValue
(
plusHundred
(
score
));
//
resultFaceInfoList.add(faceUserInfo);
resultFaceInfoList
.
add
(
faceUserInfo
);
//
}
}
//
}
}
//
} catch (Exception e) {
}
catch
(
Exception
e
)
{
//
log.error("人脸对比出现了异常");
log
.
error
(
"人脸对比出现了异常"
);
//
e.printStackTrace();
e
.
printStackTrace
();
//
} finally {
}
finally
{
//
// 回收对象到对象池
// 回收对象到对象池
//
if (faceEngine != null) {
if
(
faceEngine
!=
null
)
{
//
faceEngineGenericObjectPool.returnObject(faceEngine);
faceEngineGenericObjectPool
.
returnObject
(
faceEngine
);
//
}
}
//
}
}
//
return resultFaceInfoList;
return
resultFaceInfoList
;
//
}
}
//
//
private int plusHundred(Float value) {
private
int
plusHundred
(
Float
value
)
{
//
BigDecimal target = new BigDecimal(value);
BigDecimal
target
=
new
BigDecimal
(
value
);
//
BigDecimal hundred = new BigDecimal(100f);
BigDecimal
hundred
=
new
BigDecimal
(
100
f
);
//
return target.multiply(hundred).intValue();
return
target
.
multiply
(
hundred
).
intValue
();
//
}
}
//
//
}
}
base-manager/src/main/java/com/mortals/xhx/face/factory/FaceEnginePoolFactory.java
View file @
19b65bc5
//
package com.mortals.xhx.face.factory;
package
com.mortals.xhx.face.factory
;
//
//
import com.arcsoft.face.ActiveFileInfo;
import
com.arcsoft.face.ActiveFileInfo
;
//
import com.arcsoft.face.EngineConfiguration;
import
com.arcsoft.face.EngineConfiguration
;
//
import com.arcsoft.face.FaceEngine;
import
com.arcsoft.face.FaceEngine
;
//
import com.arcsoft.face.FunctionConfiguration;
import
com.arcsoft.face.FunctionConfiguration
;
//
import com.arcsoft.face.enums.DetectMode;
import
com.arcsoft.face.enums.DetectMode
;
//
import com.arcsoft.face.enums.DetectOrient;
import
com.arcsoft.face.enums.DetectOrient
;
//
import com.arcsoft.face.enums.ErrorInfo;
import
com.arcsoft.face.enums.ErrorInfo
;
//
import lombok.extern.slf4j.Slf4j;
import
lombok.extern.slf4j.Slf4j
;
//
import org.apache.commons.pool2.BasePooledObjectFactory;
import
org.apache.commons.pool2.BasePooledObjectFactory
;
//
import org.apache.commons.pool2.PooledObject;
import
org.apache.commons.pool2.PooledObject
;
//
import org.apache.commons.pool2.impl.DefaultPooledObject;
import
org.apache.commons.pool2.impl.DefaultPooledObject
;
//
//
@Slf4j
@Slf4j
//
public class FaceEnginePoolFactory extends BasePooledObjectFactory<FaceEngine> {
public
class
FaceEnginePoolFactory
extends
BasePooledObjectFactory
<
FaceEngine
>
{
//
//
private String appId;
private
String
appId
;
//
private String sdkKey;
private
String
sdkKey
;
//
private String sdkLibPath;
private
String
sdkLibPath
;
//
//
public FaceEnginePoolFactory(String appId, String sdkKey, String sdkLibPath) {
public
FaceEnginePoolFactory
(
String
appId
,
String
sdkKey
,
String
sdkLibPath
)
{
//
this.appId = appId;
this
.
appId
=
appId
;
//
this.sdkKey = sdkKey;
this
.
sdkKey
=
sdkKey
;
//
this.sdkLibPath = sdkLibPath;
this
.
sdkLibPath
=
sdkLibPath
;
//
//this.sdkLibPath = "D:\\face\\win64";
//this.sdkLibPath = "D:\\face\\win64";
//
}
}
//
//
/**
/**
//
* 在对象池中创建对象
* 在对象池中创建对象
//
* @return
* @return
//
* @throws Exception
* @throws Exception
//
*/
*/
//
@Override
@Override
//
public FaceEngine create() throws Exception {
public
FaceEngine
create
()
throws
Exception
{
//
FaceEngine faceEngine = new FaceEngine(sdkLibPath);
FaceEngine
faceEngine
=
new
FaceEngine
(
sdkLibPath
);
//
//激活引擎
//激活引擎
//
int errorCode = faceEngine.activeOnline(appId, sdkKey);
int
errorCode
=
faceEngine
.
activeOnline
(
appId
,
sdkKey
);
//
if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
if
(
errorCode
!=
ErrorInfo
.
MOK
.
getValue
()
&&
errorCode
!=
ErrorInfo
.
MERR_ASF_ALREADY_ACTIVATED
.
getValue
())
{
//
log.warn("引擎激活失败");
log
.
warn
(
"引擎激活失败"
);
//
}
}
//
ActiveFileInfo activeFileInfo=new ActiveFileInfo();
ActiveFileInfo
activeFileInfo
=
new
ActiveFileInfo
();
//
errorCode = faceEngine.getActiveFileInfo(activeFileInfo);
errorCode
=
faceEngine
.
getActiveFileInfo
(
activeFileInfo
);
//
if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
if
(
errorCode
!=
ErrorInfo
.
MOK
.
getValue
()
&&
errorCode
!=
ErrorInfo
.
MERR_ASF_ALREADY_ACTIVATED
.
getValue
())
{
//
log.warn("获取激活文件信息失败");
log
.
warn
(
"获取激活文件信息失败"
);
//
}
}
//
//引擎配置
//引擎配置
//
EngineConfiguration engineConfiguration = new EngineConfiguration();
EngineConfiguration
engineConfiguration
=
new
EngineConfiguration
();
//
engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);
engineConfiguration
.
setDetectMode
(
DetectMode
.
ASF_DETECT_MODE_IMAGE
);
//
engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_ALL_OUT);
engineConfiguration
.
setDetectFaceOrientPriority
(
DetectOrient
.
ASF_OP_ALL_OUT
);
//
engineConfiguration.setDetectFaceMaxNum(10);
engineConfiguration
.
setDetectFaceMaxNum
(
10
);
//
engineConfiguration.setDetectFaceScaleVal(16);
engineConfiguration
.
setDetectFaceScaleVal
(
16
);
//
//功能配置
//功能配置
//
FunctionConfiguration functionConfiguration = new FunctionConfiguration();
FunctionConfiguration
functionConfiguration
=
new
FunctionConfiguration
();
//
functionConfiguration.setSupportAge(true);
functionConfiguration
.
setSupportAge
(
true
);
//
functionConfiguration.setSupportFace3dAngle(true);
functionConfiguration
.
setSupportFace3dAngle
(
true
);
//
functionConfiguration.setSupportFaceDetect(true);
functionConfiguration
.
setSupportFaceDetect
(
true
);
//
functionConfiguration.setSupportFaceRecognition(true);
functionConfiguration
.
setSupportFaceRecognition
(
true
);
//
functionConfiguration.setSupportGender(true);
functionConfiguration
.
setSupportGender
(
true
);
//
functionConfiguration.setSupportLiveness(true);
functionConfiguration
.
setSupportLiveness
(
true
);
//
functionConfiguration.setSupportIRLiveness(true);
functionConfiguration
.
setSupportIRLiveness
(
true
);
//
engineConfiguration.setFunctionConfiguration(functionConfiguration);
engineConfiguration
.
setFunctionConfiguration
(
functionConfiguration
);
//
//初始化引擎
//初始化引擎
//
errorCode = faceEngine.init(engineConfiguration);
errorCode
=
faceEngine
.
init
(
engineConfiguration
);
//
//
if (errorCode != ErrorInfo.MOK.getValue()) {
if
(
errorCode
!=
ErrorInfo
.
MOK
.
getValue
())
{
//
log.error("初始化引擎失败");
log
.
error
(
"初始化引擎失败"
);
//
}
}
//
return faceEngine;
return
faceEngine
;
//
}
}
//
//
/**
/**
//
* 包装对象
* 包装对象
//
* @param faceEngine
* @param faceEngine
//
* @return
* @return
//
*/
*/
//
@Override
@Override
//
public PooledObject<FaceEngine> wrap(FaceEngine faceEngine) {
public
PooledObject
<
FaceEngine
>
wrap
(
FaceEngine
faceEngine
)
{
//
return new DefaultPooledObject<>(faceEngine);
return
new
DefaultPooledObject
<>(
faceEngine
);
//
}
}
//
/**
/**
//
* 销毁对象
* 销毁对象
//
* @param faceEngine 对象池
* @param faceEngine 对象池
//
* @throws Exception 异常
* @throws Exception 异常
//
*/
*/
//
@Override
@Override
//
public void destroyObject(PooledObject<FaceEngine> faceEngine) throws Exception {
public
void
destroyObject
(
PooledObject
<
FaceEngine
>
faceEngine
)
throws
Exception
{
//
super.destroyObject(faceEngine);
super
.
destroyObject
(
faceEngine
);
//
}
}
//
//
/**
/**
//
* 校验对象是否可用
* 校验对象是否可用
//
* @param faceEngine 对象池
* @param faceEngine 对象池
//
* @return 对象是否可用结果,boolean
* @return 对象是否可用结果,boolean
//
*/
*/
//
@Override
@Override
//
public boolean validateObject(PooledObject<FaceEngine> faceEngine) {
public
boolean
validateObject
(
PooledObject
<
FaceEngine
>
faceEngine
)
{
//
return super.validateObject(faceEngine);
return
super
.
validateObject
(
faceEngine
);
//
}
}
//
//
/**
/**
//
* 激活钝化的对象系列操作
* 激活钝化的对象系列操作
//
* @param faceEngine 对象池
* @param faceEngine 对象池
//
* @throws Exception 异常信息
* @throws Exception 异常信息
//
*/
*/
//
@Override
@Override
//
public void activateObject(PooledObject<FaceEngine> faceEngine) throws Exception {
public
void
activateObject
(
PooledObject
<
FaceEngine
>
faceEngine
)
throws
Exception
{
//
super.activateObject(faceEngine);
super
.
activateObject
(
faceEngine
);
//
}
}
//
//
/**
/**
//
* 钝化未使用的对象
* 钝化未使用的对象
//
* @param faceEngine 对象池
* @param faceEngine 对象池
//
* @throws Exception 异常信息
* @throws Exception 异常信息
//
*/
*/
//
@Override
@Override
//
public void passivateObject(PooledObject<FaceEngine> faceEngine) throws Exception {
public
void
passivateObject
(
PooledObject
<
FaceEngine
>
faceEngine
)
throws
Exception
{
//
super.passivateObject(faceEngine);
super
.
passivateObject
(
faceEngine
);
//
}
}
//
//
}
}
base-manager/src/main/java/com/mortals/xhx/module/identity/service/impl/SysFaceServiceImpl.java
View file @
19b65bc5
//package com.mortals.xhx.module.identity.service.impl;
package
com.mortals.xhx.module.identity.service.impl
;
//
//import cn.hutool.core.collection.CollectionUtil;
import
cn.hutool.core.collection.CollectionUtil
;
//import cn.hutool.core.img.Img;
import
cn.hutool.core.img.Img
;
//import cn.hutool.core.util.IdUtil;
import
cn.hutool.core.util.IdUtil
;
//import com.arcsoft.face.FaceEngine;
import
com.arcsoft.face.FaceEngine
;
//import com.arcsoft.face.FaceFeature;
import
com.arcsoft.face.FaceFeature
;
//import com.arcsoft.face.FaceSimilar;
import
com.arcsoft.face.FaceSimilar
;
//import com.google.common.collect.Lists;
import
com.google.common.collect.Lists
;
//import com.mortals.framework.exception.AppException;
import
com.mortals.framework.exception.AppException
;
//import com.mortals.framework.model.Context;
import
com.mortals.framework.model.Context
;
//import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import
com.mortals.framework.service.impl.AbstractCRUDServiceImpl
;
//import com.mortals.framework.util.StringUtils;
import
com.mortals.framework.util.StringUtils
;
//import com.mortals.xhx.common.utils.FaceUtil;
import
com.mortals.xhx.common.utils.FaceUtil
;
//import com.mortals.xhx.face.ArcsoftFaceUtil;
import
com.mortals.xhx.face.ArcsoftFaceUtil
;
//import com.mortals.xhx.module.identity.dao.SysFaceDao;
import
com.mortals.xhx.module.identity.dao.SysFaceDao
;
//import com.mortals.xhx.module.identity.model.SysFaceEntity;
import
com.mortals.xhx.module.identity.model.SysFaceEntity
;
//import com.mortals.xhx.module.identity.model.SysIdentityEntity;
import
com.mortals.xhx.module.identity.model.SysIdentityEntity
;
//import com.mortals.xhx.module.identity.model.vo.FaceInfoResVO;
import
com.mortals.xhx.module.identity.model.vo.FaceInfoResVO
;
//import com.mortals.xhx.module.identity.service.SysFaceService;
import
com.mortals.xhx.module.identity.service.SysFaceService
;
//import com.mortals.xhx.module.identity.service.SysIdentityService;
import
com.mortals.xhx.module.identity.service.SysIdentityService
;
//import net.coobird.thumbnailator.Thumbnails;
import
net.coobird.thumbnailator.Thumbnails
;
//import org.apache.commons.collections4.CollectionUtils;
import
org.apache.commons.collections4.CollectionUtils
;
//import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.beans.factory.annotation.Autowired
;
//import org.springframework.beans.factory.annotation.Value;
import
org.springframework.beans.factory.annotation.Value
;
//import org.springframework.stereotype.Service;
import
org.springframework.stereotype.Service
;
//import org.springframework.transaction.annotation.Transactional;
import
org.springframework.transaction.annotation.Transactional
;
//import org.springframework.web.multipart.MultipartFile;
import
org.springframework.web.multipart.MultipartFile
;
//
//import javax.annotation.PostConstruct;
import
javax.annotation.PostConstruct
;
//import java.awt.image.BufferedImage;
import
java.awt.image.BufferedImage
;
//import java.io.ByteArrayOutputStream;
import
java.io.ByteArrayOutputStream
;
//import java.io.IOException;
import
java.io.IOException
;
//import java.util.Base64;
import
java.util.Base64
;
//import java.util.Date;
import
java.util.Date
;
//import java.util.List;
import
java.util.List
;
//import java.util.concurrent.*;
import
java.util.concurrent.*
;
//import java.util.stream.Collectors;
import
java.util.stream.Collectors
;
//
///**
/**
//* SysFaceService
* SysFaceService
//* 人脸识别信息 service实现
* 人脸识别信息 service实现
//*
*
//* @author zxfei
* @author zxfei
//* @date 2022-08-03
* @date 2022-08-03
//*/
*/
//@Service("sysFaceService")
@Service
(
"sysFaceService"
)
//public class SysFaceServiceImpl extends AbstractCRUDServiceImpl<SysFaceDao, SysFaceEntity, String> implements SysFaceService {
public
class
SysFaceServiceImpl
extends
AbstractCRUDServiceImpl
<
SysFaceDao
,
SysFaceEntity
,
String
>
implements
SysFaceService
{
//
// private Integer passRate = 80;
private
Integer
passRate
=
80
;
//
// public static final int WIDTH = 100;
public
static
final
int
WIDTH
=
100
;
// public static final int HEIGHT = 100;
public
static
final
int
HEIGHT
=
100
;
//
// @Value(value = "${faceAppId}")
@Value
(
value
=
"${faceAppId}"
)
// private String appId;
private
String
appId
;
//
// @Value(value = "${winSdkKey}")
@Value
(
value
=
"${winSdkKey}"
)
// private String winSdkKey;
private
String
winSdkKey
;
//
// @Value(value = "${linuxSdkkey}")
@Value
(
value
=
"${linuxSdkkey}"
)
// private String linuxSdkKey;
private
String
linuxSdkKey
;
//
// public Integer threadPoolSize = 5;
public
Integer
threadPoolSize
=
5
;
//
// @Autowired
@Autowired
// private FaceUtil faceUtil;
private
FaceUtil
faceUtil
;
//
// @Autowired
@Autowired
// private SysIdentityService sysIdentityService;
private
SysIdentityService
sysIdentityService
;
//
// @Autowired
@Autowired
// private ArcsoftFaceUtil arcsoftFaceUtil;
private
ArcsoftFaceUtil
arcsoftFaceUtil
;
//
// private ExecutorService executorService;
private
ExecutorService
executorService
;
//
// @PostConstruct
@PostConstruct
// public void init() {
public
void
init
()
{
// executorService = Executors.newFixedThreadPool(threadPoolSize);
executorService
=
Executors
.
newFixedThreadPool
(
threadPoolSize
);
// }
}
//
// @Override
@Override
// protected void saveBefore(SysFaceEntity entity, Context context) throws AppException {
protected
void
saveBefore
(
SysFaceEntity
entity
,
Context
context
)
throws
AppException
{
// //非系统自增,需这里设置主键
//非系统自增,需这里设置主键
// entity.setId(IdUtil.fastSimpleUUID());
entity
.
setId
(
IdUtil
.
fastSimpleUUID
());
// super.saveBefore(entity, context);
super
.
saveBefore
(
entity
,
context
);
// }
}
//
// @Override
@Override
// public FaceInfoResVO uploadImage(MultipartFile multipartFile, String name, String idCard, String placeId, String placeName) throws AppException {
public
FaceInfoResVO
uploadImage
(
MultipartFile
multipartFile
,
String
name
,
String
idCard
,
String
placeId
,
String
placeName
)
throws
AppException
{
// String clientName = multipartFile.getOriginalFilename();
String
clientName
=
multipartFile
.
getOriginalFilename
();
// if(!(clientName.endsWith(".png") || clientName.endsWith(".jpg") || clientName.endsWith(".jpeg"))){
if
(!(
clientName
.
endsWith
(
".png"
)
||
clientName
.
endsWith
(
".jpg"
)
||
clientName
.
endsWith
(
".jpeg"
))){
// throw new AppException("请上传图片格式(" + clientName + ")");
throw
new
AppException
(
"请上传图片格式("
+
clientName
+
")"
);
// }
}
// FaceInfoResVO resVO = new FaceInfoResVO();
FaceInfoResVO
resVO
=
new
FaceInfoResVO
();
// SysIdentityEntity idEntityReqVO = new SysIdentityEntity();
SysIdentityEntity
idEntityReqVO
=
new
SysIdentityEntity
();
// idEntityReqVO.setName(name);
idEntityReqVO
.
setName
(
name
);
// idEntityReqVO.setIdCard(idCard);
idEntityReqVO
.
setIdCard
(
idCard
);
// String entityId = sysIdentityService.saveIdEntity(idEntityReqVO).getId();
String
entityId
=
sysIdentityService
.
saveIdEntity
(
idEntityReqVO
).
getId
();
// SysFaceEntity query = new SysFaceEntity();
SysFaceEntity
query
=
new
SysFaceEntity
();
// query.setIdCard(entityId);
query
.
setIdCard
(
entityId
);
// List<SysFaceEntity> sysFaceList = dao.getList(query);
List
<
SysFaceEntity
>
sysFaceList
=
dao
.
getList
(
query
);
// if(CollectionUtils.isNotEmpty(sysFaceList)){
if
(
CollectionUtils
.
isNotEmpty
(
sysFaceList
)){
// throw new AppException("该用户(" + idEntityReqVO.getName() + "_" + idEntityReqVO.getIdCard() + ")人脸数据已存在");
throw
new
AppException
(
"该用户("
+
idEntityReqVO
.
getName
()
+
"_"
+
idEntityReqVO
.
getIdCard
()
+
")人脸数据已存在"
);
// }
}
//
// try {
try
{
// byte[] file = multipartFile.getBytes();
byte
[]
file
=
multipartFile
.
getBytes
();
// //激活引擎
//激活引擎
// FaceEngine faceEngine = faceUtil.initFace(appId, getSdkKey());
FaceEngine
faceEngine
=
faceUtil
.
initFace
(
appId
,
getSdkKey
());
// byte[] featureData = faceUtil.featureData(faceEngine, file);
byte
[]
featureData
=
faceUtil
.
featureData
(
faceEngine
,
file
);
// //创建缩略图
//创建缩略图
// BufferedImage image = Thumbnails.of(multipartFile.getInputStream()).size(WIDTH, HEIGHT).asBufferedImage();
BufferedImage
image
=
Thumbnails
.
of
(
multipartFile
.
getInputStream
()).
size
(
WIDTH
,
HEIGHT
).
asBufferedImage
();
// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
// //此方法会造成png图片有阴影
//此方法会造成png图片有阴影
//// ImageIO.write(image, "jpg", byteArrayOutputStream);
// ImageIO.write(image, "jpg", byteArrayOutputStream);
// Img.from(image).write(byteArrayOutputStream);
Img
.
from
(
image
).
write
(
byteArrayOutputStream
);
// byteArrayOutputStream.flush();
byteArrayOutputStream
.
flush
();
// SysFaceEntity sysFace = new SysFaceEntity();
SysFaceEntity
sysFace
=
new
SysFaceEntity
();
// sysFace.setId(IdUtil.fastSimpleUUID());
sysFace
.
setId
(
IdUtil
.
fastSimpleUUID
());
// sysFace.setFace(byteArrayOutputStream.toByteArray());
sysFace
.
setFace
(
byteArrayOutputStream
.
toByteArray
());
// sysFace.setFaceFeature(featureData);
sysFace
.
setFaceFeature
(
featureData
);
// sysFace.setIdCard(entityId);
sysFace
.
setIdCard
(
entityId
);
// sysFace.setPlaceId(placeId);
sysFace
.
setPlaceId
(
placeId
);
// sysFace.setPlaceName(placeName);
sysFace
.
setPlaceName
(
placeName
);
// sysFace.setCreateTime(new Date());
sysFace
.
setCreateTime
(
new
Date
());
// sysFace.setUpdateTime(sysFace.getCreateTime());
sysFace
.
setUpdateTime
(
sysFace
.
getCreateTime
());
// sysFace.setDeleted(0);
sysFace
.
setDeleted
(
0
);
// dao.insert(sysFace);
dao
.
insert
(
sysFace
);
// resVO.setFace(Base64.getEncoder().encodeToString(file));
resVO
.
setFace
(
Base64
.
getEncoder
().
encodeToString
(
file
));
// resVO.setFaceFeature(Base64.getEncoder().encodeToString(featureData));
resVO
.
setFaceFeature
(
Base64
.
getEncoder
().
encodeToString
(
featureData
));
// resVO.setIdCard(idCard);
resVO
.
setIdCard
(
idCard
);
// resVO.setName(name);
resVO
.
setName
(
name
);
// resVO.setPhone("");
resVO
.
setPhone
(
""
);
// resVO.setId(sysFace.getId());
resVO
.
setId
(
sysFace
.
getId
());
// } catch (IOException e) {
}
catch
(
IOException
e
)
{
// log.error("提取特征失败:", e);
log
.
error
(
"提取特征失败:"
,
e
);
// }
}
// return resVO;
return
resVO
;
// }
}
//
// @Override
@Override
// public List<FaceInfoResVO> findFaceList(String placeId) throws AppException {
public
List
<
FaceInfoResVO
>
findFaceList
(
String
placeId
)
throws
AppException
{
// SysFaceEntity query = new SysFaceEntity();
SysFaceEntity
query
=
new
SysFaceEntity
();
// query.setPlaceId(placeId);
query
.
setPlaceId
(
placeId
);
// List<SysFaceEntity> sysFaceList = dao.getList(query);
List
<
SysFaceEntity
>
sysFaceList
=
dao
.
getList
(
query
);
// if(CollectionUtils.isEmpty(sysFaceList)){
if
(
CollectionUtils
.
isEmpty
(
sysFaceList
)){
// throw new AppException("该场所无人脸数据");
throw
new
AppException
(
"该场所无人脸数据"
);
// }
}
// return sysFaceList.stream().map(o -> {
return
sysFaceList
.
stream
().
map
(
o
->
{
// FaceInfoResVO resVO = new FaceInfoResVO();
FaceInfoResVO
resVO
=
new
FaceInfoResVO
();
// SysIdentityEntity resVO1 = sysIdentityService.findIdEntityDetail(o.getIdCard(), 1);
SysIdentityEntity
resVO1
=
sysIdentityService
.
findIdEntityDetail
(
o
.
getIdCard
(),
1
);
// resVO.setId(o.getId());
resVO
.
setId
(
o
.
getId
());
// resVO.setPlaceId(o.getPlaceId());
resVO
.
setPlaceId
(
o
.
getPlaceId
());
// resVO.setPlaceName(o.getPlaceName());
resVO
.
setPlaceName
(
o
.
getPlaceName
());
// resVO.setCardId(resVO1.getId());
resVO
.
setCardId
(
resVO1
.
getId
());
// resVO.setName(resVO1.getName());
resVO
.
setName
(
resVO1
.
getName
());
// resVO.setPhone(resVO1.getPhone());
resVO
.
setPhone
(
resVO1
.
getPhone
());
// resVO.setFace(Base64.getEncoder().encodeToString(o.getFace()));
resVO
.
setFace
(
Base64
.
getEncoder
().
encodeToString
(
o
.
getFace
()));
// resVO.setFaceFeature(Base64.getEncoder().encodeToString(o.getFaceFeature()));
resVO
.
setFaceFeature
(
Base64
.
getEncoder
().
encodeToString
(
o
.
getFaceFeature
()));
// return resVO;
return
resVO
;
// }).collect(Collectors.toList());
}).
collect
(
Collectors
.
toList
());
// }
}
//
// @Override
@Override
// @Transactional(rollbackFor = Exception.class)
@Transactional
(
rollbackFor
=
Exception
.
class
)
// public void batchAddFace(List<MultipartFile> files, String placeId, String placeName) {
public
void
batchAddFace
(
List
<
MultipartFile
>
files
,
String
placeId
,
String
placeName
)
{
// for (int j = 0; j < files.size(); j++) {
for
(
int
j
=
0
;
j
<
files
.
size
();
j
++)
{
// String fileName = files.get(j).getOriginalFilename();
String
fileName
=
files
.
get
(
j
).
getOriginalFilename
();
// if(StringUtils.isEmpty(fileName)){
if
(
StringUtils
.
isEmpty
(
fileName
)){
// throw new AppException("文件名称(" + fileName + ")不能为空!");
throw
new
AppException
(
"文件名称("
+
fileName
+
")不能为空!"
);
// }
}
// String[] info = fileName.split("/");
String
[]
info
=
fileName
.
split
(
"/"
);
// if(info.length != 2){
if
(
info
.
length
!=
2
){
// throw new AppException("(" + fileName + ")文件命名错误,请按照规定文件模版上传!");
throw
new
AppException
(
"("
+
fileName
+
")文件命名错误,请按照规定文件模版上传!"
);
// }
}
// String[] infos = info[1].split("\\.");
String
[]
infos
=
info
[
1
].
split
(
"\\."
);
// if(infos.length != 2){
if
(
infos
.
length
!=
2
){
// throw new AppException("(" + fileName + ")文件命名错误,请按照规定文件模版上传!");
throw
new
AppException
(
"("
+
fileName
+
")文件命名错误,请按照规定文件模版上传!"
);
// }
}
// String[] strings = infos[0].split("_");
String
[]
strings
=
infos
[
0
].
split
(
"_"
);
// if(strings.length != 2){
if
(
strings
.
length
!=
2
){
// throw new AppException("(" + fileName + ")文件命名错误,请按照规定文件模版上传!");
throw
new
AppException
(
"("
+
fileName
+
")文件命名错误,请按照规定文件模版上传!"
);
// }
}
// uploadImage(files.get(j), strings[0], strings[1], placeId, placeName);
uploadImage
(
files
.
get
(
j
),
strings
[
0
],
strings
[
1
],
placeId
,
placeName
);
// }
}
// }
}
//
// private String getSdkKey() {
private
String
getSdkKey
()
{
// return faceUtil.getOsName().equals("/win") ? winSdkKey : linuxSdkKey;
return
faceUtil
.
getOsName
().
equals
(
"/win"
)
?
winSdkKey
:
linuxSdkKey
;
// }
}
//
// @Override
@Override
// public List<FaceInfoResVO> searchUserByFace(byte[] bytes) throws InterruptedException, ExecutionException{
public
List
<
FaceInfoResVO
>
searchUserByFace
(
byte
[]
bytes
)
throws
InterruptedException
,
ExecutionException
{
// List<SysFaceEntity> resultFaceInfoList = Lists.newLinkedList();//识别到的人脸列表
List
<
SysFaceEntity
>
resultFaceInfoList
=
Lists
.
newLinkedList
();
//识别到的人脸列表
//
// byte[] faceFeature = arcsoftFaceUtil.faceFeature(bytes);
byte
[]
faceFeature
=
arcsoftFaceUtil
.
faceFeature
(
bytes
);
// FaceFeature targetFaceFeature = new FaceFeature();
FaceFeature
targetFaceFeature
=
new
FaceFeature
();
// targetFaceFeature.setFeatureData(faceFeature);
targetFaceFeature
.
setFeatureData
(
faceFeature
);
// List<SysFaceEntity> faceInfoList = this.find(new SysFaceEntity());
List
<
SysFaceEntity
>
faceInfoList
=
this
.
find
(
new
SysFaceEntity
());
// List<List<SysFaceEntity>> faceUserInfoPartList = Lists.partition(faceInfoList, 1000);//分成1000一组,多线程处理
List
<
List
<
SysFaceEntity
>>
faceUserInfoPartList
=
Lists
.
partition
(
faceInfoList
,
1000
);
//分成1000一组,多线程处理
// CompletionService<List<SysFaceEntity>> completionService = new ExecutorCompletionService(executorService);
CompletionService
<
List
<
SysFaceEntity
>>
completionService
=
new
ExecutorCompletionService
(
executorService
);
// for (List<SysFaceEntity> part : faceUserInfoPartList) {
for
(
List
<
SysFaceEntity
>
part
:
faceUserInfoPartList
)
{
// completionService.submit(new CompareFaceTask(part, targetFaceFeature));
completionService
.
submit
(
new
CompareFaceTask
(
part
,
targetFaceFeature
));
// }
}
// for (int i = 0; i < faceUserInfoPartList.size(); i++) {
for
(
int
i
=
0
;
i
<
faceUserInfoPartList
.
size
();
i
++)
{
// List<SysFaceEntity> faceUserInfoList = completionService.take().get();
List
<
SysFaceEntity
>
faceUserInfoList
=
completionService
.
take
().
get
();
// if (CollectionUtil.isNotEmpty(faceInfoList)) {
if
(
CollectionUtil
.
isNotEmpty
(
faceInfoList
))
{
// resultFaceInfoList.addAll(faceUserInfoList);
resultFaceInfoList
.
addAll
(
faceUserInfoList
);
// }
}
// }
}
//
// resultFaceInfoList.sort((h1, h2) -> h2.getSimilarValue().compareTo(h1.getSimilarValue()));//从大到小排序
resultFaceInfoList
.
sort
((
h1
,
h2
)
->
h2
.
getSimilarValue
().
compareTo
(
h1
.
getSimilarValue
()));
//从大到小排序
//
// return resultFaceInfoList.stream().map(o -> {
return
resultFaceInfoList
.
stream
().
map
(
o
->
{
// FaceInfoResVO resVO = new FaceInfoResVO();
FaceInfoResVO
resVO
=
new
FaceInfoResVO
();
// SysIdentityEntity resVO1 = sysIdentityService.findIdEntityDetail(o.getIdCard(), 1);
SysIdentityEntity
resVO1
=
sysIdentityService
.
findIdEntityDetail
(
o
.
getIdCard
(),
1
);
// resVO.setId(o.getId());
resVO
.
setId
(
o
.
getId
());
// resVO.setPlaceId(o.getPlaceId());
resVO
.
setPlaceId
(
o
.
getPlaceId
());
// resVO.setPlaceName(o.getPlaceName());
resVO
.
setPlaceName
(
o
.
getPlaceName
());
// resVO.setCardId(resVO1.getId());
resVO
.
setCardId
(
resVO1
.
getId
());
// resVO.setName(resVO1.getName());
resVO
.
setName
(
resVO1
.
getName
());
// resVO.setPhone(resVO1.getPhone());
resVO
.
setPhone
(
resVO1
.
getPhone
());
// resVO.setFace(Base64.getEncoder().encodeToString(o.getFace()));
resVO
.
setFace
(
Base64
.
getEncoder
().
encodeToString
(
o
.
getFace
()));
// resVO.setFaceFeature(Base64.getEncoder().encodeToString(o.getFaceFeature()));
resVO
.
setFaceFeature
(
Base64
.
getEncoder
().
encodeToString
(
o
.
getFaceFeature
()));
// return resVO;
return
resVO
;
// }).collect(Collectors.toList());
}).
collect
(
Collectors
.
toList
());
// }
}
//
// private class CompareFaceTask implements Callable<List<SysFaceEntity>> {
private
class
CompareFaceTask
implements
Callable
<
List
<
SysFaceEntity
>>
{
//
// private List<SysFaceEntity> faceUserInfoList;
private
List
<
SysFaceEntity
>
faceUserInfoList
;
// private FaceFeature targetFaceFeature;
private
FaceFeature
targetFaceFeature
;
//
//
// public CompareFaceTask(List<SysFaceEntity> faceUserInfoList, FaceFeature targetFaceFeature) {
public
CompareFaceTask
(
List
<
SysFaceEntity
>
faceUserInfoList
,
FaceFeature
targetFaceFeature
)
{
// this.faceUserInfoList = faceUserInfoList;
this
.
faceUserInfoList
=
faceUserInfoList
;
// this.targetFaceFeature = targetFaceFeature;
this
.
targetFaceFeature
=
targetFaceFeature
;
// }
}
//
// @Override
@Override
// public List<SysFaceEntity> call() throws Exception {
public
List
<
SysFaceEntity
>
call
()
throws
Exception
{
//
// return arcsoftFaceUtil.faceSearch(targetFaceFeature,faceUserInfoList);
return
arcsoftFaceUtil
.
faceSearch
(
targetFaceFeature
,
faceUserInfoList
);
// }
}
//
// }
}
//}
}
\ No newline at end of file
\ No newline at end of file
base-manager/src/main/java/com/mortals/xhx/module/identity/web/SysFaceController.java
View file @
19b65bc5
//package com.mortals.xhx.module.identity.web;
package
com.mortals.xhx.module.identity.web
;
//
//import com.alibaba.fastjson.JSONObject;
import
com.alibaba.fastjson.JSONObject
;
//import com.mortals.framework.annotation.UnAuth;
import
com.mortals.framework.annotation.UnAuth
;
//import com.mortals.framework.model.Context;
import
com.mortals.framework.model.Context
;
//import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import
com.mortals.framework.web.BaseCRUDJsonBodyMappingController
;
//import com.mortals.xhx.module.identity.model.SysFaceEntity;
import
com.mortals.xhx.module.identity.model.SysFaceEntity
;
//import com.mortals.xhx.module.identity.model.vo.FaceInfoResVO;
import
com.mortals.xhx.module.identity.model.vo.FaceInfoResVO
;
//import com.mortals.xhx.module.identity.service.SysFaceService;
import
com.mortals.xhx.module.identity.service.SysFaceService
;
//import org.springframework.web.bind.annotation.*;
import
org.springframework.web.bind.annotation.*
;
//import org.springframework.web.multipart.MultipartFile;
import
org.springframework.web.multipart.MultipartFile
;
//
//import java.util.HashMap;
import
java.util.HashMap
;
//import java.util.List;
import
java.util.List
;
//import java.util.Map;
import
java.util.Map
;
///**
/**
//*
*
//* 人脸识别信息
* 人脸识别信息
//*
*
//* @author zxfei
* @author zxfei
//* @date 2022-08-03
* @date 2022-08-03
//*/
*/
//@RestController
@RestController
//@RequestMapping("face")
@RequestMapping
(
"face"
)
//public class SysFaceController extends BaseCRUDJsonBodyMappingController<SysFaceService,SysFaceEntity,String> {
public
class
SysFaceController
extends
BaseCRUDJsonBodyMappingController
<
SysFaceService
,
SysFaceEntity
,
String
>
{
//
// public SysFaceController(){
public
SysFaceController
(){
// super.setModuleDesc( "人脸识别信息");
super
.
setModuleDesc
(
"人脸识别信息"
);
// }
}
//
// @Override
@Override
// protected void init(Map<String, Object> model, Context context) {
protected
void
init
(
Map
<
String
,
Object
>
model
,
Context
context
)
{
// super.init(model, context);
super
.
init
(
model
,
context
);
// }
}
//
//
//
// @PostMapping({"uploadImage"})
@PostMapping
({
"uploadImage"
})
// @UnAuth
@UnAuth
// public String uploadImage(@RequestPart("file") MultipartFile file,
public
String
uploadImage
(
@RequestPart
(
"file"
)
MultipartFile
file
,
// @RequestParam("name") String name,
@RequestParam
(
"name"
)
String
name
,
// @RequestParam("idCard") String idCard,
@RequestParam
(
"idCard"
)
String
idCard
,
// @RequestParam(value = "placeId") String placeId,
@RequestParam
(
value
=
"placeId"
)
String
placeId
,
// @RequestParam(value = "placeName") String placeName) {
@RequestParam
(
value
=
"placeName"
)
String
placeName
)
{
// Map<String, Object> model = new HashMap();
Map
<
String
,
Object
>
model
=
new
HashMap
();
// JSONObject ret = new JSONObject();
JSONObject
ret
=
new
JSONObject
();
// String busiDesc = "人脸特征解析";
String
busiDesc
=
"人脸特征解析"
;
// Context context = this.getContext();
Context
context
=
this
.
getContext
();
//
// try {
try
{
// FaceInfoResVO resVO = service.uploadImage(file, name, idCard, placeId, placeName);
FaceInfoResVO
resVO
=
service
.
uploadImage
(
file
,
name
,
idCard
,
placeId
,
placeName
);
// model.put("data",resVO);
model
.
put
(
"data"
,
resVO
);
// this.recordSysLog(this.request, busiDesc + " 【成功】");
this
.
recordSysLog
(
this
.
request
,
busiDesc
+
" 【成功】"
);
// } catch (Exception var8) {
}
catch
(
Exception
var8
)
{
// this.doException(this.request, busiDesc, model, var8);
this
.
doException
(
this
.
request
,
busiDesc
,
model
,
var8
);
// Object msg = model.get("message_info");
Object
msg
=
model
.
get
(
"message_info"
);
// return this.createFailJsonResp(msg == null ? "系统异常" : msg.toString());
return
this
.
createFailJsonResp
(
msg
==
null
?
"系统异常"
:
msg
.
toString
());
// }
}
//
// this.init(model, context);
this
.
init
(
model
,
context
);
// ret.put("data", model.get("data"));
ret
.
put
(
"data"
,
model
.
get
(
"data"
));
// ret.put("code", 1);
ret
.
put
(
"code"
,
1
);
// ret.put("msg", model.remove("message_info"));
ret
.
put
(
"msg"
,
model
.
remove
(
"message_info"
));
// return ret.toJSONString();
return
ret
.
toJSONString
();
// }
}
//
// @GetMapping({"findFaceList"})
@GetMapping
({
"findFaceList"
})
// @UnAuth
@UnAuth
// public String findFaceList(@RequestParam("placeId") String placeId) {
public
String
findFaceList
(
@RequestParam
(
"placeId"
)
String
placeId
)
{
// Map<String, Object> model = new HashMap();
Map
<
String
,
Object
>
model
=
new
HashMap
();
// JSONObject ret = new JSONObject();
JSONObject
ret
=
new
JSONObject
();
// String busiDesc = "下发人脸列表";
String
busiDesc
=
"下发人脸列表"
;
// Context context = this.getContext();
Context
context
=
this
.
getContext
();
// try {
try
{
// List<FaceInfoResVO> list = service.findFaceList(placeId);
List
<
FaceInfoResVO
>
list
=
service
.
findFaceList
(
placeId
);
// model.put("data",list);
model
.
put
(
"data"
,
list
);
// this.recordSysLog(this.request, busiDesc + " 【成功】");
this
.
recordSysLog
(
this
.
request
,
busiDesc
+
" 【成功】"
);
// } catch (Exception var8) {
}
catch
(
Exception
var8
)
{
// this.doException(this.request, busiDesc, model, var8);
this
.
doException
(
this
.
request
,
busiDesc
,
model
,
var8
);
// Object msg = model.get("message_info");
Object
msg
=
model
.
get
(
"message_info"
);
// return this.createFailJsonResp(msg == null ? "系统异常" : msg.toString());
return
this
.
createFailJsonResp
(
msg
==
null
?
"系统异常"
:
msg
.
toString
());
// }
}
//
// this.init(model, context);
this
.
init
(
model
,
context
);
// ret.put("data", model.get("data"));
ret
.
put
(
"data"
,
model
.
get
(
"data"
));
// ret.put("code", 1);
ret
.
put
(
"code"
,
1
);
// ret.put("msg", model.remove("message_info"));
ret
.
put
(
"msg"
,
model
.
remove
(
"message_info"
));
// return ret.toJSONString();
return
ret
.
toJSONString
();
// }
}
//
// @PostMapping({"batchAddFace"})
@PostMapping
({
"batchAddFace"
})
// @UnAuth
@UnAuth
// public String batchAddFace(@RequestPart("files") List<MultipartFile> files,
public
String
batchAddFace
(
@RequestPart
(
"files"
)
List
<
MultipartFile
>
files
,
// @RequestParam("placeId") String placeId,
@RequestParam
(
"placeId"
)
String
placeId
,
// @RequestParam("placeName") String placeName) {
@RequestParam
(
"placeName"
)
String
placeName
)
{
// Map<String, Object> model = new HashMap();
Map
<
String
,
Object
>
model
=
new
HashMap
();
// JSONObject ret = new JSONObject();
JSONObject
ret
=
new
JSONObject
();
// String busiDesc = "批量上传人脸";
String
busiDesc
=
"批量上传人脸"
;
// Context context = this.getContext();
Context
context
=
this
.
getContext
();
//
// try {
try
{
// service.batchAddFace(files, placeId, placeName);
service
.
batchAddFace
(
files
,
placeId
,
placeName
);
// this.recordSysLog(this.request, busiDesc + " 【成功】");
this
.
recordSysLog
(
this
.
request
,
busiDesc
+
" 【成功】"
);
// } catch (Exception var8) {
}
catch
(
Exception
var8
)
{
// this.doException(this.request, busiDesc, model, var8);
this
.
doException
(
this
.
request
,
busiDesc
,
model
,
var8
);
// Object msg = model.get("message_info");
Object
msg
=
model
.
get
(
"message_info"
);
// return this.createFailJsonResp(msg == null ? "系统异常" : msg.toString());
return
this
.
createFailJsonResp
(
msg
==
null
?
"系统异常"
:
msg
.
toString
());
// }
}
//
// this.init(model, context);
this
.
init
(
model
,
context
);
// ret.put("data", null);
ret
.
put
(
"data"
,
null
);
// ret.put("code", 1);
ret
.
put
(
"code"
,
1
);
// ret.put("msg", model.remove("message_info"));
ret
.
put
(
"msg"
,
model
.
remove
(
"message_info"
));
// return ret.toJSONString();
return
ret
.
toJSONString
();
// }
}
//
// @PostMapping({"search"})
@PostMapping
({
"search"
})
// @UnAuth
@UnAuth
// public String search(@RequestPart("file") MultipartFile file) {
public
String
search
(
@RequestPart
(
"file"
)
MultipartFile
file
)
{
// Map<String, Object> model = new HashMap();
Map
<
String
,
Object
>
model
=
new
HashMap
();
// JSONObject ret = new JSONObject();
JSONObject
ret
=
new
JSONObject
();
// String busiDesc = "人脸识别";
String
busiDesc
=
"人脸识别"
;
// Context context = this.getContext();
Context
context
=
this
.
getContext
();
// try {
try
{
// List<FaceInfoResVO> list = service.searchUserByFace(file.getBytes());
List
<
FaceInfoResVO
>
list
=
service
.
searchUserByFace
(
file
.
getBytes
());
// model.put("data",list);
model
.
put
(
"data"
,
list
);
// this.recordSysLog(this.request, busiDesc + " 【成功】");
this
.
recordSysLog
(
this
.
request
,
busiDesc
+
" 【成功】"
);
// } catch (Exception var8) {
}
catch
(
Exception
var8
)
{
// this.doException(this.request, busiDesc, model, var8);
this
.
doException
(
this
.
request
,
busiDesc
,
model
,
var8
);
// Object msg = model.get("message_info");
Object
msg
=
model
.
get
(
"message_info"
);
// return this.createFailJsonResp(msg == null ? "系统异常" : msg.toString());
return
this
.
createFailJsonResp
(
msg
==
null
?
"系统异常"
:
msg
.
toString
());
// }
}
//
// this.init(model, context);
this
.
init
(
model
,
context
);
// ret.put("data", model.get("data"));
ret
.
put
(
"data"
,
model
.
get
(
"data"
));
// ret.put("code", 1);
ret
.
put
(
"code"
,
1
);
// ret.put("msg", model.remove("message_info"));
ret
.
put
(
"msg"
,
model
.
remove
(
"message_info"
));
// return ret.toJSONString();
return
ret
.
toJSONString
();
// }
}
//}
}
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment