|
@ -6,6 +6,7 @@ import java.util.HashMap;
|
6
|
6
|
import java.util.List;
|
7
|
7
|
import java.util.Map;
|
8
|
8
|
|
|
9
|
import com.ai.bss.monitorManage.model.FaceResultDto;
|
9
|
10
|
import org.apache.commons.lang.StringUtils;
|
10
|
11
|
import org.apache.logging.log4j.util.Strings;
|
11
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -183,6 +184,7 @@ public class KafkaProcessImpl implements KafkaProcess {
|
183
|
184
|
aiIdenLogDto=instrumentDetect(aiIdenLogDto,filePath);//仪表识别
|
184
|
185
|
|
185
|
186
|
} else if (MonitorManageConsts.AI_MODEL_STRANGER.equals(aiIdenModel)){
|
|
187
|
aiIdenLogDto=strangerDetect(aiIdenLogDto,filePath);//陌生人识别
|
186
|
188
|
|
187
|
189
|
} else {
|
188
|
190
|
|
|
@ -190,15 +192,6 @@ public class KafkaProcessImpl implements KafkaProcess {
|
190
|
192
|
}
|
191
|
193
|
}
|
192
|
194
|
|
193
|
|
/*// 安全帽识别
|
194
|
|
aiIdenLogDto.setTopic(topicAiTask);// AI识别TOPICs
|
195
|
|
|
196
|
|
// 人体识别
|
197
|
|
boolean isHuman = aiworkHumanDetect(filePath);
|
198
|
|
// AI头盔检查
|
199
|
|
if (isHuman) {
|
200
|
|
aiIdenLogDto = aiHelmetDetect(aiIdenLogDto, filePath);
|
201
|
|
}*/
|
202
|
195
|
}
|
203
|
196
|
|
204
|
197
|
log.info("-------等待任务--------");
|
|
@ -207,7 +200,14 @@ public class KafkaProcessImpl implements KafkaProcess {
|
207
|
200
|
@Async
|
208
|
201
|
@Override
|
209
|
202
|
public void processVideoFile(String fileKey, String filePath) throws Exception {
|
210
|
|
Thread.sleep(70000);
|
|
203
|
String fileExpandedName=filePath.substring(filePath.lastIndexOf(".")+1);
|
|
204
|
if ("m3u8".equals(fileExpandedName)){
|
|
205
|
Thread.sleep(10000);
|
|
206
|
return;
|
|
207
|
}else{
|
|
208
|
Thread.sleep(70000);
|
|
209
|
}
|
|
210
|
|
211
|
211
|
String deviceCode = "";
|
212
|
212
|
String fileType = "";
|
213
|
213
|
String fileName = "";
|
|
@ -225,6 +225,7 @@ public class KafkaProcessImpl implements KafkaProcess {
|
225
|
225
|
monitorVideoLogDto = new MonitorVideoLogDto();
|
226
|
226
|
fileName = filePath.substring(filePath.lastIndexOf(MonitorManageConsts.getSystemSeparator()) + 1,
|
227
|
227
|
filePath.length());
|
|
228
|
|
228
|
229
|
if (fileType.equals(MonitorManageConsts.FILE_TYPE_VIDEO)) {
|
229
|
230
|
bucketName = minioConfig.getBucketAiVideo();
|
230
|
231
|
time = fileName.substring(5, 19);
|
|
@ -260,7 +261,7 @@ public class KafkaProcessImpl implements KafkaProcess {
|
260
|
261
|
String time = fileName.substring(5, 19);
|
261
|
262
|
String dateTime = DateUtils.formatDate(DateUtils.convertDate(time, DateUtils.PURE_DATETIME_PATTERN),
|
262
|
263
|
DateUtils.NORM_DATETIME_HHMM_PATTERN);
|
263
|
|
System.out.println(dateTime);
|
|
264
|
log.info(dateTime);
|
264
|
265
|
}
|
265
|
266
|
|
266
|
267
|
private Map<String, KafkaTemplate> kafkaTemplateMap = new HashMap<>();
|
|
@ -276,7 +277,7 @@ public class KafkaProcessImpl implements KafkaProcess {
|
276
|
277
|
|
277
|
278
|
try {
|
278
|
279
|
Object result = kafkaTemplate.send(topic, msgStr).get();
|
279
|
|
System.out.println("发送kafka消息:topic=" + topic + "msg: " + msgStr);
|
|
280
|
log.info("发送kafka消息:topic=" + topic + "msg: " + msgStr);
|
280
|
281
|
} catch (Exception e) {
|
281
|
282
|
log.error(e.getMessage());
|
282
|
283
|
return false;
|
|
@ -298,7 +299,7 @@ public class KafkaProcessImpl implements KafkaProcess {
|
298
|
299
|
Strings.EMPTY, Strings.EMPTY);
|
299
|
300
|
// String aiResponseData = ebcAiService.helmetDetect(ImageBase64Converter.convertInputStreamToBase64(multipartFile.getInputStream()), Strings.EMPTY, Strings.EMPTY);
|
300
|
301
|
JSONObject jsonObject = JSONObject.parseObject(aiResponseData);// JSONUtil.formatJsonStr(aiResponseData);
|
301
|
|
System.out.println("AI帽子识别结果: " + jsonObject);
|
|
302
|
log.info("AI帽子识别结果: " + jsonObject);
|
302
|
303
|
IdenResultDto idenResultDto = null;
|
303
|
304
|
List<IdenResultDto> idenResultDtoList = null;
|
304
|
305
|
if (jsonObject.getString("Status").equals("Ok")) {
|
|
@ -309,27 +310,26 @@ public class KafkaProcessImpl implements KafkaProcess {
|
309
|
310
|
JSONObject resultObj = JSONObject.parseObject(jsonoArray.get(i).toString());
|
310
|
311
|
String aiClassName = resultObj.getString("class");
|
311
|
312
|
// safety_hat表示安全帽;ordinart_hat表示普通帽子;chef_hat表示厨师帽;none表示未戴帽子
|
312
|
|
if (aiClassName.equals("none")) {
|
|
313
|
if(aiClassName.equals("safety_hat")){
|
313
|
314
|
idenResultDto = new IdenResultDto();
|
314
|
315
|
idenResultDto.setAlarmEmployeeRoleId(MonitorManageConsts.alarmEmployeeRoleId);
|
315
|
|
idenResultDto.setAlarmType(MonitorManageConsts.AI_ALARM_TYPE_WEA);
|
316
|
|
idenResultDto.setAlarmMemo("未戴帽子");
|
317
|
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT_ALARM);
|
|
316
|
idenResultDto.setAlarmType(aiClassName);
|
|
317
|
idenResultDto.setAlarmMemo(aiClassName);
|
318
|
318
|
idenResultDtoList.add(idenResultDto);
|
319
|
319
|
// aiIdenLogDto.setIdenResult(idenResultDtoList);
|
320
|
320
|
aiIdenLogDto.setIdenResult(JSON.toJSONString(idenResultDtoList));
|
|
321
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT);
|
321
|
322
|
// aiIdenLogDto.setAiIdenModel(MonitorManageConsts.AI_MODEL_CLOTHING_CODE);
|
322
|
323
|
aiIdenLogDto.setRelateEmployeeRoleId(MonitorManageConsts.alarmEmployeeRoleId);
|
323
|
|
} else {
|
324
|
|
// if(aiClassName.equals("safety_hat")){
|
|
324
|
}else{
|
325
|
325
|
idenResultDto = new IdenResultDto();
|
326
|
326
|
idenResultDto.setAlarmEmployeeRoleId(MonitorManageConsts.alarmEmployeeRoleId);
|
327
|
|
idenResultDto.setAlarmType(aiClassName);
|
328
|
|
idenResultDto.setAlarmMemo(aiClassName);
|
|
327
|
idenResultDto.setAlarmType(MonitorManageConsts.AI_ALARM_TYPE_WEA);
|
|
328
|
idenResultDto.setAlarmMemo("未戴安全帽");
|
|
329
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT_ALARM);
|
329
|
330
|
idenResultDtoList.add(idenResultDto);
|
330
|
331
|
// aiIdenLogDto.setIdenResult(idenResultDtoList);
|
331
|
332
|
aiIdenLogDto.setIdenResult(JSON.toJSONString(idenResultDtoList));
|
332
|
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT);
|
333
|
333
|
// aiIdenLogDto.setAiIdenModel(MonitorManageConsts.AI_MODEL_CLOTHING_CODE);
|
334
|
334
|
aiIdenLogDto.setRelateEmployeeRoleId(MonitorManageConsts.alarmEmployeeRoleId);
|
335
|
335
|
}
|
|
@ -403,31 +403,116 @@ public class KafkaProcessImpl implements KafkaProcess {
|
403
|
403
|
String aiResponseData = ebcAiService.faceAiRecog(ImageBase64Converter.convertFileToBase64(aifilePath));
|
404
|
404
|
|
405
|
405
|
JSONObject jsonObject = JSONObject.parseObject(aiResponseData);
|
406
|
|
System.out.println("AI人脸识别结果: " + aiResponseData);
|
|
406
|
log.info("AI人脸识别结果: " + aiResponseData);
|
407
|
407
|
|
408
|
|
if ("1".equals(jsonObject.getString("errorcode")) && "success".equals(jsonObject.getString("message"))) {
|
409
|
|
JSONObject resultJsonObject = JSONObject.parseObject(jsonObject.getString("result"));
|
|
408
|
if (!"OK".equals(jsonObject.getString("Des")) || !"OK".equals(jsonObject.getString("Status"))) {
|
|
409
|
log.info("人脸识别返回错误,不推送KAFKA消息");
|
|
410
|
return aiIdenLogDto;
|
|
411
|
}
|
|
412
|
|
|
413
|
if (jsonObject.get("result")==null){
|
|
414
|
log.info("人脸识别没有识别到人,不推送KAFKA消息");
|
|
415
|
return aiIdenLogDto;
|
|
416
|
}
|
|
417
|
|
|
418
|
List<Map> resultList = JSONArray.parseArray(jsonObject.getString("result"),Map.class);
|
|
419
|
FaceResultDto resultDto=null;
|
|
420
|
|
|
421
|
for (Map resultMap:resultList) {
|
|
422
|
resultDto=new FaceResultDto();
|
|
423
|
String faceId=String.valueOf(resultMap.get("faceid"));
|
|
424
|
|
|
425
|
if ("null".equals(faceId)||"Unknow".equals(faceId)){
|
|
426
|
resultDto.setUserId(MonitorManageConsts.alarmEmployeeRoleId);
|
|
427
|
resultDto.setSimi((float)resultMap.get("score"));
|
|
428
|
resultDto.setIsMatch(0);
|
|
429
|
resultDto.setFaceBox((int[]) resultMap.get("box"));
|
410
|
430
|
|
411
|
|
if (resultJsonObject.getIntValue("is_match") == 0) {
|
412
|
|
aiIdenLogDto.setIdenResult(jsonObject.getString("result"));
|
413
|
431
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT);
|
414
|
|
} else {
|
415
|
|
aiIdenLogDto.setIdenResult(jsonObject.getString("result"));
|
416
|
|
aiIdenLogDto.setRelateEmployeeRoleId(resultJsonObject.getString("user_id"));
|
|
432
|
}else {
|
|
433
|
resultDto.setUserId(faceId);
|
|
434
|
resultDto.setSimi((float)resultMap.get("score"));
|
|
435
|
resultDto.setIsMatch(1);
|
|
436
|
resultDto.setFaceBox((int[]) resultMap.get("box"));
|
|
437
|
|
|
438
|
aiIdenLogDto.setRelateEmployeeRoleId(faceId);
|
417
|
439
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT_ATTENDANCE);
|
418
|
440
|
}
|
419
|
441
|
|
|
442
|
aiIdenLogDto.setIdenResult(JSON.toJSONString(resultDto));
|
420
|
443
|
log.info("识别成功,推送KAFKA消息");
|
421
|
444
|
processKafka(aiIdenLogDto.getTopic(), JSONObject.toJSONString(aiIdenLogDto));
|
422
|
|
} else {
|
423
|
|
log.info("没有识别到人,不推送KAFKA消息");
|
424
|
|
return aiIdenLogDto;
|
425
|
445
|
}
|
|
446
|
|
426
|
447
|
} catch (Exception e) {
|
427
|
448
|
log.error("AI处理异常,人脸识别");
|
428
|
449
|
}
|
429
|
450
|
return aiIdenLogDto;
|
430
|
451
|
}
|
|
452
|
|
|
453
|
/**
|
|
454
|
* 陌生人识别
|
|
455
|
* @param aiIdenLogDto
|
|
456
|
* @param aifilePath
|
|
457
|
* @return
|
|
458
|
*/
|
|
459
|
private AiIdenLogDto strangerDetect(AiIdenLogDto aiIdenLogDto, String aifilePath) {
|
|
460
|
try {
|
|
461
|
log.info("开始AI陌生人识别处理...");
|
|
462
|
// 人脸识别
|
|
463
|
String aiResponseData = ebcAiService.faceAiRecog(ImageBase64Converter.convertFileToBase64(aifilePath));
|
|
464
|
|
|
465
|
JSONObject jsonObject = JSONObject.parseObject(aiResponseData);
|
|
466
|
log.info("AI陌生人识别结果: " + aiResponseData);
|
|
467
|
|
|
468
|
if (!"OK".equals(jsonObject.getString("Des")) || !"OK".equals(jsonObject.getString("Status"))) {
|
|
469
|
log.info("陌生人识别返回错误,不推送KAFKA消息");
|
|
470
|
return aiIdenLogDto;
|
|
471
|
}
|
|
472
|
|
|
473
|
if (jsonObject.get("result")==null){
|
|
474
|
log.info("陌生人识别没有识别到人,不推送KAFKA消息");
|
|
475
|
return aiIdenLogDto;
|
|
476
|
}
|
|
477
|
|
|
478
|
String resultJson=jsonObject.getString("result");
|
|
479
|
List<Map> resultList = JSONArray.parseArray(resultJson,Map.class);
|
|
480
|
|
|
481
|
IdenResultDto idenResultDto = null;
|
|
482
|
List<IdenResultDto> idenResultDtoList = new ArrayList<IdenResultDto>();
|
|
483
|
|
|
484
|
for (Map resultMap:resultList) {
|
|
485
|
String faceId=String.valueOf(resultMap.get("faceid"));
|
|
486
|
if ("null".equals(faceId)||"Unknow".equals(faceId)){
|
|
487
|
log.info("检测到陌生人");
|
|
488
|
idenResultDto = new IdenResultDto();
|
|
489
|
idenResultDto.setAlarmEmployeeRoleId(MonitorManageConsts.alarmEmployeeRoleId);
|
|
490
|
idenResultDto.setAlarmType(MonitorManageConsts.AI_ALARM_TYPE_STA);
|
|
491
|
idenResultDto.setAlarmMemo("陌生人");
|
|
492
|
idenResultDto.setAlarmBox((int[]) resultMap.get("box"));
|
|
493
|
idenResultDtoList.add(idenResultDto);
|
|
494
|
}
|
|
495
|
}
|
|
496
|
|
|
497
|
if (!CollectionUtils.isEmpty(idenResultDtoList)){
|
|
498
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT_ALARM);
|
|
499
|
aiIdenLogDto.setIdenResult(JSON.toJSONString(idenResultDtoList));
|
|
500
|
aiIdenLogDto.setRelateEmployeeRoleId(MonitorManageConsts.alarmEmployeeRoleId);
|
|
501
|
}else{
|
|
502
|
aiIdenLogDto.setIdenResult(resultJson);
|
|
503
|
aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT);
|
|
504
|
}
|
|
505
|
|
|
506
|
log.info("陌生人识别成功,推送KAFKA消息");
|
|
507
|
processKafka(aiIdenLogDto.getTopic(), JSONObject.toJSONString(aiIdenLogDto));
|
|
508
|
log.info("消息推送完成");
|
|
509
|
|
|
510
|
} catch (Exception e) {
|
|
511
|
log.error("AI处理异常,陌生人识别");
|
|
512
|
}
|
|
513
|
return aiIdenLogDto;
|
|
514
|
}
|
|
515
|
|
431
|
516
|
/**
|
432
|
517
|
* AI吸烟检测
|
433
|
518
|
*
|
|
@ -437,6 +522,7 @@ public class KafkaProcessImpl implements KafkaProcess {
|
437
|
522
|
log.info("开始AI抽烟识别处理...");
|
438
|
523
|
//抽烟识别
|
439
|
524
|
String aiResponseData=ebcAiService.smokingDetect(ImageBase64Converter.convertFileToBase64(aifilePath));
|
|
525
|
|
440
|
526
|
IdenResultDto idenResultDto = null;
|
441
|
527
|
List<IdenResultDto> idenResultDtoList = null;
|
442
|
528
|
JSONObject jsonObject = JSONObject.parseObject(aiResponseData);
|