Pārlūkot izejas kodu

AI仪表识别,服装识别

wangxu16 4 gadi atpakaļ
vecāks
revīzija
ae36fb97ab

+ 15 - 20
monitor-manage-service/src/main/java/com/ai/bss/monitorManage/service/impl/KafkaProcessImpl.java

@ -36,6 +36,8 @@ import com.alibaba.fastjson.JSONObject;
36 36
37 37
import lombok.extern.slf4j.Slf4j;
38 38
39
import javax.sound.sampled.Line;
40
39 41
@Slf4j
40 42
@Service
41 43
public class KafkaProcessImpl implements KafkaProcess {
@ -129,7 +131,6 @@ public class KafkaProcessImpl implements KafkaProcess {
129 131
		}
130 132
		// 文件上传到 minio文件服务器
131 133
		multipartFile = new CommonsMultipartFile(FileUtils.createFileItem(new File(filePath), fileName));
132
133 134
		log.info("保存图片文件:"+fileName);
134 135
		minioFileMap = fileManageService.uploadFile(multipartFile, bucketName, deviceCode, null);
135 136
@ -375,7 +376,6 @@ public class KafkaProcessImpl implements KafkaProcess {
375 376
			log.info("开始AI人数识别处理...");
376 377
			String aiResponseData = ebcAiService.headDetect(ImageBase64Converter.convertFileToBase64(aifilePath), true,
377 378
					0.9f);
378
379 379
			JSONObject jsonObject = JSONObject.parseObject(aiResponseData);
380 380
			JSONArray jsonArray = jsonObject.getJSONArray("Result");
381 381
			if (!CollectionUtils.isEmpty(jsonArray)) {
@ -384,7 +384,6 @@ public class KafkaProcessImpl implements KafkaProcess {
384 384
			} else {
385 385
				log.info("AI人数识别结果:没有人");
386 386
			}
387
388 387
		} catch (Exception e) {
389 388
			log.error("AI处理异常");
390 389
		}
@ -412,12 +411,10 @@ public class KafkaProcessImpl implements KafkaProcess {
412 411
				if (resultJsonObject.getIntValue("is_match") == 0) {
413 412
					aiIdenLogDto.setIdenResult(jsonObject.getString("result"));
414 413
					aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT);
415
416 414
				} else {
417 415
					aiIdenLogDto.setIdenResult(jsonObject.getString("result"));
418 416
					aiIdenLogDto.setRelateEmployeeRoleId(resultJsonObject.getString("user_id"));
419 417
					aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT_ATTENDANCE);
420
421 418
				}
422 419
423 420
				log.info("识别成功,推送KAFKA消息");
@ -468,8 +465,9 @@ public class KafkaProcessImpl implements KafkaProcess {
468 465
                                    aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT);
469 466
                                }
470 467
                        }
471
                        log.info("识别成功,推送KAFKA消息");
468
						log.info("识别成功,推送KAFKA消息");
472 469
                        processKafka(aiIdenLogDto.getTopic(), JSONObject.toJSONString(aiIdenLogDto));
470
                    	log.info("消息推送完成");
473 471
                    }else{
474 472
                        log.info("没有识别到吸烟者,不推送KAFKA消息");
475 473
                    }
