1.缺陷自动标注修改

2.增加dev数据源,避免模型问题路径问题导致无法启动
This commit is contained in:
cuizhibin 2025-07-04 15:36:26 +08:00
parent cbe77aeef3
commit 105e339464
14 changed files with 77 additions and 43 deletions

View File

@ -61,4 +61,5 @@ public class Message implements Serializable {
public static final String WORK_SHIFT_NAME_EXIST = "班次名称已经存在"; public static final String WORK_SHIFT_NAME_EXIST = "班次名称已经存在";
public static final String WORK_SHIFT_NOT_EXIST = "班次不存在"; public static final String WORK_SHIFT_NOT_EXIST = "班次不存在";
public static final String WORK_SHIFT_IS_NOT_UNPUBLISH = "班次的状态不是未发布"; public static final String WORK_SHIFT_IS_NOT_UNPUBLISH = "班次的状态不是未发布";
public static final String IMAGE_AUTO_MARK_ERROR = "自动标注出错:";
} }

View File

@ -23,9 +23,6 @@ public class DefectMarkReq implements Serializable {
@ApiModelProperty("图片id") @ApiModelProperty("图片id")
private String imageId; private String imageId;
@ApiModelProperty("图片集id")
private String collectId;
@NotBlank(groups = {ValidationGroup.Request.class}, message = "模型id不能为空") @NotBlank(groups = {ValidationGroup.Request.class}, message = "模型id不能为空")
@ApiModelProperty("模型id") @ApiModelProperty("模型id")
private String modelId; private String modelId;

View File

@ -1,5 +1,6 @@
package com.dite.znpt.domain.vo; package com.dite.znpt.domain.vo;
import com.dite.znpt.domain.bo.Detection;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -51,6 +52,9 @@ public class DefectReq implements Serializable {
@ApiModelProperty("标注信息") @ApiModelProperty("标注信息")
private String labelInfo; private String labelInfo;
@ApiModelProperty("标注信息")
private Detection markInfo;
@ApiModelProperty("说明") @ApiModelProperty("说明")
private String description; private String description;

View File

@ -1,16 +1,11 @@
package com.dite.znpt.domain.vo; package com.dite.znpt.domain.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDate;
/** /**
* @author huise23 * @author huise23
@ -27,6 +22,9 @@ public class DefectResp extends DefectReq implements Serializable {
@ApiModelProperty("缺陷id") @ApiModelProperty("缺陷id")
private String defectId; private String defectId;
@ApiModelProperty("图像id")
private String imageId;
@ApiModelProperty("缺陷类型描述") @ApiModelProperty("缺陷类型描述")
private String defectTypeLabel; private String defectTypeLabel;

View File

@ -13,7 +13,7 @@ import java.util.List;
*/ */
@Getter @Getter
public enum DefectTypeEnum { public enum DefectTypeEnum {
CRAZE("BMLW", "合缝开裂"), BMLW("bmlw", "表面裂纹"),
ABRASION("ABRASION", "合缝磨损"), ABRASION("ABRASION", "合缝磨损"),
LEATHER_BREAKAGE("LEATHER_BREAKAGE", "蒙皮破损"), LEATHER_BREAKAGE("LEATHER_BREAKAGE", "蒙皮破损"),
FABRIC_BREAKAGE("FABRIC_BREAKAGE", "布层破损"), FABRIC_BREAKAGE("FABRIC_BREAKAGE", "布层破损"),

View File

@ -14,8 +14,7 @@ public enum FilePathEnum {
IMAGE_TEMP("/static/image/temp/", "image-temp"), IMAGE_TEMP("/static/image/temp/", "image-temp"),
VIDEO("/static/video/", "video"), VIDEO("/static/video/", "video"),
AUDIO("/static/audio/", "audio"), AUDIO("/static/audio/", "audio"),
ATTACH("/static/attach/", "attach"), ATTACH("/static/attach/", "attach");
INSURANCE("/static/insurance/", "insurance");
@Getter @Getter
private final String urlPath; private final String urlPath;

View File

@ -13,19 +13,17 @@ import java.util.List;
*/ */
@Getter @Getter
public enum ImageSourceEnum { public enum ImageSourceEnum {
COLLECT("collect", "图像采集", Boolean.TRUE), COLLECT("collect", "图像采集"),
OUT_WORK("out-work", "外部工作", Boolean.TRUE), OUT_WORK("out-work", "外部工作"),
IN_WORK("in-work", "内部工作", Boolean.TRUE), IN_WORK("in-work", "内部工作"),
LIGHTNING_PROTECTING_WORK("lightning-protection-work", "防雷工作", Boolean.FALSE); LIGHTNING_PROTECTING_WORK("lightning-protection-work", "防雷工作");
private final String code; private final String code;
private final String desc; private final String desc;
private final boolean isDefectImage;
ImageSourceEnum(String code, String desc, boolean isDefectImage){ ImageSourceEnum(String code, String desc){
this.code = code; this.code = code;
this.desc = desc; this.desc = desc;
this.isDefectImage = isDefectImage;
} }
public static ImageSourceEnum getByCode(String code){ public static ImageSourceEnum getByCode(String code){
@ -42,15 +40,13 @@ public enum ImageSourceEnum {
return null == e ? null : e.desc; return null == e ? null : e.desc;
} }
public static List<JSONObject> list(Boolean isDefectImage){ public static List<JSONObject> list(){
List<JSONObject> list = new ArrayList<>(ImageSourceEnum.values().length); List<JSONObject> list = new ArrayList<>(ImageSourceEnum.values().length);
for (ImageSourceEnum e : ImageSourceEnum.values() ) { for (ImageSourceEnum e : ImageSourceEnum.values() ) {
if(isDefectImage.equals(e.isDefectImage)){
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.set(e.code, e.desc); jsonObject.set(e.code, e.desc);
list.add(jsonObject); list.add(jsonObject);
} }
}
return list; return list;
} }
} }

View File

@ -77,10 +77,10 @@ public interface DefectService extends IService<DefectEntity> {
* 功能描述缺陷自动检测 * 功能描述缺陷自动检测
* *
* @param markReq 马克请求类 * @param markReq 马克请求类
* @return {@link DefectResp } * @return {@link List }<{@link DefectResp }>
* @author cuizhibin * @author cuizhibin
* @date 2025/07/04 10:55 * @date 2025/07/04 14:53
**/ **/
DefectResp detect(DefectMarkReq markReq); List<DefectResp> detect(DefectMarkReq markReq);
} }

View File

@ -1,15 +1,17 @@
package com.dite.znpt.service.impl; package com.dite.znpt.service.impl;
import ai.onnxruntime.OrtException;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dite.znpt.constant.Message; import com.dite.znpt.constant.Message;
import com.dite.znpt.converts.Converts; import com.dite.znpt.converts.Converts;
import com.dite.znpt.domain.bo.Detection;
import com.dite.znpt.domain.entity.DefectEntity; import com.dite.znpt.domain.entity.DefectEntity;
import com.dite.znpt.domain.entity.ImageEntity; import com.dite.znpt.domain.entity.ImageEntity;
import com.dite.znpt.domain.vo.*; import com.dite.znpt.domain.vo.*;
import com.dite.znpt.enums.DefectSourceEnum; import com.dite.znpt.enums.*;
import com.dite.znpt.enums.DefectTypeEnum;
import com.dite.znpt.enums.RepairStatusEnum;
import com.dite.znpt.exception.ServiceException; import com.dite.znpt.exception.ServiceException;
import com.dite.znpt.mapper.DefectMapper; import com.dite.znpt.mapper.DefectMapper;
import com.dite.znpt.service.DefectService; import com.dite.znpt.service.DefectService;
@ -21,9 +23,11 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -51,12 +55,19 @@ public class DefectServiceImpl extends ServiceImpl<DefectMapper, DefectEntity> i
@Override @Override
public List<DefectResp> page(DefectListReq req) { public List<DefectResp> page(DefectListReq req) {
PageUtil.startPage(); PageUtil.startPage();
return this.list(req); List<DefectResp> list = this.list(req);
list.forEach(defect -> {
defect.setMarkInfo(JSONUtil.toBean(defect.getLabelInfo(), Detection.class));
});
return list;
} }
@Override @Override
public List<DefectResp> list(DefectListReq req) { public List<DefectResp> list(DefectListReq req) {
List<DefectResp> defectList= this.baseMapper.queryBySelective(req); List<DefectResp> defectList= this.baseMapper.queryBySelective(req);
defectList.forEach(defect -> {
defect.setMarkInfo(JSONUtil.toBean(defect.getLabelInfo(), Detection.class));
});
return defectList; return defectList;
} }
@ -72,9 +83,10 @@ public class DefectServiceImpl extends ServiceImpl<DefectMapper, DefectEntity> i
public DefectResp detail(String defectId) { public DefectResp detail(String defectId) {
DefectResp defectResp = this.baseMapper.detail(defectId); DefectResp defectResp = this.baseMapper.detail(defectId);
defectResp.setDefectTypeLabel(DefectTypeEnum.getDescByCode(defectResp.getDefectType())); defectResp.setDefectTypeLabel(DefectTypeEnum.getDescByCode(defectResp.getDefectType()));
defectResp.setDefectLevel(DefectTypeEnum.getDescByCode(defectResp.getDefectLevel())); defectResp.setDefectLevel(DefectLevelEnum.getDescByCode(defectResp.getDefectLevel()));
defectResp.setRepairStatusLabel(RepairStatusEnum.getDescByCode(defectResp.getRepairStatus())); defectResp.setRepairStatusLabel(RepairStatusEnum.getDescByCode(defectResp.getRepairStatus()));
defectResp.setSourceLabel(DefectSourceEnum.getDescByCode(defectResp.getSourceLabel())); defectResp.setSourceLabel(DefectSourceEnum.getDescByCode(defectResp.getSourceLabel()));
defectResp.setMarkInfo(JSONUtil.toBean(defectResp.getLabelInfo(), Detection.class));
return defectResp; return defectResp;
} }
@ -94,6 +106,7 @@ public class DefectServiceImpl extends ServiceImpl<DefectMapper, DefectEntity> i
} }
DefectEntity defectEntity = Converts.INSTANCE.toDefectEntity(req); DefectEntity defectEntity = Converts.INSTANCE.toDefectEntity(req);
defectEntity.setImageId(imageId); defectEntity.setImageId(imageId);
defectEntity.setLabelInfo(JSONUtil.toJsonStr(req.getMarkInfo()));
this.save(defectEntity); this.save(defectEntity);
} }
@ -115,6 +128,7 @@ public class DefectServiceImpl extends ServiceImpl<DefectMapper, DefectEntity> i
if(imageMap.containsKey(key)){ if(imageMap.containsKey(key)){
DefectEntity defectEntity = Converts.INSTANCE.toDefectEntity(req); DefectEntity defectEntity = Converts.INSTANCE.toDefectEntity(req);
defectEntity.setImageId(imageMap.get(key).getImageId()); defectEntity.setImageId(imageMap.get(key).getImageId());
defectEntity.setLabelInfo(JSONUtil.toJsonStr(req.getMarkInfo()));
defectEntityList.add(defectEntity); defectEntityList.add(defectEntity);
} }
}); });
@ -137,6 +151,7 @@ public class DefectServiceImpl extends ServiceImpl<DefectMapper, DefectEntity> i
throw new ServiceException(Message.DEFECT_ID_IS_NOT_EXIST); throw new ServiceException(Message.DEFECT_ID_IS_NOT_EXIST);
} }
DefectEntity defectEntity = Converts.INSTANCE.toDefectEntity(req); DefectEntity defectEntity = Converts.INSTANCE.toDefectEntity(req);
defectEntity.setLabelInfo(JSONUtil.toJsonStr(req.getMarkInfo()));
this.updateById(defectEntity); this.updateById(defectEntity);
} }
@ -157,13 +172,38 @@ public class DefectServiceImpl extends ServiceImpl<DefectMapper, DefectEntity> i
* 功能描述缺陷自动检测 * 功能描述缺陷自动检测
* *
* @param markReq 马克请求类 * @param markReq 马克请求类
* @return {@link DefectResp } * @return {@link List }<{@link DefectResp }>
* @author cuizhibin * @author cuizhibin
* @date 2025/07/04 10:55 * @date 2025/07/04 10:55
**/ **/
@Override @Override
public DefectResp detect(DefectMarkReq markReq) { public List<DefectResp> detect(DefectMarkReq markReq) {
// multiModelYoloService.runFolderDetection(); ImageEntity image = imageService.getById(markReq.getImageId());
return null; if (Objects.isNull(image)) {
throw new ServiceException(Message.IMAGE_ID_IS_NOT_EXIST);
}
FilePathEnum pathEnum = image.getImagePath().contains("temp") ? FilePathEnum.IMAGE_TEMP : FilePathEnum.IMAGE;
String inputPath = pathEnum.getFileAbsolutePath(image.getImagePath());
String outputPath = FileUtil.getParent(inputPath, 1).concat(FileUtil.mainName(inputPath)+"_mark").concat(StrUtil.DOT).concat(FileUtil.extName(inputPath));
try {
List<Detection> detect = multiModelYoloService.detect(markReq.getModelId(), inputPath, outputPath, markReq.getConfThreshold());
List<DefectResp> respList = new ArrayList<>();
for (Detection detection : detect) {
DefectResp resp = new DefectResp();
resp.setImageId(markReq.getImageId());
resp.setDefectType(detection.getLabel());
resp.setDefectTypeLabel(DefectTypeEnum.getDescByCode(detection.getLabel()));
resp.setDetectionDate(LocalDate.now());
resp.setSource(DefectSourceEnum.AI.getCode());
resp.setSourceLabel(DefectSourceEnum.AI.getDesc());
resp.setMarkInfo(detection);
resp.setRepairStatus(RepairStatusEnum.INCOMPLETE.getCode());
resp.setRepairStatusLabel(RepairStatusEnum.INCOMPLETE.getDesc());
respList.add(resp);
}
return respList;
} catch (OrtException e) {
throw new ServiceException(Message.IMAGE_AUTO_MARK_ERROR + e.getMessage());
}
} }
} }

