提交修改
This commit is contained in:
parent
5103de1e3f
commit
619aca0b0e
@ -0,0 +1,55 @@
|
||||
package com.heyu.api.controller.imagerecog;
|
||||
|
||||
|
||||
import com.aliyun.imagerecog20190930.models.TaggingAdImageResponse;
|
||||
import com.aliyun.imagerecog20190930.models.TaggingAdImageResponseBody;
|
||||
import com.heyu.api.alibaba.handle.imagerecog.ATaggingAdImageHandle;
|
||||
import com.heyu.api.alibaba.request.imagerecog.ATaggingAdImageRequest;
|
||||
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.TaggingAdImageReq;
|
||||
import com.heyu.api.resp.imagerecog.TaggingAdImageResp;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/***
|
||||
* https://next.api.aliyun.com/api/imagerecog/2019-09-30/TaggingAdImage?tab=DOC&lang=JAVA&RegionId=cn-shanghai
|
||||
* 广告素材分析 TaggingAdImage
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/image")
|
||||
@NotIntercept
|
||||
public class TaggingAdImageController extends BaseController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ATaggingAdImageHandle ataggingAdImageHandle;
|
||||
|
||||
|
||||
@RequestMapping("/taggingAd")
|
||||
@CacheResult
|
||||
public R recognize(TaggingAdImageReq req) {
|
||||
TaggingAdImageResp resp = new TaggingAdImageResp();
|
||||
ATaggingAdImageRequest request = new ATaggingAdImageRequest();
|
||||
request.setImageBase64(req.getImageBase64());
|
||||
request.setImageUrl(req.getImageUrl());
|
||||
|
||||
ApiR<TaggingAdImageResponse> aR = ataggingAdImageHandle.handle(request);
|
||||
if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
|
||||
TaggingAdImageResponseBody.TaggingAdImageResponseBodyData responseBodyData = aR.getData().getBody().getData();
|
||||
resp.setTagMap(responseBodyData.getTagInfo());
|
||||
return R.ok().setData(resp);
|
||||
|
||||
}
|
||||
return R.error(aR.getErrorMsg());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
package com.heyu.api.controller.imagerecog;
|
||||
|
||||
|
||||
import com.aliyun.imagerecog20190930.models.TaggingImageResponse;
|
||||
import com.aliyun.imagerecog20190930.models.TaggingImageResponseBody;
|
||||
import com.heyu.api.alibaba.handle.imagerecog.ATaggingImageHandle;
|
||||
import com.heyu.api.alibaba.request.imagerecog.ATaggingImageRequest;
|
||||
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.TaggingImageReq;
|
||||
import com.heyu.api.resp.imagerecog.TaggingImageResp;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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/TaggingImage?tab=DOC&lang=JAVA&RegionId=cn-shanghai
|
||||
*
|
||||
*通用图像打标 Tagging|mage
|
||||
*
|
||||
*
|
||||
* 功能描述
|
||||
* 通用图像打标能力用于识别图像中的主体内容并打上类型标签,支持数千个内容标签,覆盖常见物体品类。
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/image/color")
|
||||
@NotIntercept
|
||||
public class TaggingImageController extends BaseController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ATaggingImageHandle aTaggingImageHandle;
|
||||
|
||||
|
||||
@RequestMapping("/recognize")
|
||||
@CacheResult
|
||||
public R recognize(TaggingImageReq req) {
|
||||
List<TaggingImageResp> respList = new ArrayList<>();
|
||||
|
||||
ATaggingImageRequest ataggingImageRequest = new ATaggingImageRequest();
|
||||
ataggingImageRequest.setImageBase64(req.getImageBase64());
|
||||
ataggingImageRequest.setImageUrl(req.getImageUrl());
|
||||
|
||||
ApiR<TaggingImageResponse> aR = aTaggingImageHandle.handle(ataggingImageRequest);
|
||||
if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
|
||||
TaggingImageResponseBody.TaggingImageResponseBodyData responseBodyData = aR.getData().getBody().getData();
|
||||
for (TaggingImageResponseBody.TaggingImageResponseBodyDataTags tag : responseBodyData.getTags()) {
|
||||
|
||||
TaggingImageResp resp = new TaggingImageResp();
|
||||
resp.setConfidence(tag.getConfidence());
|
||||
resp.setValue(tag.getValue());
|
||||
respList.add(resp);
|
||||
|
||||
}
|
||||
return R.error().setData(respList);
|
||||
|
||||
}
|
||||
|
||||
return R.error(aR.getErrorMsg());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package com.heyu.api.request.imagerecog;
|
||||
|
||||
|
||||
import com.heyu.api.request.CommonReq;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TaggingAdImageReq extends CommonReq {
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package com.heyu.api.request.imagerecog;
|
||||
|
||||
import com.heyu.api.request.CommonReq;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TaggingImageReq extends CommonReq {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.heyu.api.resp.imagerecog;
|
||||
|
||||
|
||||
import com.heyu.api.data.dto.BaseResp;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class TaggingAdImageResp extends BaseResp {
|
||||
|
||||
|
||||
private Map tagMap;
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.heyu.api.resp.imagerecog;
|
||||
|
||||
|
||||
import com.heyu.api.data.dto.BaseResp;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TaggingImageResp extends BaseResp {
|
||||
|
||||
|
||||
/***
|
||||
* 标签名称对应的置信度,取值范围 0~100。
|
||||
*
|
||||
* 示例值:
|
||||
* 65
|
||||
*/
|
||||
public Float confidence;
|
||||
|
||||
|
||||
/***
|
||||
* 标签名称。具体取值请下载 Label 文件查看。
|
||||
*
|
||||
* 示例值:
|
||||
* 沙发
|
||||
*/
|
||||
public String value;
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user