提交修改
This commit is contained in:
parent
09baceebc4
commit
7cda632f36
@ -0,0 +1,86 @@
|
||||
package com.heyu.api.controller.imagerecog;
|
||||
|
||||
|
||||
import com.aliyun.imagerecog20190930.models.ClassifyingRubbishResponse;
|
||||
import com.aliyun.imagerecog20190930.models.ClassifyingRubbishResponseBody;
|
||||
import com.heyu.api.alibaba.handle.imagerecog.AClassifyingRubbishHandle;
|
||||
import com.heyu.api.alibaba.request.imagerecog.AClassifyingRubbishRequest;
|
||||
import com.heyu.api.controller.BaseController;
|
||||
import com.heyu.api.data.annotation.CacheResult;
|
||||
import com.heyu.api.data.annotation.NotIntercept;
|
||||
import com.heyu.api.data.utils.ApiR;
|
||||
import com.heyu.api.data.utils.R;
|
||||
import com.heyu.api.request.imagerecog.ClassifyingRubbishReq;
|
||||
import com.heyu.api.resp.imagerecog.ClassifyingRubbishElements;
|
||||
import com.heyu.api.resp.imagerecog.ClassifyingRubbishResp;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/***
|
||||
*
|
||||
* https://next.api.aliyun.com/api/imagerecog/2019-09-30/ClassifyingRubbish?tab=DOC&lang=JAVA&RegionId=cn-shanghai
|
||||
*
|
||||
* ClassifyingRubbish
|
||||
*
|
||||
* 垃圾分类识别ClassifyingRubbish的语法及示例
|
||||
*
|
||||
* 常见垃圾输出列举值
|
||||
* 湿垃圾: 八宝粥,冰激凌,冰糖葫芦,饼干,菠萝,菠萝蜜,菜根菜叶,残渣剩饭,
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/pubbish")
|
||||
@NotIntercept
|
||||
public class ClassifyingRubbishController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private AClassifyingRubbishHandle classifyingRubbishHandle;
|
||||
|
||||
|
||||
@RequestMapping("/classifying")
|
||||
@CacheResult
|
||||
public R classifying(ClassifyingRubbishReq req) {
|
||||
ClassifyingRubbishResp resp = new ClassifyingRubbishResp();
|
||||
AClassifyingRubbishRequest request = new AClassifyingRubbishRequest();
|
||||
request.setImageBase64(req.getImageBase64());
|
||||
request.setImageUrl(req.getImageUrl());
|
||||
|
||||
ApiR<ClassifyingRubbishResponse> aR = classifyingRubbishHandle.handle(request);
|
||||
if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
|
||||
ClassifyingRubbishResponseBody.ClassifyingRubbishResponseBodyData responseBodyData = aR.getData().getBody().getData();
|
||||
resp.setSensitive(responseBodyData.getSensitive());
|
||||
List<ClassifyingRubbishElements> elements = new ArrayList<>();
|
||||
|
||||
if (CollectionUtils.isNotEmpty(responseBodyData.getElements())) {
|
||||
for (ClassifyingRubbishResponseBody.ClassifyingRubbishResponseBodyDataElements element : responseBodyData.getElements()) {
|
||||
|
||||
ClassifyingRubbishElements classifyingRubbishElements = new ClassifyingRubbishElements();
|
||||
classifyingRubbishElements.setRubbishScore(element.getRubbishScore());
|
||||
classifyingRubbishElements.setRubbish(element.getRubbish());
|
||||
classifyingRubbishElements.setCategory(element.getCategory());
|
||||
classifyingRubbishElements.setCategoryScore(element.getCategoryScore());
|
||||
|
||||
elements.add(classifyingRubbishElements);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
resp.setElements(elements);
|
||||
|
||||
return R.ok().setData(resp);
|
||||
}
|
||||
|
||||
|
||||
return R.error(aR.getErrorMsg());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.heyu.api.request.imagerecog;
|
||||
|
||||
|
||||
import com.heyu.api.request.CommonReq;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ClassifyingRubbishReq extends CommonReq {
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package com.heyu.api.resp.imagerecog;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ClassifyingRubbishElements implements Serializable {
|
||||
/**
|
||||
* 垃圾类别。包括可回收垃圾、干垃圾、湿垃圾、有害垃圾。
|
||||
*
|
||||
* 示例值:
|
||||
* 可回收垃圾
|
||||
*/
|
||||
public String category;
|
||||
|
||||
/***
|
||||
* 识别出的垃圾类别的置信度。
|
||||
*
|
||||
* 示例值:
|
||||
* 0.9406
|
||||
*
|
||||
*/
|
||||
public Float categoryScore;
|
||||
|
||||
/**
|
||||
* 具体的物品名称。
|
||||
*
|
||||
* 示例值:
|
||||
* 纸板箱
|
||||
*/
|
||||
public String rubbish;
|
||||
|
||||
/***
|
||||
* 物品名称的置信度。
|
||||
*
|
||||
* 示例值:
|
||||
* 0.9406
|
||||
*/
|
||||
public Float rubbishScore;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.heyu.api.resp.imagerecog;
|
||||
|
||||
import com.heyu.api.data.dto.BaseResp;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ClassifyingRubbishResp extends BaseResp {
|
||||
|
||||
/***
|
||||
* 图片中是否存在敏感信息。
|
||||
*
|
||||
* true:存在敏感信息,不会返回具体垃圾分类信息。
|
||||
*
|
||||
* false:不存在敏感信息。
|
||||
*
|
||||
* 示例值:
|
||||
* false
|
||||
*/
|
||||
public Boolean sensitive;
|
||||
|
||||
/***
|
||||
* 输出垃圾识别结果。
|
||||
*/
|
||||
public List<ClassifyingRubbishElements> elements;
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user