提交修改
This commit is contained in:
parent
c04a19c021
commit
e80dfa4c24
@ -0,0 +1,59 @@
|
||||
package com.heyu.api.controller.imageseg;
|
||||
|
||||
|
||||
import com.aliyun.imageseg20191230.models.SegmentCommodityResponse;
|
||||
import com.aliyun.imageseg20191230.models.SegmentCommodityResponseBody;
|
||||
import com.heyu.api.alibaba.handle.imageseg.ASegmentCommodityHandle;
|
||||
import com.heyu.api.alibaba.request.imageseg.ASegmentCommodityRequest;
|
||||
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.resp.imageseg.SegmentCommodityResp;
|
||||
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/imageseg/2019-12-30/SegmentCommodity?RegionId=cn-shanghai
|
||||
*
|
||||
*
|
||||
* 商品分割
|
||||
*
|
||||
* SegmentCommodity
|
||||
*
|
||||
*功能描述
|
||||
* 商品分割能力用于识别输入图像中的商品轮廓,与背景进行分离,返回分割后的前景商品图(4 通道)。功能适用于实景图,不适用于卡通图片。商品分割主要针对拍到全貌的商品进行分割。 关于该接口功能的示例图如下:
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/goods")
|
||||
@NotIntercept
|
||||
public class SegmentCommodityController extends BaseController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ASegmentCommodityHandle segmentCommodityHandle;
|
||||
|
||||
@RequestMapping("/segment")
|
||||
@CacheResult
|
||||
public R segment(ASegmentCommodityRequest request) {
|
||||
|
||||
SegmentCommodityResp resp = new SegmentCommodityResp();
|
||||
ApiR<SegmentCommodityResponse> aR = segmentCommodityHandle.handle(request);
|
||||
if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
|
||||
SegmentCommodityResponseBody.SegmentCommodityResponseBodyData responseBodyData = aR.getData().getBody().getData();
|
||||
|
||||
resp.setImageURL(responseBodyData.getImageURL());
|
||||
return R.ok().setData(resp);
|
||||
|
||||
}
|
||||
|
||||
return R.error();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
package com.heyu.api.controller.imageseg;
|
||||
|
||||
|
||||
import com.aliyun.imageseg20191230.models.SegmentCommonImageResponse;
|
||||
import com.aliyun.imageseg20191230.models.SegmentCommonImageResponseBody;
|
||||
import com.heyu.api.alibaba.handle.imageseg.ASegmentCommonImageHandle;
|
||||
import com.heyu.api.alibaba.request.imageseg.ASegmentCommonImageRequest;
|
||||
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.resp.imageseg.SegmentCommonImageResp;
|
||||
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/imageseg/2019-12-30/SegmentCommonImage?tab=DOC&RegionId=cn-shanghai
|
||||
*
|
||||
*
|
||||
* 通用分割
|
||||
*
|
||||
* SegmentCommonImage
|
||||
*
|
||||
*
|
||||
* 功能描述
|
||||
* 通用分割能力可以识别输入图像中视觉中心的物体轮廓,将物体与背景进行分离,返回分割后的前景物体图(4 通道)。 关于该接口功能的示例图如下:
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/image/common")
|
||||
@NotIntercept
|
||||
public class SegmentCommonImageController extends BaseController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ASegmentCommonImageHandle segmentCommonImageHandle;
|
||||
|
||||
|
||||
@RequestMapping("/segment")
|
||||
@CacheResult
|
||||
public R segment(ASegmentCommonImageRequest request) {
|
||||
|
||||
SegmentCommonImageResp resp = new SegmentCommonImageResp();
|
||||
|
||||
ApiR<SegmentCommonImageResponse> aR = segmentCommonImageHandle.handle(request);
|
||||
if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
|
||||
SegmentCommonImageResponseBody.SegmentCommonImageResponseBodyData responseBodyData = aR.getData().getBody().getData();
|
||||
|
||||
resp.setImageURL(responseBodyData.getImageURL());
|
||||
return R.ok().setData(resp);
|
||||
|
||||
}
|
||||
|
||||
return R.error(aR.getErrorMsg());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,51 @@
|
||||
package com.heyu.api.controller.imageseg;
|
||||
|
||||
|
||||
import com.aliyun.imageseg20191230.models.SegmentFoodResponse;
|
||||
import com.aliyun.imageseg20191230.models.SegmentFoodResponseBody;
|
||||
import com.heyu.api.alibaba.handle.imageseg.ASegmentFoodHandle;
|
||||
import com.heyu.api.alibaba.request.imageseg.ASegmentFoodRequest;
|
||||
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.resp.imageseg.SegmentFoodResp;
|
||||
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/imageseg/2019-12-30/SegmentFood
|
||||
*
|
||||
* 食品分割
|
||||
*
|
||||
* SegmentFood
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/food")
|
||||
@NotIntercept
|
||||
public class SegmentFoodController extends BaseController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ASegmentFoodHandle segmentFoodHandle;
|
||||
|
||||
|
||||
@RequestMapping("/segment")
|
||||
@CacheResult
|
||||
public R segment(ASegmentFoodRequest request) {
|
||||
SegmentFoodResp resp = new SegmentFoodResp();
|
||||
|
||||
|
||||
ApiR<SegmentFoodResponse> aR = segmentFoodHandle.handle(request);
|
||||
if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
|
||||
SegmentFoodResponseBody.SegmentFoodResponseBodyData responseBodyData = aR.getData().getBody().getData();
|
||||
resp.setImageURL(responseBodyData.getImageURL());
|
||||
return R.ok().setData(resp);
|
||||
}
|
||||
return R.error();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
package com.heyu.api.controller.imageseg;
|
||||
|
||||
|
||||
import com.aliyun.imageseg20191230.models.SegmentHairResponse;
|
||||
import com.aliyun.imageseg20191230.models.SegmentHairResponseBody;
|
||||
import com.heyu.api.alibaba.handle.imageseg.ASegmentHairHandle;
|
||||
import com.heyu.api.alibaba.request.imageseg.ASegmentHairRequest;
|
||||
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.resp.imageseg.SegmentHairResp;
|
||||
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/imageseg/2019-12-30/SegmentHair?tab=DOC&lang=JAVA&RegionId=cn-shanghai¶ms={%22ImageURL%22:%22http%3A%2F%2Fworkbench-file-transfer.oss-cn-shanghai.aliyuncs.com%2Fuser-files%2F2893a748-900f-4310-9c8e-9d45b011c3ce-SegmentHair1.jpg%3FOSSAccessKeyId%3DLTAI5tRvL6vYdjKSfTFZ156m%26Expires%3D1742401044%26Signature%3DFXSfytFsiXJntSbyz95BuwnzPww%253D%26response-content-disposition%3Dattachment%22}
|
||||
*头发分割
|
||||
*
|
||||
* SegmentHair
|
||||
*
|
||||
*功能描述
|
||||
* 头发分割能力用于识别图像中的人物头像,然后对人物头像区域进行抠图解析,最后输出 PNG 格式的人物头发矩形透明图。
|
||||
*
|
||||
*
|
||||
* 应用场景
|
||||
* 假发网络试戴:通过头发分割,截取自拍照的头发后,换成假发图像,就可以直接看到假发试戴效果,省去了网购后佩戴不合适需要退换货的烦恼。
|
||||
* 理发店发型尝试:发型师指导客户通过平板电脑或手机拍摄的自己头像,换成各种发型,有更直观的感觉。客户可以选择最喜欢的发型,让发型师为自己打理
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/hair")
|
||||
@NotIntercept
|
||||
public class SegmentHairController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ASegmentHairHandle segmentHairHandle;
|
||||
|
||||
|
||||
@RequestMapping("/segment")
|
||||
@CacheResult
|
||||
public R changeSky(ASegmentHairRequest request) {
|
||||
|
||||
List<SegmentHairResp> respList = new ArrayList<>();
|
||||
|
||||
ApiR<SegmentHairResponse> aR = segmentHairHandle.handle(request);
|
||||
if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
|
||||
SegmentHairResponseBody.SegmentHairResponseBodyData responseBodyData = aR.getData().getBody().getData();
|
||||
|
||||
if (CollectionUtils.isNotEmpty(responseBodyData.getElements())) {
|
||||
for (SegmentHairResponseBody.SegmentHairResponseBodyDataElements element : responseBodyData.getElements()) {
|
||||
|
||||
SegmentHairResp resp = new SegmentHairResp();
|
||||
resp.setImageURL(element.getImageURL());
|
||||
resp.setY(element.getY());
|
||||
resp.setX(element.getX());
|
||||
resp.setHeight(element.getHeight());
|
||||
resp.setWidth(element.getWidth());
|
||||
respList.add(resp);
|
||||
}
|
||||
}
|
||||
|
||||
return R.ok().setData(respList);
|
||||
}
|
||||
|
||||
return R.error(aR.getErrorMsg());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package com.heyu.api.resp.imageseg;
|
||||
|
||||
import com.heyu.api.resp.CommonImageUrlResp;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SegmentCommodityResp extends CommonImageUrlResp {
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.heyu.api.resp.imageseg;
|
||||
|
||||
|
||||
import com.heyu.api.resp.CommonImageUrlResp;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SegmentCommonImageResp extends CommonImageUrlResp {
|
||||
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.heyu.api.resp.imageseg;
|
||||
|
||||
|
||||
import com.heyu.api.resp.CommonImageUrlResp;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SegmentFoodResp extends CommonImageUrlResp {
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package com.heyu.api.resp.imageseg;
|
||||
|
||||
import com.heyu.api.resp.CommonImageUrlResp;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SegmentHairResp extends CommonImageUrlResp {
|
||||
/***
|
||||
* 结果图的高度。
|
||||
*
|
||||
* 示例值:
|
||||
* 180
|
||||
*/
|
||||
|
||||
public Integer height;
|
||||
/***
|
||||
* 结果图的宽度。
|
||||
*
|
||||
* 示例值:
|
||||
* 113
|
||||
*/
|
||||
|
||||
public Integer width;
|
||||
|
||||
/***
|
||||
* 结果图左上角在原图中的 x 轴坐标。
|
||||
*
|
||||
* 示例值:
|
||||
* 446
|
||||
*/
|
||||
public Integer x;
|
||||
|
||||
/**
|
||||
* 结果图左上角在原图中的 y 轴坐标。
|
||||
*
|
||||
* 示例值:
|
||||
* 102
|
||||
*/
|
||||
public Integer y;
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user