修改 imageToSketch
This commit is contained in:
@@ -4,6 +4,7 @@ import com.ai.da.common.response.Response;
|
||||
import com.ai.da.model.dto.GenerateLikeDTO;
|
||||
import com.ai.da.model.dto.GenerateModifyDTO;
|
||||
import com.ai.da.model.dto.GenerateThroughImageTextDTO;
|
||||
import com.ai.da.model.dto.ImageToSketchDTO;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.service.GenerateService;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -86,17 +87,15 @@ public class GenerateController {
|
||||
|
||||
@ApiOperation(value = "imageToSketch")
|
||||
@PostMapping("/imageToSketch")
|
||||
public Response<String> imageToSketch(@Valid @RequestBody GenerateThroughImageTextDTO generateThroughImageTextDTO) {
|
||||
String generateResult = generateService.imageToSketch(generateThroughImageTextDTO);
|
||||
return Response.success(generateResult);
|
||||
public Response<GenerateResultVO> imageToSketch(@Valid @RequestBody ImageToSketchDTO imageToSketchDTO) {
|
||||
return Response.success(generateService.imageToSketch(imageToSketchDTO));
|
||||
}
|
||||
|
||||
// modifySketch
|
||||
@ApiOperation(value = "modifySketch")
|
||||
@PostMapping("/modifySketch")
|
||||
public Response<String> modifySketch(@Valid @RequestBody GenerateModifyDTO generateModifyDTO) {
|
||||
generateService.modifySketch(generateModifyDTO);
|
||||
return Response.success("success");
|
||||
public Response<CollectionElementVO> modifySketch(@Valid @RequestBody GenerateModifyDTO generateModifyDTO) {
|
||||
return Response.success(generateService.modifySketch(generateModifyDTO));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,6 +72,19 @@ public class Generate {
|
||||
*/
|
||||
private String seed;
|
||||
|
||||
/**
|
||||
* 1 -> 粗
|
||||
* 2 -> 中
|
||||
* 3 -> 细
|
||||
* custom -> 自定义
|
||||
*/
|
||||
private String sketchStyle;
|
||||
|
||||
/**
|
||||
* sketch 风格参考图的collection_element_id
|
||||
*/
|
||||
private Long styleImageElementId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
22
src/main/java/com/ai/da/model/dto/ImageToSketchDTO.java
Normal file
22
src/main/java/com/ai/da/model/dto/ImageToSketchDTO.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.ai.da.model.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@ApiModel("image to sketch")
|
||||
@Data
|
||||
public class ImageToSketchDTO {
|
||||
|
||||
@ApiModelProperty("上传图片的collection_element_id")
|
||||
private Long elementId;
|
||||
|
||||
@ApiModelProperty("sketch线条风格 1->粗, 2->中, 3->细,传数字,自定义风格时,传空 ")
|
||||
private String style;
|
||||
|
||||
@ApiModelProperty("自定义线条风格,上传图片的collection_element_id")
|
||||
private Long styleImageId;
|
||||
|
||||
@ApiModelProperty("性别")
|
||||
private String gender;
|
||||
}
|
||||
20
src/main/java/com/ai/da/model/enums/SketchStyle.java
Normal file
20
src/main/java/com/ai/da/model/enums/SketchStyle.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.ai.da.model.enums;
|
||||
|
||||
public enum SketchStyle implements IEnumDisplay{
|
||||
|
||||
THICK("Thick"),
|
||||
|
||||
MEDIUM("Medium"),
|
||||
|
||||
THIN("Thin");
|
||||
|
||||
private String value;
|
||||
|
||||
SketchStyle(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -28,9 +28,10 @@ public class GenerateResultVO {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public GenerateResultVO(Long id, String url, String status) {
|
||||
public GenerateResultVO(Long id, String url, String status, String category) {
|
||||
this.id = id;
|
||||
this.url = url;
|
||||
this.status = status;
|
||||
this.category = category;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +63,6 @@ public class PythonService {
|
||||
private String accessPythonIp;
|
||||
@Value("${access.python.port:''}")
|
||||
private String accessPythonPort;
|
||||
@Value("${access.python.address}")
|
||||
private String fastApiPythonAddress;
|
||||
@Value("${minio.bucketName.gradient}")
|
||||
private String gradientBucketName;
|
||||
@Value("${access.python.generate_sr_port}")
|
||||
@@ -3449,7 +3447,7 @@ public class PythonService {
|
||||
throw new BusinessException("relightImage.interface.exception");
|
||||
}
|
||||
|
||||
public String imageToSketch(String imagePath, String bucket, String objectName){
|
||||
public String imageToSketch(String imagePath, String bucket, String objectName, String styleCode, String styleImageUrl){
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||
@@ -3460,6 +3458,8 @@ public class PythonService {
|
||||
//关闭FastJson的引用检测 防止出现$ref 现象
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("image_url", imagePath);
|
||||
map.put("style_image_url", styleImageUrl);
|
||||
map.put("default_style", styleCode);
|
||||
map.put("sketch_bucket", bucket);
|
||||
map.put("sketch_name", objectName);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.ai.da.mapper.primary.entity.GenerateDetail;
|
||||
import com.ai.da.model.dto.GenerateLikeDTO;
|
||||
import com.ai.da.model.dto.GenerateModifyDTO;
|
||||
import com.ai.da.model.dto.GenerateThroughImageTextDTO;
|
||||
import com.ai.da.model.dto.ImageToSketchDTO;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
@@ -43,7 +44,7 @@ public interface GenerateService extends IService<Generate> {
|
||||
|
||||
List<Map<String, Object>> getCountByUserAndTime(String startTime, String endTime, List<Long> accountIdList);
|
||||
|
||||
String imageToSketch(GenerateThroughImageTextDTO generateThroughImageTextDTO);
|
||||
GenerateResultVO imageToSketch(ImageToSketchDTO imageToSketchDTO);
|
||||
|
||||
void modifySketch(GenerateModifyDTO generateModifyDTO);
|
||||
CollectionElementVO modifySketch(GenerateModifyDTO generateModifyDTO);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,4 @@ public interface UserLikeService extends IService<UserLike> {
|
||||
void updateDate(Long designItemId,String timeZone);
|
||||
|
||||
List<UserLike> getUserLikeList(Long id);
|
||||
|
||||
List<Map<String, Long>> getHistoryLikeWithGradient();
|
||||
}
|
||||
|
||||
@@ -7,10 +7,8 @@ import com.ai.da.common.enums.*;
|
||||
import com.ai.da.common.utils.*;
|
||||
import com.ai.da.mapper.primary.*;
|
||||
import com.ai.da.mapper.primary.entity.*;
|
||||
import com.ai.da.model.dto.GenerateLikeDTO;
|
||||
import com.ai.da.model.dto.GenerateModifyDTO;
|
||||
import com.ai.da.model.dto.GenerateThroughImageTextDTO;
|
||||
import com.ai.da.model.dto.GenerateToPythonDTO;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.enums.SketchStyle;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.python.PythonService;
|
||||
import com.ai.da.service.*;
|
||||
@@ -773,25 +771,28 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String imageToSketch(GenerateThroughImageTextDTO generateThroughImageTextDTO) {
|
||||
public GenerateResultVO imageToSketch(ImageToSketchDTO imageToSketchDTO) {
|
||||
String bucket = userBucket;
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
|
||||
String imagePath;
|
||||
if (generateThroughImageTextDTO.getDesignType().equals("collection")) {
|
||||
CollectionElement collectionElement = collectionElementService.getById(generateThroughImageTextDTO.getCollectionElementId());
|
||||
imagePath = collectionElement.getUrl();
|
||||
} else if (generateThroughImageTextDTO.getDesignType().equals("productImage")) {
|
||||
ToProductImageResult productImage = toProductImageResultMapper.selectById(generateThroughImageTextDTO.getCollectionElementId());
|
||||
imagePath = productImage.getUrl();
|
||||
} else {
|
||||
log.error("unknown designType");
|
||||
throw new BusinessException("unknown designType");
|
||||
}
|
||||
CollectionElement collectionElement = collectionElementService.getById(imageToSketchDTO.getElementId());
|
||||
String imagePath = collectionElement.getUrl();
|
||||
|
||||
log.info(minioUtil.getPreSignedUrl(imagePath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
String imageName = imagePath.substring(imagePath.lastIndexOf("/") + 1);
|
||||
String objectName = accountId + "/imageToSketch/" + imageName;
|
||||
String sketchPath = pythonService.imageToSketch(imagePath, bucket, objectName);
|
||||
String style = imageToSketchDTO.getStyle();
|
||||
String styleCode = style.equals(SketchStyle.THICK.getValue()) ? "1" :
|
||||
style.equals(SketchStyle.MEDIUM.getValue()) ? "2" :
|
||||
style.equals(SketchStyle.THIN.getValue()) ? "3" : "Custom";
|
||||
String styleImage;
|
||||
if (!Objects.isNull(imageToSketchDTO.getStyleImageId())){
|
||||
CollectionElement styleElement = collectionElementService.getById(imageToSketchDTO.getElementId());
|
||||
styleImage = styleElement.getUrl();
|
||||
} else {
|
||||
styleImage = null;
|
||||
}
|
||||
String sketchPath = pythonService.imageToSketch(imagePath, bucket, objectName, styleCode, styleImage);
|
||||
|
||||
// 存DB
|
||||
Generate generate = new Generate();
|
||||
@@ -799,21 +800,33 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
generate.setUniqueId(String.valueOf(0));
|
||||
generate.setLevel1Type(SKETCH_BOARD.getRealName());
|
||||
generate.setLevel2Type("ImageToSketch");
|
||||
generate.setElementSource(generateThroughImageTextDTO.getDesignType());
|
||||
generate.setElementId(generateThroughImageTextDTO.getCollectionElementId());
|
||||
generate.setElementSource("collection");
|
||||
generate.setElementId(imageToSketchDTO.getElementId());
|
||||
generate.setGenerateType("image");
|
||||
generate.setSketchStyle(styleCode);
|
||||
generate.setStyleImageElementId(imageToSketchDTO.getElementId());
|
||||
generate.setCreateDate(new Date());
|
||||
baseMapper.insert(generate);
|
||||
|
||||
// 返回
|
||||
return minioUtil.getPreSignedUrl(sketchPath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME);
|
||||
// 将生成结果存入DB
|
||||
GenerateDetail generateDetail = new GenerateDetail();
|
||||
generateDetail.setGenerateId(generate.getId());
|
||||
generateDetail.setUrl(sketchPath);
|
||||
generateDetail.setIsLike((byte)0);
|
||||
generateDetail.setMd5(MD5Utils.encryptFile(minioUtil.getPreSignedUrl(sketchPath, 24 * 60), Boolean.FALSE));
|
||||
generateDetail.setCreateDate(LocalDateTime.now());
|
||||
generateDetailMapper.insert(generateDetail);
|
||||
|
||||
String clothCategory = pythonService.getClothCategory(sketchPath, imageToSketchDTO.getGender());
|
||||
|
||||
return new GenerateResultVO(generateDetail.getId(), minioUtil.getPreSignedUrl(sketchPath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME), "Success", clothCategory);
|
||||
}
|
||||
|
||||
// 对提取出来的sketch做调整
|
||||
// 输入 base64,以及 性别 分类,将图片添加到library
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modifySketch(GenerateModifyDTO generateModifyDTO) {
|
||||
public CollectionElementVO modifySketch(GenerateModifyDTO generateModifyDTO) {
|
||||
log.info("修改提取出的sketch,并加入到library");
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
String base64 = generateModifyDTO.getBase64();
|
||||
@@ -826,17 +839,23 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
|
||||
log.info("修改后的图片 : {}", minioPath);
|
||||
|
||||
// 存入db
|
||||
Library library = new Library();
|
||||
library.setAccountId(accountId);
|
||||
library.setLevel1Type(SKETCH_BOARD.getRealName());
|
||||
library.setLevel2Type(category);
|
||||
library.setLevel3Type(gender);
|
||||
library.setName(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")));
|
||||
library.setUrl(minioPath);
|
||||
library.setMd5(MD5Utils.encryptFile(minioUtil.getPreSignedUrl(minioPath, 24 * 60), Boolean.FALSE));
|
||||
library.setCreateDate(new Date());
|
||||
// 存入db 保存到t_collection_element
|
||||
CollectionElement collectionElement = new CollectionElement();
|
||||
collectionElement.setAccountId(accountId);
|
||||
collectionElement.setCollectionId(0L);
|
||||
collectionElement.setLevel1Type(SKETCH_BOARD.getRealName());
|
||||
collectionElement.setLevel2Type(generateModifyDTO.getCategory());
|
||||
collectionElement.setName(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")));
|
||||
collectionElement.setUrl(minioPath);
|
||||
collectionElement.setHasPin((byte)0);
|
||||
collectionElement.setMd5(MD5Utils.encryptFile(minioUtil.getPreSignedUrl(minioPath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME), Boolean.FALSE));
|
||||
collectionElement.setCreateDate(new Date());
|
||||
collectionElementService.save(collectionElement);
|
||||
|
||||
libraryService.save(library);
|
||||
CollectionElementVO collectionElementVO = CopyUtil.copyObject(collectionElement, CollectionElementVO.class);
|
||||
collectionElementVO.setMinIOPath(collectionElementVO.getUrl());
|
||||
collectionElementVO.setUrl(minioUtil.getPreSignedUrl(collectionElementVO.getUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
collectionElementVO.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||
return collectionElementVO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,21 +94,4 @@ public class UserLikeServiceImpl extends ServiceImpl<UserLikeMapper, UserLike> i
|
||||
return userLikeMapper.selectList(qw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Long>> getHistoryLikeWithGradient(){
|
||||
List<Map<String, Long>> historyLikeWithGradient = baseMapper.getHistoryLikeWithGradient();
|
||||
return historyLikeWithGradient.stream()
|
||||
.map(map -> {
|
||||
Map<String, Long> newMap = new HashMap<>();
|
||||
if (map.containsKey("design_item_id")) {
|
||||
newMap.put("designItemId", map.get("design_item_id"));
|
||||
}
|
||||
if (map.containsKey("design_outfit_id")) {
|
||||
newMap.put("designPythonOutfitId", map.get("design_outfit_id"));
|
||||
}
|
||||
return newMap;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -208,4 +208,8 @@ BUTTON=Button
|
||||
BELT=Belt
|
||||
CORSAGE=Corsage
|
||||
ZIPPER=Zipper
|
||||
POCKET=Pocket
|
||||
POCKET=Pocket
|
||||
|
||||
THICK=Thick Lines
|
||||
MEDIUM=Medium Lines
|
||||
THIN=Thin lines
|
||||
@@ -201,4 +201,8 @@ BUTTON=纽扣
|
||||
BELT=腰带
|
||||
CORSAGE=胸花
|
||||
ZIPPER=拉链
|
||||
POCKET=口袋
|
||||
POCKET=口袋
|
||||
|
||||
THICK=粗线条
|
||||
MEDIUM=中线条
|
||||
THIN=细线条
|
||||
Reference in New Issue
Block a user