View File

@ -148,7 +148,7 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
temCategory.mkdirs(); temCategory.mkdirs();
} }
String temPathPrefix = FilePathEnum.IMAGE_TEMP.getFileAbsolutePathPrefix().concat(imageSource).concat(FileUtil.FILE_SEPARATOR).concat(partId).concat(FileUtil.FILE_SEPARATOR); String temPathPrefix = FilePathEnum.IMAGE_TEMP.getFileAbsolutePathPrefix().concat(imageSource).concat(FileUtil.FILE_SEPARATOR).concat(partId).concat(FileUtil.FILE_SEPARATOR);
ImageCollectEntity imageCollect = BeanUtil.copyProperties(collectReq, ImageCollectEntity.class); ImageCollectEntity imageCollect = Optional.ofNullable(BeanUtil.copyProperties(collectReq, ImageCollectEntity.class)).orElse(new ImageCollectEntity());
imageCollect.setCollectId(IdUtil.simpleUUID()); imageCollect.setCollectId(IdUtil.simpleUUID());
List<ImageEntity> imageList = new ArrayList<>(); List<ImageEntity> imageList = new ArrayList<>();
for (MultipartFile file : files) { for (MultipartFile file : files) {

View File

@ -90,7 +90,7 @@ public class CommonController {
@ApiOperation(value = "查询通用图片来源", httpMethod = "GET") @ApiOperation(value = "查询通用图片来源", httpMethod = "GET")
@GetMapping("/list/common-image-source") @GetMapping("/list/common-image-source")
public Result<?> listCommonImageSource(){ public Result<?> listCommonImageSource(){
return Result.ok(ImageSourceEnum.list(Boolean.FALSE)); return Result.ok(ImageSourceEnum.list());
} }
@ApiOperation(value = "查询学历", httpMethod = "GET") @ApiOperation(value = "查询学历", httpMethod = "GET")

View File

@ -68,8 +68,8 @@ public class DefectController {
} }
@ApiOperation(value = "单图自动标注缺陷", httpMethod = "POST") @ApiOperation(value = "单图自动标注缺陷", httpMethod = "POST")
@PostMapping("/run") @PostMapping("/detect")
public Result<DefectResp> runBatch(@Validated(ValidationGroup.Request.class) @RequestBody DefectMarkReq markReq) { public Result<List<DefectResp>> runBatch(@Validated(ValidationGroup.Request.class) @RequestBody DefectMarkReq markReq) {
return Result.ok(defectService.detect(markReq)); return Result.ok(defectService.detect(markReq));
} }
} }

