1、新增 imageToSketch
2、删除无用代码
This commit is contained in:
@@ -2643,8 +2643,6 @@ public class PythonService {
|
||||
minioPath = minioUtil.base64UploadToPath(colorImg, gradientBucketName, null);
|
||||
designSingleItem.getGradient().setColorImg(null);
|
||||
gradientString = JSONObject.toJSONString(designSingleItem.getGradient());
|
||||
|
||||
// todo 当渐变色不为空时,是否需要将颜色置为 0 0 0
|
||||
}
|
||||
|
||||
PrintToPython printToPython = resolveDesignSinglePrint(designSingleItem.getPrintObject().getPrints());
|
||||
@@ -3450,4 +3448,62 @@ public class PythonService {
|
||||
//生成失败
|
||||
throw new BusinessException("relightImage.interface.exception");
|
||||
}
|
||||
|
||||
public String imageToSketch(String imagePath, String bucket, String objectName){
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
|
||||
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
|
||||
.build();
|
||||
MediaType paramMap = MediaType.parse("application/json");
|
||||
//关闭FastJson的引用检测 防止出现$ref 现象
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("image_url", imagePath);
|
||||
map.put("sketch_bucket", bucket);
|
||||
map.put("sketch_name", objectName);
|
||||
|
||||
log.info("ImageToSketch请求python 参数:####{}", map);
|
||||
String param = JSON.toJSONString(map, SerializerFeature.WriteNullStringAsEmpty);
|
||||
RequestBody body = RequestBody.create(paramMap, param);
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/image2sketch")
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Response response;
|
||||
|
||||
try {
|
||||
response = client.newCall(request).execute();
|
||||
} catch (IOException ioException) {
|
||||
log.error("PythonService##ImageToSketch异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
throw new BusinessException("generate.interface.error");
|
||||
}
|
||||
int responseCode = response.code();
|
||||
String bodyString;
|
||||
try {
|
||||
bodyString = response.body().string();
|
||||
if (responseCode != HttpURLConnection.HTTP_OK) {
|
||||
// 基本不会有除200以外的code
|
||||
log.info("ImageToSketch 失败。 Response code {}", responseCode);
|
||||
throw new BusinessException("ImageToSketch 失败。 Response code " + responseCode);
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(bodyString);
|
||||
if (response.isSuccessful() && jsonObject.get("msg").equals("OK!")) {
|
||||
String sketchResult = jsonObject.get("data").toString();
|
||||
log.info("ImageToSketch 结果 : {}", sketchResult);
|
||||
return sketchResult;
|
||||
}else {
|
||||
log.info("ImageToSketch 失败。 Response code {}", responseCode);
|
||||
throw new BusinessException("ImageToSketch 失败。 Response code " + responseCode);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("ImageToSketch 失败; error message => {}", e.getMessage());
|
||||
response.close();
|
||||
throw new BusinessException("generate.interface.error");
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user