@ -496,12 +494,11 @@ private AiIdenLogDto workClothesDetect(AiIdenLogDto aiIdenLogDto, String aifileP
496 494
		List<IdenResultDto> idenResultDtoList = null;
497 495
		if(jsonObject.getString("Status").equals("Ok")){
498 496
			idenResultDtoList = new ArrayList<>();
499
			JSONArray jsonArray = JSONArray.parseArray(jsonObject.getString("Result"));
500
			if(jsonArray.size()>0){
501
				for (int i = 0; i < jsonArray.size(); i++) {
502
					JSONObject resultObj = JSONObject.parseObject(jsonArray.get(i).toString());
503
					JSONObject jsonArray1 = JSONObject.parseObject(resultObj.getString("clothes"));
504
					String aiClassName =jsonArray1.getString("class");
497
			List<Map> resultList = JSONArray.parseArray(jsonObject.getString("Result"),Map.class);
498
			if(resultList.size()>0){
499
				for (int i = 0; i < resultList.size(); i++) {
500
					JSONObject resultObject = JSONObject.parseObject(resultList.get(i).get("clothes").toString());
501
					String aiClassName =resultObject.getString("class");
505 502
					if(aiClassName.equals("qita")){
506 503
						idenResultDto = new IdenResultDto();
507 504
						idenResultDto.setAlarmEmployeeRoleId(MonitorManageConsts.alarmEmployeeRoleId);
@ -526,6 +523,7 @@ private AiIdenLogDto workClothesDetect(AiIdenLogDto aiIdenLogDto, String aifileP
526 523
				}
527 524
				log.info("识别成功,推送KAFKA消息");
528 525
				processKafka(aiIdenLogDto.getTopic(), JSONObject.toJSONString(aiIdenLogDto));
526
				log.info("消息推送完成");
529 527
			}else {
530 528
				log.info("没有识别到人,不推送KAFKA消息");
531 529
			}
@ -549,16 +547,17 @@ private AiIdenLogDto instrumentDetect(AiIdenLogDto aiIdenLogDto, String aifilePa
549 547
		String aiResponseData=ebcAiService.instrumentDetect(ImageBase64Converter.convertFileToBase64(aifilePath),Strings.EMPTY,Strings.EMPTY,Strings.EMPTY);
550 548
		JSONObject jsonObject = JSONObject.parseObject(aiResponseData);
551 549
		System.out.print("AI识别结果:"+aiResponseData);
552
		JSONObject jsonObjectpredictions=JSONObject.parseObject(jsonObject.getString("predictions"));
550
		JSONObject jsonObjectpredictions=jsonObject.getJSONObject("predictions");
553 551
		if(jsonObjectpredictions.getString("Errors").isEmpty()){
554 552
			if(jsonObjectpredictions.getInteger("Nums")>0){
555 553
				log.info("识别到的仪表的数量为:"+jsonObjectpredictions.getInteger("Nums"));
556 554
				aiIdenLogDto.setIdenResultType(MonitorManageConsts.AI_IDENTIFY_RESULT);
557 555
				aiIdenLogDto.setRelateEmployeeRoleId(MonitorManageConsts.alarmEmployeeRoleId);
558
				log.info("返回的仪表信息为:"+JSON.toJSONString(jsonObject));
559
				aiIdenLogDto.setIdenResult(JSON.toJSONString(jsonObject));
556
				log.info("返回的仪表信息为:"+jsonObjectpredictions.getString("Items"));
557
				aiIdenLogDto.setIdenResult(jsonObjectpredictions.getString("Items"));
560 558
				log.info("识别成功,推送KAFKA消息");
561 559
				processKafka(aiIdenLogDto.getTopic(), JSONObject.toJSONString(aiIdenLogDto));
560
				log.info("消息推送完成");
562 561
			}else{
563 562
				log.info("仪表数量为0,不推送消息");
564 563
			}
@ -570,9 +569,6 @@ private AiIdenLogDto instrumentDetect(AiIdenLogDto aiIdenLogDto, String aifilePa
570 569
	}
571 570
	return aiIdenLogDto;
572 571
}
573
574
575
576 572
	/**
577 573
	 * 根据设备code获取监控任务详情
578 574
	 * @param deviceCode
@ -580,11 +576,10 @@ private AiIdenLogDto instrumentDetect(AiIdenLogDto aiIdenLogDto, String aifilePa
580 576
	 */
581 577
	private List<Map> getResourceToolAllInfo(String deviceCode) {
582 578
		List<Map> resourceToolInfoList = new ArrayList<Map>();
583
579
		deviceCode="6L04C6FPAGFD039";
584 580
		try {
585 581
			String url = protectionResourceUrl + "?resourceToolCode=" + deviceCode;
586 582
			log.info("getResourceToolAllInfo method params: resourceToolCode=" + deviceCode + ", url=" + url);
587
588 583
			String resultJson = HttpServiceUtil.sendRequest(url);
589 584
			JSONObject resultData = JSON.parseObject(resultJson);
590 585
			if (StringUtils.isEmpty(resultData.getString("data"))) {