Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
lefull-lot-microservice
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
yangqi
lefull-lot-microservice
Commits
23c0a04e
提交
23c0a04e
authored
11月 25, 2022
作者:
yangqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
回调
上级
14bcb67b
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
126 行增加
和
255 行删除
+126
-255
FaceController.java
...t-api-web/src/main/java/cn/lefull/api/FaceController.java
+67
-3
HikvisionService.java
.../main/java/cn/lefull/common/sdk/ali/HikvisionService.java
+0
-248
Face.java
...mon/src/main/java/cn/lefull/common/sdk/ali/base/Face.java
+42
-4
FaceService.java
...vice/src/main/java/cn/lefull/service/ali/FaceService.java
+5
-0
FaceServiceImpl.java
.../src/main/java/cn/lefull/service/ali/FaceServiceImpl.java
+12
-0
没有找到文件。
lefull-lot-api-web/src/main/java/cn/lefull/api/FaceController.java
浏览文件 @
23c0a04e
...
...
@@ -3,13 +3,20 @@ package cn.lefull.api;
import
cn.lefull.common.annotation.NoAuth
;
import
cn.lefull.common.response.ApiResponse
;
import
cn.lefull.service.ali.FaceService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.File
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
/**
* @author 杨奇
...
...
@@ -17,6 +24,9 @@ import java.util.Map;
@RestController
@RequestMapping
(
"/face"
)
public
class
FaceController
{
public
static
final
String
REAL_PATH
=
"/opt/server/iot/"
;
@Autowired
private
FaceService
faceService
;
...
...
@@ -68,4 +78,58 @@ public class FaceController {
faceService
.
searchFace
(
dbName
,
url
);
return
new
ApiResponse
<>();
}
@NoAuth
@RequestMapping
(
"/uploads"
)
public
String
uploadFiles
(
HttpServletRequest
request
,
@RequestPart
(
"faceImage"
)
MultipartFile
faceImage
,
@RequestPart
(
"backgroundImage"
)
MultipartFile
backgroundImage
)
{
Logger
logger
=
LoggerFactory
.
getLogger
(
FaceController
.
class
);
logger
.
info
(
"upload...."
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"/yyyy/MM/dd/"
);
//获得路径
String
format
=
sdf
.
format
(
new
Date
());
String
path
=
REAL_PATH
+
format
;
//创建文件夹
File
fold
=
new
File
(
path
);
while
(!
fold
.
exists
())
{
fold
.
mkdirs
();}
StringBuffer
retsb
=
new
StringBuffer
();
MultipartFile
[]
uploadFile
=
new
MultipartFile
[]
{
faceImage
,
backgroundImage
};
try
{
for
(
int
i
=
0
;
i
<
uploadFile
.
length
;
i
++)
{
MultipartFile
file
=
uploadFile
[
i
];
String
oldname
=
file
.
getOriginalFilename
();
// 新文件名
String
newname
=
UUID
.
randomUUID
().
toString
()
+
"_"
+
file
.
getName
()
+
".jpg"
;
file
.
transferTo
(
new
File
(
fold
,
newname
));
String
ssss
=
request
.
getScheme
()
+
"://"
+
request
.
getServerName
()
+
":"
+
request
.
getServerPort
()
+
"/facebody/preview?path="
+
format
+
newname
;
logger
.
info
(
ssss
);
retsb
.
append
(
String
.
format
(
"<img src=\"%s\" /><br/>\n"
,
ssss
));
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
retsb
.
toString
();
}
@NoAuth
@RequestMapping
(
"/upload"
)
public
void
uploadFile
()
throws
Exception
{
String
dbName
=
"faceDb_321"
;
String
file
=
"D:/phpstudy/phpstudy_pro/WWW/wework/runtime/1.jpg"
;
faceService
.
searchFaces
(
dbName
,
file
);
}
}
lefull-lot-common/src/main/java/cn/lefull/common/sdk/ali/HikvisionService.java
deleted
100644 → 0
浏览文件 @
14bcb67b
package
cn
.
lefull
.
common
.
sdk
.
ali
;
import
com.aliyun.com.viapi.FileUtils
;
import
com.aliyun.facebody20191230.models.*
;
import
com.aliyun.oss.ClientException
;
import
com.aliyun.oss.OSS
;
import
com.aliyun.oss.OSSClientBuilder
;
import
com.aliyun.oss.OSSException
;
import
com.aliyun.oss.model.PutObjectRequest
;
import
com.aliyun.oss.model.PutObjectResult
;
import
com.aliyun.tea.TeaException
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Service
public
class
HikvisionService
{
static
String
endpoint
=
"oss-cn-shanghai.aliyuncs.com"
;
static
String
accessKeyId
=
"LTAI5t7ip3G6Wr5mMsC9UUfb"
;
static
String
accessKeySecret
=
"f03aZwjNUQb3rQMZmc4aey3bDWgfLc"
;
static
String
bucketName
=
"lefull-facebody-sh"
;
public
static
void
test
()
{
System
.
out
.
println
(
"tttttttttttttttttttttttttt"
);
}
/**
* 使用AK&SK初始化账号Client
* @return Client
* @throws Exception
*/
public
static
com
.
aliyun
.
facebody20191230
.
Client
createClient
()
{
com
.
aliyun
.
teaopenapi
.
models
.
Config
config
=
new
com
.
aliyun
.
teaopenapi
.
models
.
Config
()
// 您的 AccessKey ID
.
setAccessKeyId
(
"LTAI5tAFLtDk3SLdGEzpA3TY"
)
// 您的 AccessKey Secret
.
setAccessKeySecret
(
"1Mfr9POAjZcviHPkdAjhZ47ZYuyIiY"
);
// 访问的域名
config
.
endpoint
=
"facebody.cn-shanghai.aliyuncs.com"
;
try
{
return
new
com
.
aliyun
.
facebody20191230
.
Client
(
config
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
static
void
searchFace
(
String
daName
,
String
imageUrl
)
{
com
.
aliyun
.
facebody20191230
.
Client
client
=
createClient
();
com
.
aliyun
.
facebody20191230
.
models
.
SearchFaceRequest
searchFaceRequest
=
new
com
.
aliyun
.
facebody20191230
.
models
.
SearchFaceRequest
();
searchFaceRequest
.
setImageUrl
(
imageUrl
);
searchFaceRequest
.
setLimit
(
3
);
searchFaceRequest
.
setDbName
(
daName
);
com
.
aliyun
.
teautil
.
models
.
RuntimeOptions
runtime
=
new
com
.
aliyun
.
teautil
.
models
.
RuntimeOptions
();
try
{
// 复制代码运行请自行打印 API 的返回值
SearchFaceResponse
searchFaceResponse
=
client
.
searchFaceWithOptions
(
searchFaceRequest
,
runtime
);
Map
body
=
(
Map
)
searchFaceResponse
.
toMap
().
get
(
"body"
);
Map
data
=
(
Map
)
body
.
get
(
"Data"
);
ArrayList
list
=
(
ArrayList
)
data
.
get
(
"MatchList"
);
System
.
out
.
println
(
list
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Map
faceList
=
(
Map
)
list
.
get
(
i
);
ArrayList
items
=
(
ArrayList
)
faceList
.
get
(
"FaceItems"
);
for
(
int
j
=
0
;
j
<
items
.
size
();
j
++)
{
Map
item
=
(
Map
)
items
.
get
(
j
);
String
entityId
=
(
String
)
item
.
get
(
"EntityId"
);
String
faceId
=
(
String
)
item
.
get
(
"FaceId"
);
Float
score
=
(
Float
)
item
.
get
(
"Score"
);
String
dbName
=
(
String
)
item
.
get
(
"DbName"
);
System
.
out
.
println
(
"[\n\tentityId="
+
entityId
+
"\n"
+
"\tfaceId="
+
faceId
+
"\n"
+
"\tscore="
+
score
+
"\n"
+
"\tdbName="
+
dbName
+
"\n]\n"
);
}
}
}
catch
(
TeaException
error
)
{
// 如有需要,请打印 error
System
.
err
.
println
(
"TeaException:"
+
error
.
message
);
com
.
aliyun
.
teautil
.
Common
.
assertAsString
(
error
.
message
);
}
catch
(
Exception
_error
)
{
TeaException
error
=
new
TeaException
(
_error
.
getMessage
(),
_error
);
com
.
aliyun
.
teautil
.
Common
.
assertAsString
(
error
.
message
);
System
.
err
.
println
(
"Exception:"
+
error
.
message
);
// 如有需要,请打印 error
com
.
aliyun
.
teautil
.
Common
.
assertAsString
(
error
.
message
);
}
}
public
static
URL
uploadImage
(
String
dbName
,
String
entityId
,
String
fileName
,
File
file
)
{
String
objectName
=
(
new
StringBuilder
()
.
append
(
dbName
)
.
append
(
"/"
)
.
append
(
entityId
)
.
append
(
"/"
)
.
append
(
fileName
))
.
toString
();
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
try
{
PutObjectRequest
putObjectRequest
=
new
PutObjectRequest
(
bucketName
,
objectName
,
file
);
PutObjectResult
putObjectResult
=
ossClient
.
putObject
(
putObjectRequest
);
Date
expiration
=
new
Date
(
System
.
currentTimeMillis
()
+
3600
*
1000
);
URL
url
=
ossClient
.
generatePresignedUrl
(
bucketName
,
objectName
,
expiration
);
System
.
out
.
println
(
url
);
return
url
;
}
catch
(
OSSException
oe
)
{
System
.
err
.
println
(
"Caught an OSSException, which means your request made it to OSS, "
+
"but was rejected with an error response for some reason."
);
System
.
err
.
println
(
"Error Message:"
+
oe
.
getErrorMessage
());
System
.
err
.
println
(
"Error Code:"
+
oe
.
getErrorCode
());
System
.
err
.
println
(
"Request ID:"
+
oe
.
getRequestId
());
System
.
err
.
println
(
"Host ID:"
+
oe
.
getHostId
());
return
null
;
}
finally
{
if
(
ossClient
!=
null
)
{
ossClient
.
shutdown
();
}
}
}
public
static
URL
getImageUrl
(
String
objectName
)
{
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
try
{
// 设置签名URL过期时间,单位为毫秒。
Date
expiration
=
new
Date
(
System
.
currentTimeMillis
()
+
3600
*
1000
);
// 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
URL
url
=
ossClient
.
generatePresignedUrl
(
bucketName
,
objectName
,
expiration
);
System
.
out
.
println
(
url
);
return
url
;
}
catch
(
OSSException
oe
)
{
System
.
out
.
println
(
"Caught an OSSException, which means your request made it to OSS, "
+
"but was rejected with an error response for some reason."
);
System
.
out
.
println
(
"Error Message:"
+
oe
.
getErrorMessage
());
System
.
out
.
println
(
"Error Code:"
+
oe
.
getErrorCode
());
System
.
out
.
println
(
"Request ID:"
+
oe
.
getRequestId
());
System
.
out
.
println
(
"Host ID:"
+
oe
.
getHostId
());
}
catch
(
ClientException
ce
)
{
System
.
out
.
println
(
"Caught an ClientException, which means the client encountered "
+
"a serious internal problem while trying to communicate with OSS, "
+
"such as not being able to access the network."
);
System
.
out
.
println
(
"Error Message:"
+
ce
.
getMessage
());
}
finally
{
if
(
ossClient
!=
null
)
{
ossClient
.
shutdown
();
}
}
return
null
;
}
public
static
URL
uploadImage
(
String
dbName
,
String
entityId
,
String
fileName
,
String
filePath
)
{
return
uploadImage
(
dbName
,
entityId
,
fileName
,
new
File
(
filePath
));
}
public
static
String
uploadImageUrl
(
String
file
)
throws
com
.
aliyuncs
.
exceptions
.
ClientException
,
IOException
{
FileUtils
fileUtils
=
FileUtils
.
getInstance
(
accessKeyId
,
accessKeySecret
);
return
fileUtils
.
upload
(
file
);
}
public
static
ArrayList
getFaceDb
()
{
com
.
aliyun
.
facebody20191230
.
Client
client
=
createClient
();
com
.
aliyun
.
facebody20191230
.
models
.
ListFaceDbsRequest
listFaceDbsRequest
=
new
com
.
aliyun
.
facebody20191230
.
models
.
ListFaceDbsRequest
();
com
.
aliyun
.
teautil
.
models
.
RuntimeOptions
runtime
=
new
com
.
aliyun
.
teautil
.
models
.
RuntimeOptions
();
try
{
// 复制代码运行请自行打印 API 的返回值
ListFaceDbsResponse
listFaceDbsResponse
=
client
.
listFaceDbsWithOptions
(
listFaceDbsRequest
,
runtime
);
Map
body
=
(
Map
)
listFaceDbsResponse
.
toMap
().
get
(
"body"
);
Map
data
=
(
Map
)
body
.
get
(
"Data"
);
ArrayList
list
=
(
ArrayList
)
data
.
get
(
"DbList"
);
return
list
;
}
catch
(
TeaException
error
)
{
// 如有需要,请打印 error
System
.
err
.
println
(
"Exception:"
+
error
.
message
);
com
.
aliyun
.
teautil
.
Common
.
assertAsString
(
error
.
message
);
}
catch
(
Exception
_error
)
{
TeaException
error
=
new
TeaException
(
_error
.
getMessage
(),
_error
);
System
.
err
.
println
(
"Exception:"
+
error
.
message
);
// 如有需要,请打印 error
com
.
aliyun
.
teautil
.
Common
.
assertAsString
(
error
.
message
);
}
return
null
;
}
public
static
ArrayList
getEntity
(
String
dbName
)
{
com
.
aliyun
.
facebody20191230
.
Client
client
=
createClient
();
com
.
aliyun
.
facebody20191230
.
models
.
ListFaceEntitiesRequest
listFaceEntitiesRequest
=
new
com
.
aliyun
.
facebody20191230
.
models
.
ListFaceEntitiesRequest
();
listFaceEntitiesRequest
.
setDbName
(
dbName
);
com
.
aliyun
.
teautil
.
models
.
RuntimeOptions
runtime
=
new
com
.
aliyun
.
teautil
.
models
.
RuntimeOptions
();
try
{
ListFaceEntitiesResponse
listFaceEntitiesResponse
=
client
.
listFaceEntitiesWithOptions
(
listFaceEntitiesRequest
,
runtime
);
Map
body
=
(
Map
)
listFaceEntitiesResponse
.
toMap
().
get
(
"body"
);
Map
data
=
(
Map
)
body
.
get
(
"Data"
);
ArrayList
<
Map
>
entities
=
(
ArrayList
<
Map
>)
data
.
get
(
"Entities"
);
for
(
int
i
=
0
;
i
<
entities
.
size
();
i
++)
{
Map
e
=
(
Map
)
entities
.
get
(
i
);
System
.
out
.
println
(
"DbName:"
+
e
.
get
(
"DbName"
));
System
.
out
.
println
(
"EntityId:"
+
e
.
get
(
"EntityId"
));
System
.
out
.
println
(
"Labels:"
+
e
.
get
(
"Labels"
));
System
.
out
.
println
(
"FaceCount:"
+
e
.
get
(
"FaceCount"
));
System
.
out
.
println
(
"-----------------"
);
}
return
entities
;
}
catch
(
TeaException
error
)
{
// 如有需要,请打印 error
System
.
err
.
println
(
"Exception:"
+
error
.
message
);
com
.
aliyun
.
teautil
.
Common
.
assertAsString
(
error
.
message
);
}
catch
(
Exception
_error
)
{
TeaException
error
=
new
TeaException
(
_error
.
getMessage
(),
_error
);
System
.
err
.
println
(
"Exception:"
+
error
.
message
);
// 如有需要,请打印 error
com
.
aliyun
.
teautil
.
Common
.
assertAsString
(
error
.
message
);
}
return
null
;
}
}
lefull-lot-common/src/main/java/cn/lefull/common/sdk/ali/base/Face.java
浏览文件 @
23c0a04e
...
...
@@ -2,14 +2,18 @@ package cn.lefull.common.sdk.ali.base;
import
com.aliyun.com.viapi.FileUtils
;
import
com.aliyun.facebody20191230.models.*
;
import
com.aliyun.oss.OSS
;
import
com.aliyun.oss.OSSClientBuilder
;
import
com.aliyun.oss.OSSException
;
import
com.aliyun.oss.model.PutObjectRequest
;
import
com.aliyun.oss.model.PutObjectResult
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.net.URL
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Component
...
...
@@ -186,4 +190,38 @@ public class Face {
FileUtils
fileUtils
=
FileUtils
.
getInstance
(
this
.
accessKeyId
,
this
.
accessKeySecret
);
return
fileUtils
.
upload
(
file
);
}
public
URL
uploadImage
(
String
fileName
,
File
file
)
{
String
objectName
=
(
new
StringBuilder
()
.
append
(
fileName
))
.
toString
();
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
try
{
PutObjectRequest
request
=
new
PutObjectRequest
(
bucketName
,
objectName
,
file
);
ossClient
.
putObject
(
request
);
Date
expiration
=
new
Date
(
System
.
currentTimeMillis
()
+
3600
*
1000
);
URL
url
=
ossClient
.
generatePresignedUrl
(
bucketName
,
objectName
,
expiration
);
System
.
out
.
println
(
url
);
return
url
;
}
catch
(
OSSException
oe
)
{
System
.
err
.
println
(
"Caught an OSSException, which means your request made it to OSS, "
+
"but was rejected with an error response for some reason."
);
System
.
err
.
println
(
"Error Message:"
+
oe
.
getErrorMessage
());
System
.
err
.
println
(
"Error Code:"
+
oe
.
getErrorCode
());
System
.
err
.
println
(
"Request ID:"
+
oe
.
getRequestId
());
System
.
err
.
println
(
"Host ID:"
+
oe
.
getHostId
());
return
null
;
}
finally
{
if
(
ossClient
!=
null
)
{
ossClient
.
shutdown
();
}
}
}
}
lefull-lot-service/src/main/java/cn/lefull/service/ali/FaceService.java
浏览文件 @
23c0a04e
...
...
@@ -45,4 +45,9 @@ public interface FaceService {
* 搜索人脸
*/
boolean
searchFace
(
String
dbName
,
String
url
)
throws
Exception
;
/**
* 搜索人脸
*/
public
void
searchFaces
(
String
dbName
,
String
filePath
)
throws
Exception
;
}
lefull-lot-service/src/main/java/cn/lefull/service/ali/FaceServiceImpl.java
浏览文件 @
23c0a04e
...
...
@@ -15,6 +15,8 @@ import com.aliyun.facebody20191230.models.SearchFaceResponseBody;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.io.File
;
import
java.net.URL
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -157,4 +159,14 @@ public class FaceServiceImpl implements FaceService{
logMapper
.
addLog
(
log
);
return
true
;
}
@Override
public
void
searchFaces
(
String
dbName
,
String
filePath
)
throws
Exception
{
Utils
.
checkParamsNotEmpty
(
dbName
,
"dbName"
);
Utils
.
checkParamsNotEmpty
(
filePath
,
"filePath"
);
File
file
=
new
File
(
filePath
);
URL
url
=
sdk
.
uploadImage
(
dbName
,
"1.jpg"
,
file
);
sdk
.
searchFace
(
dbName
,
url
.
toString
());
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论