BAIDU_AI开放平台_天空分割的测试
一、基本情况
目前网络服务多以Http方式直接传播数据信息。在本次调用中,首先是
开通权限
而后是鉴权
public static class AccessToken
{
// 调用getAccessToken()获取的 access_token建议根据expires_in 时间 设置缓存
// 返回token示例
public static String TOKEN = "24.adda70c11b9786206253ddb70affdc46.2592000.1493524354.282335-1234567";
// 百度云中开通对应服务应用的 API Key 建议开通应用的时候多选服务
private static String clientId = "VGzQ7jWz57mBGcDTYACgbAaD";
// 百度云中开通对应服务应用的 Secret Key
private static String clientSecret = "RZOcID2IRUCccUGzXdihZKjaoCMTZIth";
public static String getAccessToken()
{
String authHost = "https://aip.baidubce.com/oauth/2.0/token";
HttpClient client = new HttpClient();
List<KeyValuePair<String, String>> paraList = new List<KeyValuePair<string, string>>();
paraList.Add(new KeyValuePair<string, string>("grant_type", "client_credentials"));
paraList.Add(new KeyValuePair<string, string>("client_id", clientId));
paraList.Add(new KeyValuePair<string, string>("client_secret", clientSecret));
HttpResponseMessage response = client.PostAsync(authHost, new FormUrlEncodedContent(paraList)).Result;
String result = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(result);
return result;
}
}
最后是调用
public class SkySeg
{
// 天空分割
public static string skySeg()
{
string token = "24.f3ad594ec508e2830506909191535524.2592000.1602456936.282335-18132305";
string host = "https://aip.baidubce.com/rest/2.0/image-process/v1/sky_seg?access_token=" + token;
Encoding encoding = Encoding.Default;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(host);
request.Method = "post";
request.KeepAlive = true;
// 图片的base64编码
string base64 = getFileBase64("E:/sky.jpg");
String str = "image=" + HttpUtility.UrlEncode(base64);
byte[] buffer = encoding.GetBytes(str);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
string result = reader.ReadToEnd();
Console.WriteLine("天空分割:");
Console.WriteLine(result);
return result;
}
public static String getFileBase64(String fileName)
{
FileStream filestream = new FileStream(fileName, FileMode.Open);
byte[] arr = new byte[filestream.Length];
filestream.Read(arr, 0, (int)filestream.Length);
string baser64 = Convert.ToBase64String(arr);
filestream.Close();
return baser64;
}
}
获得结果(上部分是鉴权结果,下部分是编码结果)
{
"refresh_token"
:
"25.256af18522b7159b270bc7a8eb45f0b5.315360000.1915224936.282335-18132305",
"expires_in"
:
2592000,
"session_key"
:
"9mzdXUcE6x4mNuLtv5IKZwVKrOZjzxuAMv+HRnZj8k353eMTRTHoyoDvcxg4DRb3DwJaGjf1tPwvj3WbIReWnAorFLmW3Q==",
"access_token"
:
"24.f3ad594ec508e2830506909191535524.2592000.1602456936.282335-18132305",
"scope"
:
"brain_sky_seg public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\u6743\u9650 vis-classify_flower lpq_\u5f00\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\u5f00\u653eScope vis-ocr_\u865a\u62df\u4eba\u7269\u52a9\u7406 idl-video_\u865a\u62df\u4eba\u7269\u52a9\u7406",
"session_secret"
:
"f59b2284ec68e5ad5cb6bdfa8bf10779"}
{
"labelmap"
:
"iVBORw0KGgoAAAANSUhEUgAAAdkAAAHZCAAAAADvLB7eAAAEGElEQVR4Ae3BO07DAAAFwd37HzoUgFJQECkf2087o2SSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkklKJimZpGSSkknKXze+SS5LniA5LXk1yRnIu0mOIAeQvJ0cS37cJK8kVyJ5lOyQ3El+yRLJf+SKJC8jJyL5MPkIyfnI8yRXIo+S7BGQbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJskmySbJJs+gK3GgRzJbjFsgAAAABJRU5ErkJggg==",
"log_id"
:
1304554692201676800,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ILtoAAAAAElFTkSuQmCC",
"type"
:
"sky"}
二、延伸研究
对于这样一个平台,最后如果部署为网络 服务,肯定还是走Python js等语言,所以Csharp只是简单测试一下。我想思考的问题是它的应用场景在哪里?我是否需要去做准备?然后应该去做什么准备?
使用DL去做图像增强,即使是Baidu也意识到是一个领域,但是他们很可能同样也应用场景不明,其局限应该还是“真”和“假”的区分。因为其根本,这里的增强并不是一种主观意识的正确(比如夜视、静脉穿刺、去雾等),它的容错率是很低的,如果做的不“真”,最终只能是停留在娱乐领域。但是从另一个方面来说,这个方面能力的积累却不能等到场景展现出来以后再做,至少现在就 应该有所积累。这个我是放在专门的项目中来说明的。
三、BAIDU_AI开放平台
可以看出倾向于CV,这个分类可以说是有参考价值的。
四、备注
获取Access Token
请求URL数据格式
向授权服务地址https://aip.baidubce.com/oauth/2.0/token
发送请求(推荐使用POST),并在URL中带上以下参数:
- grant_type: 必须参数,固定为
client_credentials
; - client_id: 必须参数,应用的
API Key
; - client_secret: 必须参数,应用的
Secret Key
;
服务器返回的JSON文本参数如下:
- access_token: 要获取的Access Token;
- expires_in: Access Token的有效期(秒为单位,一般为1个月);
- 其他参数忽略,暂时不用;
例如:
{"refresh_token": "25.b55fe1d287227ca97aab219bb249b8ab.315360000.1798284651.282335-8574074","expires_in": 2592000,"scope": "public wise_adapt","session_key": "9mzdDZXu3dENdFZQurfg0Vz8slgSgvvOAUebNFzyzcpQ5EnbxbF+hfG9DQkpUVQdh4p6HbQcAiz5RmuBAja1JJGgIdJI","access_token": "24.6c5e1ff107f0e8bcef8c46d3424a0e78.2592000.1485516651.282335-8574074","session_secret": "dfac94a3489fe9fca7c3221cbf7525ff"}
-
返回参数
字段 是否必选 类型 说明 log_id 是 uint64 唯一的log id,用于问题定位 scoremap 否 string 分割结果的灰度图,base64编码字符串。每个像素的取值范围是0-255的整数,可以近似于概率,值越大表示越可能是天空。 labelmap 否 string 分割结果的二值图,base64编码字符串。每个像素值是0或1,0表示背景,1表示天空。 返回示例
{"labelmap": "处理后图片的二值图base64编码字符串","log_id": "1262724512684703744","scoremap": "处理后图片的灰度图base64编码字符串","type": "sky"}
附件列表