Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
Z
zhengyuan-danger-chemistry-manage
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
耿迪迪
zhengyuan-danger-chemistry-manage
Commits
5adbbb36
Commit
5adbbb36
authored
Dec 16, 2022
by
耿迪迪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
人脸识别接口 gengdidi
parent
9d39387e
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
385 additions
and
5 deletions
+385
-5
libarcsoft_face.so
danger-manage-admin/arcsoft_lib/LINUX64/libarcsoft_face.so
+0
-0
libarcsoft_face_engine.so
...anage-admin/arcsoft_lib/LINUX64/libarcsoft_face_engine.so
+0
-0
libarcsoft_face_engine_jni.so
...e-admin/arcsoft_lib/LINUX64/libarcsoft_face_engine_jni.so
+0
-0
libarcsoft_face.dll
danger-manage-admin/arcsoft_lib/WIN64/libarcsoft_face.dll
+0
-0
libarcsoft_face_engine.dll
...manage-admin/arcsoft_lib/WIN64/libarcsoft_face_engine.dll
+0
-0
libarcsoft_face_engine_jni.dll
...ge-admin/arcsoft_lib/WIN64/libarcsoft_face_engine_jni.dll
+0
-0
pom.xml
danger-manage-admin/pom.xml
+34
-0
FaceEngineFactory.java
...ava/com/zehong/web/arcface/factory/FaceEngineFactory.java
+67
-0
FaceEngineUtils.java
...ain/java/com/zehong/web/arcface/util/FaceEngineUtils.java
+204
-0
FaceCompareController.java
.../web/controller/arcfacecompare/FaceCompareController.java
+52
-0
application-dev.yml
danger-manage-admin/src/main/resources/application-dev.yml
+12
-1
application-prd.yml
danger-manage-admin/src/main/resources/application-prd.yml
+16
-4
No files found.
danger-manage-admin/arcsoft_lib/LINUX64/libarcsoft_face.so
0 → 100644
View file @
5adbbb36
File added
danger-manage-admin/arcsoft_lib/LINUX64/libarcsoft_face_engine.so
0 → 100644
View file @
5adbbb36
File added
danger-manage-admin/arcsoft_lib/LINUX64/libarcsoft_face_engine_jni.so
0 → 100644
View file @
5adbbb36
File added
danger-manage-admin/arcsoft_lib/WIN64/libarcsoft_face.dll
0 → 100644
View file @
5adbbb36
File added
danger-manage-admin/arcsoft_lib/WIN64/libarcsoft_face_engine.dll
0 → 100644
View file @
5adbbb36
File added
danger-manage-admin/arcsoft_lib/WIN64/libarcsoft_face_engine_jni.dll
0 → 100644
View file @
5adbbb36
File added
danger-manage-admin/pom.xml
View file @
5adbbb36
...
...
@@ -66,6 +66,16 @@
<artifactId>
artemis-http-client
</artifactId>
<version>
1.1.3
</version>
</dependency>
<!--虹软 -->
<dependency>
<groupId>
arcsoft
</groupId>
<artifactId>
arcsoft-sdk-face
</artifactId>
<version>
3.0.0.0
</version>
<scope>
system
</scope>
<systemPath>
${project.basedir}/arcsoft_lib/arcsoft-sdk-face-3.0.0.0.jar
</systemPath>
</dependency>
</dependencies>
<build>
...
...
@@ -132,6 +142,7 @@
</resources>
</configuration>
</execution>
<execution>
<id>
copy-sh
</id>
<phase>
package
</phase>
...
...
@@ -152,6 +163,29 @@
</resources>
</configuration>
</execution>
<execution>
<id>
copy-arcsoft-lib
</id>
<phase>
package
</phase>
<goals>
<goal>
copy-resources
</goal>
</goals>
<configuration>
<encoding>
UTF-8
</encoding>
<outputDirectory>
${project.build.directory}/danger-manage-${project.version}/arcsoft_lib
</outputDirectory>
<resources>
<resource>
<directory>
arcsoft_lib
</directory>
<excludes>
<exclude>
*.jar
</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>
copy-dist-jar
</id>
<phase>
package
</phase>
...
...
danger-manage-admin/src/main/java/com/zehong/web/arcface/factory/FaceEngineFactory.java
0 → 100644
View file @
5adbbb36
package
com
.
zehong
.
web
.
arcface
.
factory
;
import
com.arcsoft.face.EngineConfiguration
;
import
com.arcsoft.face.FaceEngine
;
import
com.arcsoft.face.enums.ErrorInfo
;
import
org.apache.commons.pool2.BasePooledObjectFactory
;
import
org.apache.commons.pool2.PooledObject
;
import
org.apache.commons.pool2.impl.DefaultPooledObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* @author geng
* 人脸识别引擎初始化
*/
public
class
FaceEngineFactory
extends
BasePooledObjectFactory
<
FaceEngine
>
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
FaceEngineFactory
.
class
);
private
String
appId
;
private
String
sdkKey
;
private
String
sdkLibPath
;
private
EngineConfiguration
engineConfiguration
;
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
(
System
.
getProperty
(
"user.dir"
)
+
sdkLibPath
);
int
activeCode
=
faceEngine
.
activeOnline
(
appId
,
sdkKey
);
logger
.
info
(
"faceEngineActiveCode:"
+
activeCode
+
"=========================="
);
if
(
activeCode
!=
ErrorInfo
.
MOK
.
getValue
()
&&
activeCode
!=
ErrorInfo
.
MERR_ASF_ALREADY_ACTIVATED
.
getValue
())
{
logger
.
error
(
"引擎激活失败"
+
activeCode
);
throw
new
Exception
(
"引擎激活失败"
+
activeCode
);
}
int
initCode
=
faceEngine
.
init
(
engineConfiguration
);
logger
.
info
(
"faceEngineInitCode:"
+
initCode
+
"=========================="
);
if
(
initCode
!=
ErrorInfo
.
MOK
.
getValue
())
{
logger
.
error
(
"引擎初始化失败"
+
initCode
);
throw
new
Exception
(
"引擎初始化失败"
+
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
();
logger
.
info
(
"faceEngineUnInitCode:"
+
unInitCode
+
"=========================="
);
super
.
destroyObject
(
p
);
}
}
danger-manage-admin/src/main/java/com/zehong/web/arcface/util/FaceEngineUtils.java
0 → 100644
View file @
5adbbb36
package
com
.
zehong
.
web
.
arcface
.
util
;
import
com.arcsoft.face.*
;
import
com.arcsoft.face.enums.DetectMode
;
import
com.arcsoft.face.enums.DetectOrient
;
import
com.arcsoft.face.toolkit.ImageInfo
;
import
com.zehong.web.arcface.factory.FaceEngineFactory
;
import
org.apache.commons.pool2.impl.GenericObjectPool
;
import
org.apache.commons.pool2.impl.GenericObjectPoolConfig
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.PostConstruct
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @author geng
* 人脸比对
*/
@Component
public
class
FaceEngineUtils
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
FaceEngineUtils
.
class
);
@Value
(
"${config.arcface-sdk.sdk-lib-path}"
)
public
String
sdkLibPath
;
@Value
(
"${config.arcface-sdk.app-id}"
)
public
String
appId
;
@Value
(
"${config.arcface-sdk.sdk-key}"
)
public
String
sdkKey
;
@Value
(
"${config.arcface-sdk.detect-face-max-num}"
)
public
Integer
detectFaceMaxNum
;
@Value
(
"${config.arcface-sdk.detect-face-scale-val}"
)
public
Integer
detectFaceScaleVal
;
@Value
(
"${config.arcface-sdk.thread-pool-size}"
)
public
Integer
threadPoolSize
;
private
GenericObjectPool
<
FaceEngine
>
faceEngineGeneralPool
;
@PostConstruct
public
void
init
()
{
GenericObjectPoolConfig
poolConfig
=
new
GenericObjectPoolConfig
();
poolConfig
.
setMaxIdle
(
threadPoolSize
);
poolConfig
.
setMaxTotal
(
threadPoolSize
);
poolConfig
.
setMinIdle
(
threadPoolSize
);
poolConfig
.
setLifo
(
false
);
//引擎配置
EngineConfiguration
engineConfiguration
=
new
EngineConfiguration
();
engineConfiguration
.
setDetectMode
(
DetectMode
.
ASF_DETECT_MODE_IMAGE
);
engineConfiguration
.
setDetectFaceOrientPriority
(
DetectOrient
.
ASF_OP_0_ONLY
);
engineConfiguration
.
setDetectFaceMaxNum
(
detectFaceMaxNum
);
engineConfiguration
.
setDetectFaceScaleVal
(
detectFaceScaleVal
);
//功能配置
FunctionConfiguration
functionConfiguration
=
new
FunctionConfiguration
();
functionConfiguration
.
setSupportFaceDetect
(
true
);
functionConfiguration
.
setSupportFaceRecognition
(
true
);
engineConfiguration
.
setFunctionConfiguration
(
functionConfiguration
);
//底层库算法对象池
faceEngineGeneralPool
=
new
GenericObjectPool
(
new
FaceEngineFactory
(
sdkLibPath
,
appId
,
sdkKey
,
engineConfiguration
),
poolConfig
);
}
/**
* 人脸识别
* @param imageInfo 人脸信息
* @return List<FaceInfo>
*/
public
List
<
FaceInfo
>
detectFaces
(
ImageInfo
imageInfo
)
{
FaceEngine
faceEngine
=
null
;
try
{
faceEngine
=
faceEngineGeneralPool
.
borrowObject
();
if
(
faceEngine
==
null
)
{
throw
new
Exception
(
"获取引擎失败"
);
}
//人脸检测得到人脸列表
List
<
FaceInfo
>
faceInfoList
=
new
ArrayList
<>();
//人脸检测
int
errorCode
=
faceEngine
.
detectFaces
(
imageInfo
.
getImageData
(),
imageInfo
.
getWidth
(),
imageInfo
.
getHeight
(),
imageInfo
.
getImageFormat
(),
faceInfoList
);
if
(
errorCode
==
0
)
{
return
faceInfoList
;
}
else
{
logger
.
error
(
"人脸检测失败,errorCode:"
+
errorCode
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"人脸识别系统错误:"
,
e
);
}
finally
{
if
(
faceEngine
!=
null
)
{
//释放引擎对象
faceEngineGeneralPool
.
returnObject
(
faceEngine
);
}
}
return
null
;
}
/**
* 人脸比对
* @param imageInfo1 待比对图片
* @param imageInfo2 比对图片
* @return Integer
*/
public
Integer
compareFace
(
ImageInfo
imageInfo1
,
ImageInfo
imageInfo2
)
throws
Exception
{
List
<
FaceInfo
>
faceInfoList1
=
detectFaces
(
imageInfo1
);
List
<
FaceInfo
>
faceInfoList2
=
detectFaces
(
imageInfo2
);
if
(
CollectionUtils
.
isEmpty
(
faceInfoList1
))
{
throw
new
Exception
(
"照片1未检测到人脸"
);
}
if
(
CollectionUtils
.
isEmpty
(
faceInfoList2
))
{
throw
new
Exception
(
"照片2未检测到人脸"
);
}
byte
[]
feature1
=
extractFaceFeature
(
imageInfo1
,
faceInfoList1
.
get
(
0
));
byte
[]
feature2
=
extractFaceFeature
(
imageInfo2
,
faceInfoList2
.
get
(
0
));
FaceEngine
faceEngine
=
null
;
try
{
faceEngine
=
faceEngineGeneralPool
.
borrowObject
();
if
(
faceEngine
==
null
)
{
throw
new
Exception
(
"获取引擎失败"
);
}
FaceFeature
faceFeature1
=
new
FaceFeature
();
faceFeature1
.
setFeatureData
(
feature1
);
FaceFeature
faceFeature2
=
new
FaceFeature
();
faceFeature2
.
setFeatureData
(
feature2
);
//提取人脸特征
FaceSimilar
faceSimilar
=
new
FaceSimilar
();
int
errorCode
=
faceEngine
.
compareFaceFeature
(
faceFeature1
,
faceFeature2
,
faceSimilar
);
if
(
errorCode
==
0
)
{
return
plusHundred
(
faceSimilar
.
getScore
());
}
else
{
logger
.
error
(
"特征提取失败,errorCode:"
+
errorCode
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"人脸比对系统错误:"
,
e
);
}
finally
{
if
(
faceEngine
!=
null
)
{
//释放引擎对象
faceEngineGeneralPool
.
returnObject
(
faceEngine
);
}
}
return
null
;
}
/**
* 人脸特征
* @param imageInfo 图片信息
* @return byte[]
*/
public
byte
[]
extractFaceFeature
(
ImageInfo
imageInfo
,
FaceInfo
faceInfo
)
{
FaceEngine
faceEngine
=
null
;
try
{
faceEngine
=
faceEngineGeneralPool
.
borrowObject
();
if
(
faceEngine
==
null
)
{
throw
new
Exception
(
"获取引擎失败"
);
}
FaceFeature
faceFeature
=
new
FaceFeature
();
//提取人脸特征
int
errorCode
=
faceEngine
.
extractFaceFeature
(
imageInfo
.
getImageData
(),
imageInfo
.
getWidth
(),
imageInfo
.
getHeight
(),
imageInfo
.
getImageFormat
(),
faceInfo
,
faceFeature
);
if
(
errorCode
==
0
)
{
return
faceFeature
.
getFeatureData
();
}
else
{
logger
.
error
(
"特征提取失败,errorCode:"
+
errorCode
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"人脸特征系统错误:"
,
e
);
}
finally
{
if
(
faceEngine
!=
null
)
{
//释放引擎对象
faceEngineGeneralPool
.
returnObject
(
faceEngine
);
}
}
return
null
;
}
/**
* 百分比转化
* @param value 相似度
* @return int
*/
private
int
plusHundred
(
Float
value
)
{
BigDecimal
target
=
new
BigDecimal
(
value
);
BigDecimal
hundred
=
new
BigDecimal
(
100
f
);
return
target
.
multiply
(
hundred
).
intValue
();
}
}
danger-manage-admin/src/main/java/com/zehong/web/controller/arcfacecompare/FaceCompareController.java
0 → 100644
View file @
5adbbb36
package
com
.
zehong
.
web
.
controller
.
arcfacecompare
;
import
com.arcsoft.face.toolkit.ImageFactory
;
import
com.arcsoft.face.toolkit.ImageInfo
;
import
com.zehong.web.arcface.util.FaceEngineUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author geng
* 人脸识别
*/
@RestController
@RequestMapping
(
"/arcFace"
)
public
class
FaceCompareController
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
FaceCompareController
.
class
);
@Autowired
private
FaceEngineUtils
faceEngineUtil
;
/**
* 图片比对
* @param file 待比对图片
* @param compareFile 比对图片
* @return Integer
*/
@PostMapping
(
value
=
"/compare"
)
public
Map
<
String
,
Object
>
compare
(
@RequestParam
(
value
=
"file"
)
MultipartFile
file
,
@RequestParam
(
value
=
"compareFile"
)
MultipartFile
compareFile
){
Map
<
String
,
Object
>
result
=
new
HashMap
<>(
16
);
try
{
ImageInfo
rgbData1
=
ImageFactory
.
getRGBData
(
file
.
getBytes
());
ImageInfo
rgbData2
=
ImageFactory
.
getRGBData
(
compareFile
.
getBytes
());
result
.
put
(
"code"
,
"0"
);
result
.
put
(
"faceSimilar"
,
faceEngineUtil
.
compareFace
(
rgbData1
,
rgbData2
));
return
result
;
}
catch
(
Exception
e
)
{
result
.
put
(
"code"
,
"1"
);
result
.
put
(
"msg"
,
e
.
getMessage
());
logger
.
error
(
"图片比对系统错误:"
+
e
);
return
result
;
}
}
}
danger-manage-admin/src/main/resources/application-dev.yml
View file @
5adbbb36
...
...
@@ -109,4 +109,15 @@ zehong:
# 获取ip地址开关
addressEnabled
:
false
# 验证码类型 math 数组计算 char 字符验证
captchaType
:
math
\ No newline at end of file
captchaType
:
#虹软人脸识别配置(windows配置)
config
:
arcface-sdk
:
#算法引擎路径 示例(Windows配置\danger-manage-admin\arcsoft_lib\WIN64,Linux配置/arcsoft_lib/LINUX64)
sdk-lib-path
:
\danger-manage-admin\arcsoft_lib\WIN64
app-id
:
C8vzXcY8iD7yGFCHweh1QcvJaV684GCPk2oCe4JC1rpZ
sdk-key
:
C8MFKCRxMAsBSDG5W5cL1x1YirGREoojZvFtBzKv3bAP
detect-face-max-num
:
10
detect-face-scale-val
:
32
thread-pool-size
:
5
\ No newline at end of file
danger-manage-admin/src/main/resources/application-prd.yml
View file @
5adbbb36
...
...
@@ -21,9 +21,9 @@ spring:
druid
:
# 主库数据源
master
:
url
:
jdbc:mysql://localhost:3306
/ry
?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
url
:
jdbc:mysql://localhost:3306
0/danger_manage_area_a
?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username
:
root
password
:
root
password
:
zehong_/sjz!D
# 从库数据源
slave
:
# 从数据源开关/默认关闭
...
...
@@ -73,7 +73,7 @@ spring:
# redis 配置
redis
:
# 地址
host
:
localhost
host
:
36.138.181.113
# 端口,默认为6379
port
:
6379
# 数据库索引
...
...
@@ -109,4 +109,16 @@ zehong:
# 获取ip地址开关
addressEnabled
:
false
# 验证码类型 math 数组计算 char 字符验证
captchaType
:
math
\ No newline at end of file
captchaType
:
math
#虹软人脸识别配置(linux配置)
config
:
arcface-sdk
:
#算法引擎路径 示例(Windows配置\danger-manage-admin\arcsoft_lib\WIN64,Linux配置/arcsoft_lib/LINUX64)
sdk-lib-path
:
/arcsoft_lib/LINUX64
app-id
:
3ZM3ayaRriUPWzzy29QsqeynFcpmu9zMVXGjBrQ4rPkL
sdk-key
:
J1wqG4VVGJYLe5YYT2hQN3xHSqLEwrZJBBRQmuEXkZqc
detect-face-max-num
:
10
detect-face-scale-val
:
32
thread-pool-size
:
5
\ 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