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 行增加
和
7 行删除
+126
-7
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
-0
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
差异被折叠。
点击展开。
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论