天天看點

Day5筆記——風格遷移

輸入限制

圖檔格式:JPEG、JPG、BMP、PNG。

圖檔大小:大小不超過3MB。

圖檔分辨率:分辨率要求小于1200×1200像素。

圖像都必須是RGB 3通道。

URL位址中不能包含中文字元。

請求參數

Day5筆記——風格遷移
傳回資料
Day5筆記——風格遷移
錯誤碼
Day5筆記——風格遷移

示例

請求示例

&MajorUrl=http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/ExtendImageStyle/majorUrl.jpeg
&StyleUrl=http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/ExtendImageStyle/styleUrl.jpeg
&<公共請求參數>           

正常傳回示例

"Data": {
    "Url": "http://ivpd-cn-shanghai.oss-cn-shanghai.aliyuncs.com/upload/result_/2019-11-21/invi__015743391278011000102_oRkJ4W.jpg?Expires=1574598327&OSSAccessKeyId=LTAI4FeJ8qKkYn6SrHhQ****&Signature=8%2B65JsTvfxXjKtc2ztKGw%2BxxmL****"
  },
  "RequestId": "F1ABC965-2612-4680-9DE3-B5C77434B9B7"
}           

圖檔:

Day5筆記——風格遷移

風格參考圖檔:

Day5筆記——風格遷移

合成圖:

Day5筆記——風格遷移

核心代碼:

import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
public class ExtendImageStyle {
    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);
        ExtendImageStyleRequest request = new ExtendImageStyleRequest();
        request.setRegionId("cn-shanghai");
        request.setMajorUrl("http://explorer-image.oss-cn-shanghai.aliyuncs.com/iskjCQfNe0cJ_zLOydKNQxVp/%E8%9C%82%E8%9C%9C%E6%B5%8F%E8%A7%88%E5%99%A8_%E6%BE%B9%E4%BD%BA%E7%84%8A_4.jpg?OSSAccessKeyId=LTAI4Fk9FstqSEYnqKJ5Dpeo&Expires=1604383888&Signature=CqDBEvD%2BRZsxp%2Ffuyz3Lo4GTRUw%3D");
        request.setStyleUrl("http://viapi-test.oss-cn-shanghai.aliyuncs.com/sanjiye-meizi/%E5%9B%BE%E5%83%8F%E5%A2%9E%E5%BC%BA/%E9%A3%8E%E6%A0%BC%E8%BF%81%E7%A7%BB1.jpg");
        try {
            ExtendImageStyleResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    }
}           

總結:通過這些天的學習,我明白了視覺産生方面的許多知識和技巧,明白了架構的重要性和協調性。這篇文章所述内容實作了不同圖檔之間的風格遷移,也是我很喜歡的一項功能,希望各位小夥伴能夠從懷收獲知識。

參考連結:

https://vision.aliyun.com/experience/detail?spm=a211p3.14471187.J_7524944390.19.6e92797duEBsEB&tagName=imageenhan&children=ExtendImageStyle

繼續閱讀