View File

@ -4,7 +4,6 @@ package com.dite.znpt.web.controller;
import com.dite.znpt.domain.PageResult; import com.dite.znpt.domain.PageResult;
import com.dite.znpt.domain.Result; import com.dite.znpt.domain.Result;
import com.dite.znpt.domain.vo.*; import com.dite.znpt.domain.vo.*;
import com.dite.znpt.enums.ImageSourceEnum;
import com.dite.znpt.service.ImageCollectService; import com.dite.znpt.service.ImageCollectService;
import com.dite.znpt.service.ImageService; import com.dite.znpt.service.ImageService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -60,7 +59,7 @@ public class ImageController {
@PostMapping("/{imageSource}/upload/{partId}") @PostMapping("/{imageSource}/upload/{partId}")
public Result<String> uploadOutWork(@PathVariable String imageSource, @PathVariable String partId, ImageCollectReq collectReq, @RequestParam("file") MultipartFile file) { public Result<String> uploadOutWork(@PathVariable String imageSource, @PathVariable String partId, ImageCollectReq collectReq, @RequestParam("file") MultipartFile file) {
MultipartFile[] files = {file}; MultipartFile[] files = {file};
return Result.ok(imageService.batchUploadDefectImage(partId, ImageSourceEnum.OUT_WORK.getCode(), collectReq, files).get(0).getImagePath()); return Result.ok(imageService.batchUploadDefectImage(partId, imageSource, collectReq, files).get(0).getImagePath());
} }
@ApiOperation(value = "设置信息", httpMethod = "POST") @ApiOperation(value = "设置信息", httpMethod = "POST")

View File

@ -8,7 +8,7 @@ spring:
datasource: datasource:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://39.99.201.243:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://39.99.201.243:3306/znpt_dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root username: root
password: BUw8YW6%@^8q password: BUw8YW6%@^8q
druid: druid: