|
@ -13,7 +13,9 @@ import com.ai.bss.monitorManage.service.interfaces.MonitorManageService;
|
13
|
13
|
import com.ai.bss.monitorManage.utils.DateUtils;
|
14
|
14
|
import com.ai.bss.monitorManage.utils.FileUtils;
|
15
|
15
|
import com.ai.bss.monitorManage.utils.SecurityProtectionMinioConfig;
|
|
16
|
import com.alibaba.druid.sql.visitor.functions.Lcase;
|
16
|
17
|
import com.alibaba.fastjson.JSON;
|
|
18
|
import com.alibaba.fastjson.JSONArray;
|
17
|
19
|
import com.alibaba.fastjson.JSONObject;
|
18
|
20
|
import lombok.SneakyThrows;
|
19
|
21
|
import lombok.extern.slf4j.Slf4j;
|
|
@ -53,7 +55,7 @@ public class MonitorManageServiceImpl implements MonitorManageService {
|
53
|
55
|
private EbcAiService ebcAiService;
|
54
|
56
|
|
55
|
57
|
@Value("${camera.filePath}")
|
56
|
|
private String filePath;
|
|
58
|
private String baseFilePath;
|
57
|
59
|
|
58
|
60
|
@Value("${kafka.topic.aitask}")
|
59
|
61
|
private String topicAiTask;
|
|
@ -79,7 +81,7 @@ public class MonitorManageServiceImpl implements MonitorManageService {
|
79
|
81
|
}
|
80
|
82
|
|
81
|
83
|
private void loadFileList(){
|
82
|
|
File file = new File(filePath);//path为监听文件夹
|
|
84
|
File file = new File(baseFilePath);//path为监听文件夹
|
83
|
85
|
|
84
|
86
|
File[] files = file.listFiles();
|
85
|
87
|
//摄像头列表
|
|
@ -149,7 +151,8 @@ public class MonitorManageServiceImpl implements MonitorManageService {
|
149
|
151
|
bucketName = minioConfig.getBucketAiImage();
|
150
|
152
|
time = fileName.substring(3,17);
|
151
|
153
|
dateTime = DateUtils.formatDate(DateUtils.convertDate(time,DateUtils.PURE_DATETIMEHHMM_PATTERN),DateUtils.NORM_DATETIME_PATTERN);
|
152
|
|
aiIdenLogDto.setTaskExecuteTime(dateTime);
|
|
154
|
aiIdenLogDto.setTaskExecuteTime(DateUtils.getSysDateTime());
|
|
155
|
aiIdenLogDto.setIdenPictureSnapDate(dateTime);
|
153
|
156
|
}
|
154
|
157
|
//文件上传到 minio文件服务器
|
155
|
158
|
multipartFile = new CommonsMultipartFile(createFileItem(new File(filePath),fileName));
|
|
@ -166,32 +169,97 @@ public class MonitorManageServiceImpl implements MonitorManageService {
|
166
|
169
|
aiIdenLogDto.setIdenPictureUrl(minioFileMap.get("fileId"));
|
167
|
170
|
aiIdenLogDto.setResourceToolCode(deviceCode);
|
168
|
171
|
//安全帽识别
|
169
|
|
aiIdenLogDto.setTopic(topicAiTask);//AI识别TOPIC
|
170
|
|
|
171
|
|
try {
|
172
|
|
aiResponseData = ebcAiService.helmetDetect(ImageBase64Converter.convertFileToBase64(filePath), Strings.EMPTY, Strings.EMPTY);
|
173
|
|
System.out.println(JSONUtil.formatJsonStr(aiResponseData));
|
174
|
|
log.info(JSONUtil.formatJsonStr(aiResponseData));
|
175
|
|
// ebcAiService.helmetDetect()
|
176
|
|
//AI模型
|
177
|
|
aiIdenLogDto.setAiIdenModel(MonitorManageConsts.AI_MODEL_IDENTIFY_HELMET);
|
178
|
|
aiIdenLogDto.setIdenResult(JSONUtil.formatJsonStr(aiResponseData));
|
179
|
|
aiIdenLogDto.setIdenResultType("");
|
180
|
|
}catch (Exception e){
|
181
|
|
log.error("AI处理异常");
|
|
172
|
aiIdenLogDto.setTopic(topicAiTask);//AI识别TOPICs
|
|
173
|
|
|
174
|
//人体识别
|
|
175
|
boolean isHuman = aiworkHumanDetect(filePath);
|
|
176
|
//AI头盔检查
|
|
177
|
if(isHuman){
|
|
178
|
aiIdenLogDto = aiHelmetDetect(aiIdenLogDto,filePath);
|
|
179
|
|
|
180
|
kafkaProcess.processKafka(aiIdenLogDto.getTopic(), JSONObject.toJSONString(aiIdenLogDto));
|
182
|
181
|
}
|
183
|
|
kafkaProcess.processKafka(aiIdenLogDto.getTopic(), JSONObject.toJSONString(aiIdenLogDto));
|
184
|
182
|
}
|
185
|
|
|
186
|
183
|
iterator.remove();//使用迭代器的删除方法删除
|
187
|
184
|
}
|
188
|
185
|
|
189
|
186
|
}
|
190
|
|
System.out.println("-------等待任务--------");
|
|
187
|
log.info("-------等待任务--------");
|
191
|
188
|
}
|
192
|
189
|
}, 10000, 10000);
|
193
|
190
|
}
|
194
|
191
|
|
|
192
|
/**
|
|
193
|
* AI头盔检查
|
|
194
|
* @param aiIdenLogDto
|
|
195
|
* @return
|
|
196
|
*/
|
|
197
|
private AiIdenLogDto aiHelmetDetect(AiIdenLogDto aiIdenLogDto,String aifilePath){
|
|
198
|
try {
|
|
199
|
//安全帽识别
|
|
200
|
String aiResponseData = ebcAiService.helmetDetect(ImageBase64Converter.convertFileToBase64(aifilePath), Strings.EMPTY, Strings.EMPTY);
|
|
201
|
// String aiResponseData = ebcAiService.helmetDetect(ImageBase64Converter.convertInputStreamToBase64(multipartFile.getInputStream()), Strings.EMPTY, Strings.EMPTY);
|
|
202
|
JSONObject jsonObject = JSONObject.parseObject(aiResponseData);// JSONUtil.formatJsonStr(aiResponseData);
|
|
203
|
if(jsonObject.getString("Status").equals("Ok")){
|
|
204
|
JSONArray jsonoArray = JSONArray.parseArray(jsonObject.getString("Result"));
|
|
205
|
for(int i=0;i<jsonoArray.size();i++){
|
|
206
|
JSONObject resultObj = JSONObject.parseObject(jsonoArray.get(i).toString());
|
|
207
|
String aiClassName = resultObj.getString("class");
|
|
208
|
// safety_hat表示安全帽;ordinart_hat表示普通帽子;chef_hat表示厨师帽;none表示未戴帽子
|
|
209
|
if(aiClassName.equals("none")){
|
|
210
|
aiIdenLogDto.setIdenResult("未戴帽子");
|
|
211
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.PROCESS_SUCCESS_STATUS);
|
|
212
|
aiIdenLogDto.setAiIdenModel(MonitorManageConsts.AI_MODEL_CLOTHING_CODE);
|
|
213
|
}else{
|
|
214
|
if(aiClassName.equals("safety_hat")){
|
|
215
|
aiIdenLogDto.setIdenResult("安全帽");
|
|
216
|
}else if(aiClassName.equals("ordinart_hat")){
|
|
217
|
aiIdenLogDto.setIdenResult("普通帽子");
|
|
218
|
}else if(aiClassName.equals("chef_hat")){
|
|
219
|
aiIdenLogDto.setIdenResult("厨师帽");
|
|
220
|
}
|
|
221
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.PROCESS_SUCCESS_STATUS);
|
|
222
|
aiIdenLogDto.setAiIdenModel(MonitorManageConsts.AI_MODEL_OTHER);
|
|
223
|
}
|
|
224
|
}
|
|
225
|
}
|
|
226
|
//AI模型
|
|
227
|
// aiIdenLogDto.setAiIdenModel(MonitorManageConsts.AI_MODEL_CLOTHING_CODE);
|
|
228
|
}catch (Exception e){
|
|
229
|
log.error("AI处理异常");
|
|
230
|
}
|
|
231
|
return aiIdenLogDto;
|
|
232
|
}
|
|
233
|
|
|
234
|
/**
|
|
235
|
* AI人体识别
|
|
236
|
* @param aifilePath
|
|
237
|
* @return
|
|
238
|
*/
|
|
239
|
private boolean aiworkHumanDetect(String aifilePath){
|
|
240
|
boolean isHuman = false;
|
|
241
|
try {
|
|
242
|
//安全帽识别
|
|
243
|
String aiResponseData = ebcAiService.workClothesDetect(ImageBase64Converter.convertFileToBase64(aifilePath), true,true,0.9f);
|
|
244
|
|
|
245
|
JSONObject jsonObject = JSONObject.parseObject(aiResponseData);// JSONUtil.formatJsonStr(aiResponseData);
|
|
246
|
if(jsonObject.getString("Status").equals("Ok")){
|
|
247
|
JSONArray jsonoArray = JSONArray.parseArray(jsonObject.getString("Result"));
|
|
248
|
for(int i=0;i<jsonoArray.size();i++){
|
|
249
|
JSONObject resultObj = JSONObject.parseObject(jsonoArray.get(i).toString());
|
|
250
|
String aiClassName = resultObj.getString("lable");
|
|
251
|
// safety_hat表示安全帽;ordinart_hat表示普通帽子;chef_hat表示厨师帽;none表示未戴帽子
|
|
252
|
if(aiClassName.equals("person")){
|
|
253
|
isHuman = true;
|
|
254
|
}
|
|
255
|
}
|
|
256
|
}
|
|
257
|
}catch (Exception e){
|
|
258
|
log.error("AI处理异常");
|
|
259
|
}
|
|
260
|
return isHuman;
|
|
261
|
}
|
|
262
|
|
195
|
263
|
public static List<String> mapTransitionList(Map map) {
|
196
|
264
|
List list = new ArrayList();
|
197
|
265
|
Iterator iter = map.entrySet().iterator(); // 获得map的Iterator
|