|
@@ -1,5 +1,6 @@
|
|
|
package com.fdkankan.scene.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.img.ImgUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.lang.UUID;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
@@ -26,7 +27,9 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import sun.rmi.runtime.Log;
|
|
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
import java.io.File;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
@@ -68,12 +71,28 @@ public class SceneServiceImpl implements ISceneService {
|
|
|
File tempFile = File.createTempFile(java.util.UUID.randomUUID().toString(), extName);
|
|
|
file.transferTo(tempFile);
|
|
|
|
|
|
+ //校验像素
|
|
|
+ BufferedImage bufferedImage = ImgUtil.read(tempFile.getPath());
|
|
|
+ Float scale = 1F;
|
|
|
+ Float widthScale = 1F;
|
|
|
+ Float heightScale = 1F;
|
|
|
+ int width = bufferedImage.getWidth();
|
|
|
+ int height = bufferedImage.getHeight();
|
|
|
+ if(width > 2000){
|
|
|
+ widthScale = new BigDecimal(2000).divide(new BigDecimal(width)).setScale(5, BigDecimal.ROUND_DOWN).floatValue();
|
|
|
+ }
|
|
|
+ if(height > 2000){
|
|
|
+ heightScale = new BigDecimal(2000).divide(new BigDecimal(width)).setScale(5, BigDecimal.ROUND_DOWN).floatValue();
|
|
|
+ }
|
|
|
+ scale = widthScale > heightScale ? heightScale : widthScale;
|
|
|
+ ImgUtil.scale(new File(tempFile.getPath()), new File(tempFile.getPath()), scale);
|
|
|
+
|
|
|
String orgImgOssPath = "body_segment/original/" + tempFile.getName();
|
|
|
ossBodySegmentUtil.uploadOss(tempFile.getPath(), orgImgOssPath);
|
|
|
// fYunFileService.uploadFile(bodySegmentBucket, tempFile.getPath(), orgImgOssPath);
|
|
|
|
|
|
BodySegmentStatusBean bodySegmentStatusBean = BodySegmentStatusBean.builder().uuid(uuid).status(CommonOperStatus.WAITING.code()).build();
|
|
|
- redisUtil.hset(RedisKey.SCENE_BODY_SEGMENT, uuid, JSON.toJSONString(bodySegmentStatusBean));
|
|
|
+ redisUtil.set(String.format(RedisKey.SCENE_BODY_SEGMENT, uuid), JSON.toJSONString(bodySegmentStatusBean), RedisKey.CAMERA_EXPIRE_7_TIME);
|
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put("uuid", uuid);
|
|
@@ -107,11 +126,10 @@ public class SceneServiceImpl implements ISceneService {
|
|
|
fYunFileService.uploadFile(imgPath, targetOssImgPath);
|
|
|
bodySegmentStatusBean.setStatus(CommonOperStatus.SUCCESS.code());
|
|
|
bodySegmentStatusBean.setImageUrl(fYunFileConfig.getHost() + targetOssImgPath);
|
|
|
- redisUtil.hset(RedisKey.SCENE_BODY_SEGMENT, uuid, JSON.toJSONString(bodySegmentStatusBean));
|
|
|
+ redisUtil.set(String.format(RedisKey.SCENE_BODY_SEGMENT, uuid), JSON.toJSONString(bodySegmentStatusBean), RedisKey.CAMERA_EXPIRE_7_TIME);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("提取人体分割图片失败,imgUrl: "+imgUrl, e);
|
|
|
bodySegmentStatusBean.setStatus(CommonOperStatus.FAILD.code());
|
|
|
- redisUtil.hset(RedisKey.SCENE_BODY_SEGMENT, uuid, JSON.toJSONString(bodySegmentStatusBean));
|
|
|
+ redisUtil.set(String.format(RedisKey.SCENE_BODY_SEGMENT, uuid), JSON.toJSONString(bodySegmentStatusBean), RedisKey.CAMERA_EXPIRE_7_TIME);
|
|
|
}finally {
|
|
|
try {
|
|
|
//免费版qps不能大于2,故休眠一秒
|