TASK:自动识别上传服装的类别
This commit is contained in:
@@ -37,6 +37,7 @@ import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -1965,23 +1966,6 @@ public class PythonService {
|
||||
return new DesignPythonItemPrint(new ArrayList<>(), false);
|
||||
}
|
||||
DesignPythonItemPrint print = CopyUtil.copyObject(printObject, DesignPythonItemPrint.class);
|
||||
// if(StringUtils.isEmpty(printObject.getPath())){
|
||||
// print.setPrint_path_list(new ArrayList<>());
|
||||
// }else {
|
||||
// print.setPrint_path_list(Collections.singletonList(printObject.getPath()));
|
||||
// }
|
||||
// if (StringUtils.isEmpty(clothesPath)
|
||||
// || "none".equals(clothesPath)
|
||||
// || CollectionUtils.isEmpty(printObject.getPrints())) {
|
||||
// return print;
|
||||
// }
|
||||
//图片宽 高
|
||||
// FileVO fileVO = FileUtil.getFileSize(FileUtil.getOriginFile(clothesPath));
|
||||
/* List<List<Float>> locations = printObject.getLocation();
|
||||
locations.forEach(location -> {
|
||||
location.set(0, location.get(0) * fileVO.getWidth());
|
||||
location.set(1, location.get(1) * fileVO.getHigh());
|
||||
});*/
|
||||
|
||||
List<List<Double>> location = new ArrayList<>(printObject.getPrints().size());
|
||||
List<Double> scale = new ArrayList<>(printObject.getPrints().size());
|
||||
@@ -2270,6 +2254,9 @@ public class PythonService {
|
||||
if (Objects.isNull(response) || Objects.isNull(response.body())) {
|
||||
log.error("PythonService##generateSketchOrPrint异常###{}", "response or body is empty!");
|
||||
throw new BusinessException("generate.interface.error");
|
||||
} else if (response.code() != HttpURLConnection.HTTP_OK){
|
||||
log.error("PythonService##generateSketchOrPrint异常###{}", "Response error!Response code ## " + response.code() + " ##");
|
||||
throw new BusinessException("generate.interface.error");
|
||||
} else {
|
||||
try {
|
||||
bodyString = response.body().string();
|
||||
@@ -2328,7 +2315,7 @@ public class PythonService {
|
||||
return imageUrlList;
|
||||
}
|
||||
|
||||
public String composeLayers(List<OutfitDetailPythonItem> layersDetail) throws IOException {
|
||||
public String composeLayers(List<OutfitDetailPythonItem> layersDetail) {
|
||||
HashMap<String, List<OutfitDetailPythonItem>> layers = new HashMap<>();
|
||||
HashMap<String, HashMap<String, List<OutfitDetailPythonItem>>> content = new HashMap<>();
|
||||
layers.put("layers", layersDetail);
|
||||
@@ -2343,9 +2330,16 @@ public class PythonService {
|
||||
// 生成失败
|
||||
if (Objects.isNull(response) || Objects.isNull(response.body())) {
|
||||
log.error("PythonService##composeLayers异常###{}", "response or body is empty!");
|
||||
throw new BusinessException("generate exception!");
|
||||
throw new BusinessException("compose-layer.interface.exception");
|
||||
}else if (response.code() != HttpURLConnection.HTTP_OK){
|
||||
log.error("PythonService##composeLayers异常###{}", "Response error!Response code ## " + response.code() + " ##");
|
||||
throw new BusinessException("compose-layer.interface.exception");
|
||||
} else {
|
||||
bodyString = response.body().string();
|
||||
try {
|
||||
bodyString = response.body().string();
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException("compose-layer.interface.exception");
|
||||
}
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(bodyString);
|
||||
Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful");
|
||||
@@ -2354,11 +2348,50 @@ public class PythonService {
|
||||
}
|
||||
log.info("composeLayers 失败###{}", jsonObject);
|
||||
//生成失败
|
||||
throw new BusinessException("composeLayers Exception!");
|
||||
throw new BusinessException("compose-layer.interface.exception");
|
||||
}
|
||||
|
||||
private String getCompositeImage(JSONObject jsonObject) {
|
||||
JSONObject item0 = jsonObject.getJSONObject("0");
|
||||
return item0.getString("synthesis_url");
|
||||
}
|
||||
|
||||
public String getClothCategory(String path,String gender){
|
||||
HashMap<String, String> content = new HashMap<>();
|
||||
content.put("sketch_img_url",path);
|
||||
content.put("colony",gender);
|
||||
List<HashMap<String, String>> contents = Collections.singletonList(content);
|
||||
String jsonString = JSON.toJSONString(contents, SerializerFeature.WriteNullStringAsEmpty);
|
||||
|
||||
// todo 添加限流
|
||||
Response response = this.sendPostToModel(jsonString, "9992/api/category_recognition", "getClothCategory");
|
||||
// todo 结束限流
|
||||
|
||||
String bodyString;
|
||||
// 生成失败
|
||||
if (Objects.isNull(response) || Objects.isNull(response.body())) {
|
||||
log.error("PythonService##GetClothCategory###{}", "response or body is empty!");
|
||||
throw new BusinessException("cloth-classification.interface.exception");
|
||||
} else if (response.code() != HttpURLConnection.HTTP_OK){
|
||||
log.error("PythonService##GetClothCategory###{}", "Response error!Response code ## " + response.code() + " ##");
|
||||
throw new BusinessException("cloth-classification.interface.exception");
|
||||
} else {
|
||||
try {
|
||||
bodyString = response.body().string();
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException("cloth-classification.interface.exception");
|
||||
}
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(bodyString);
|
||||
Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful");
|
||||
if (result && jsonObject.get("msg").equals("OK!")) {
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
JSONArray list = JSONArray.parseArray(data.get("list").toString());
|
||||
JSONObject map = (JSONObject) list.get(0);
|
||||
return map.get("category").toString();
|
||||
}
|
||||
log.info("getClothCategory 失败###{}", jsonObject);
|
||||
//生成失败
|
||||
throw new BusinessException("cloth-classification.interface.exception");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user