1 #include <iostream>
2 #include "alibabacloud/core/AlibabaCloud.h"
3 #include "alibabacloud/imageenhan/ImageenhanClient.h"
4 #include "alibabacloud/core/CommonClient.h"
5 #include "model/common.h"
6
7 extern "C" {
8 using namespace std;
9 using namespace AlibabaCloud;
10 using namespace AlibabaCloud::Imageenhan;
11
erasePerson(char * imageUrl,char * userMaskUrl,AIModelCBFunc cb)12 int erasePerson(char *imageUrl, char *userMaskUrl, AIModelCBFunc cb)
13 {
14 InitializeSdk();
15 string key = getAccessKey();
16 string secret = getAccessSecret();
17 ClientConfiguration configuration;
18 configuration.setRegionId(CLOUD_AI_REGION_ID);
19 configuration.setEndpoint(CLOUD_AI_IMAGEENHAN_ENDPOINT);
20 ImageenhanClient client(key, secret, configuration);
21 Model::ErasePersonRequest request;
22 string imageURL, userMaskURL;
23 ImageEnhanResultStruct result;
24 string url;
25 int ret = 0;
26
27 imageURL = imageUrl;
28 userMaskURL = userMaskUrl;
29 request.setScheme("http");
30 request.setMethod(HttpRequest::Method::Post);
31 request.setImageURL(imageURL);
32 request.setUserMask(userMaskURL);
33
34 auto outcome = client.erasePerson(request);
35 cout << endl << "result erasePerson describeInstances returned:" << endl;
36 cout << "error code: " << outcome.error().errorCode() << endl;
37 cout << "requestId: " << outcome.result().requestId() << endl << endl;
38 cout << "imageUrl: " << outcome.result().getData().imageUrl << endl;
39
40 url = outcome.result().getData().imageUrl;
41
42 if (url.size() > 0) {
43 result.person.url = (char *)url.c_str();
44 result.person.imageLen = getResponseBodyByUrl(result.person.url, &result.person.image);
45
46 if (result.person.image && cb) {
47 ret = cb((void *)&result);
48 }
49 }
50 ShutdownSdk();
51 return ret;
52 }
53
extendImageStyle(char * majorUrl,char * styleUrl,AIModelCBFunc cb)54 int extendImageStyle(char *majorUrl, char *styleUrl, AIModelCBFunc cb)
55 {
56 InitializeSdk();
57 string key = getAccessKey();
58 string secret = getAccessSecret();
59 ClientConfiguration configuration;
60 configuration.setRegionId(CLOUD_AI_REGION_ID);
61 configuration.setEndpoint(CLOUD_AI_IMAGEENHAN_ENDPOINT);
62 ImageenhanClient client(key, secret, configuration);
63 Model::ExtendImageStyleRequest request;
64 string inMajorURL, outMajorURL;
65 string styleURL, outImageURL;
66 ImageEnhanResultStruct result;
67 int ret = 0;
68
69 inMajorURL = majorUrl;
70 styleURL = styleUrl;
71 request.setScheme("http");
72 request.setMethod(HttpRequest::Method::Post);
73 request.setMajorUrl(inMajorURL);
74 request.setStyleUrl(styleURL);
75
76 auto outcome = client.extendImageStyle(request);
77 cout << endl << "imageenhan extendImageStyle describeInstances returned:" << endl;
78 cout << "error code: " << outcome.error().errorCode() << endl;
79 cout << "requestId: " << outcome.result().requestId() << endl << endl;
80 cout << "outMajorURL: " << outcome.result().getData().majorUrl << endl;
81 cout << "outImageURL: " << outcome.result().getData().url << endl;
82
83 outMajorURL = outcome.result().getData().majorUrl;
84 outImageURL = outcome.result().getData().url;
85
86 if (outMajorURL.size() > 0 && cb) {
87 result.style.majorUrl = (char *)outMajorURL.c_str();
88 result.style.majorImageLen = getResponseBodyByUrl(outMajorURL.c_str(), &result.style.majorImage);
89 ret = cb((void *)&result);
90 } else if (outImageURL.size() > 0 && cb) {
91 result.style.majorUrl = NULL;
92 result.style.outImageUrl = (char *)outImageURL.c_str();
93 result.style.outImageLen = getResponseBodyByUrl(outImageURL.c_str(), &result.style.outImage);
94 ret = cb((void *)&result);
95 }
96
97 ShutdownSdk();
98 return ret;
99 }
100
101 }
102