C# 通过阿里云接口实现人脸属性识别

简介: C# 通过阿里云接口实现人脸属性识别

应用场景

个人简历注册系统中,上传个人照片是我们经常遇到的一项功能。为了提高数据采集的有效性,我们需要的功能不仅是能够提供上传一张图片而已,至少我们要对图片的内容进行一个基本的判断,如是否为人像,性别判断等。通过人脸属性识别功能,采集的数据的准确率将明显提高,有效的数据为后期对注册的个人能够提供更加有效的功能服务,从而提高系统的可用性。

本文将以阿里云提供的接口服务,实现人脸属性识别功能。

关于阿里云人脸属性识别

官方介绍其人脸属性识别能力可以识别检测人脸的性别、年龄、表情、眼镜、帽子五种属性,支持人脸遮挡、光照、模糊度、姿态、噪声综合质量评分,支持检测含有多张人脸的照片属性判断。

更多信息内容请参照:https://help.aliyun.com/zh/viapi/developer-reference/api-m78543?spm=a2c4g.11186623.0.i8

开发前请准备如下操作:

1. 注册阿里云账号。

2. 开通人脸人体服务能力,获取开发者ID和开发者密钥,后继开发会用到。

开发运行环境

操作系统: Windows Server 2019 DataCenter

.net版本: .netFramework4.0 或以上

开发工具:VS2019  C#

类设计

类 AFR (阿里人脸识别) 设计见下表:

类属性

序号 属性名 类型 说明
1 ErrorMessage string 发生任何异常返回的错误信息
2 ErrorResultJson string 请求错误时返回结果Json数据
3 debugMessage string 调试信息
4 AnalysisReport string 综合分析报告建议
5 ResultJson string 正常返回的JSON数据
6 face_num int 识别图片中的人脸个数,默认为0
7 errno int 接口返回的错误码
8 err_msg string 接口返回的错误信息
9 request_id string 接口返回的申请ID
10 face_rect int[] 接口识别有人像时,存储每个人像在图片中的矩形框,分别是[left, top, width, height]。如有多个人脸,则依次顺延,返回矩形框。
11 face_prob float[] 接口识别有人像时,存储每个人像的人脸检测的概率,取值范围0~1。如有多个人脸,则依次返回。例如有两个人脸则返回[face_prob1, face_prob2]
12 pose float[]

接口识别有人像时,存储每个人像的人脸姿态,格式为[yaw, pitch, roll]。如有多个人脸,则依次返回。

yaw为左右角度,取值范围-90~90。

pitch为上下角度,取值范围-90~90。

roll为平面旋转角度,取值范围-180~180。

13 landmark_num int[] 接口识别有人像时,存储每个人像的人脸检测的特征点数目,目前固定为105点。依次为:眉毛24点,眼睛32点,鼻子6点,嘴巴34点,外轮廓9点。
14 landmark float[] 与landmark_num对应,如果有时则返回人脸的特征点定位结果,每个人脸返回一组特征点位置,表示方式为(x0, y0, x1, y1, ……)。如有多个人脸,则依次返回,返回定位浮点数。
15 iris float[] 接口识别有人像时,存储每个人像的左右两个瞳孔的中心点坐标和半径,每个人脸6个浮点数,顺序为[left_iris_cenpt.x, left_iris_cenpt.y, left_iris_radius, right_iris_cenpt.x, right_iris_cenpt.y, right_iris_radis]
16 gender int[] 接口识别有人像时,存储每个人像的性别,0 女性,1 男性
17 age int[] 接口识别有人像时,存储每个人像的预判年龄值
18 expression int[] 接口识别有人像时,存储每个人像的表情结果,0 中性,1 微笑
19 glass int[] 接口识别有人像时,存储每个人像是否佩戴眼镜,0 没有,1 普通眼镜,2 墨镜
20 dense_fea_len int 人脸识别返回的特征维度,目前固定为1024。
21 dense_fea float[] 与dense_fea_len对应,存储每个人像的特征维度值

类方法

matchAFR 方法调用返回对应的类属性数据,参数见如下表格:

序号 参数名 类型 说明
1 ImageFileOrUrl string 可传递物理文件路径或网络url图片路径

本方法返回 string 类型的 Json 接口返回值(如果成功的话)。

实现代码

创建AFR类

public class AFR{
                public string ErrorMessage = "";
                public string ErrorResultJson = "";
                public string debugMessage = "";
                public string AnalysisReport = "";
                public string ResultJson = "";
                public int face_num = 0;
                public int errno = -1;
                public string err_msg = "";
                public string request_id = "";
                public int[] face_rect = null;
                public float[] face_prob = null;
                public float[] pose = null;
                public int[] landmark_num = null;
                public float[] landmark = null;
                public float[] iris = null;
                public int[] gender = null;
                public int[] age = null;
                public int[] expression = null;
                public int[] glass = null;
                public int dense_fea_len = 0;
                public float[] dense_fea = null;
 
 
 
                public AFR()
                {
                }
                public string matchAFR(string ImageFileOrUrl)
                {
                    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;
                    //ak,sk信息设置
                    string ak_id = "您的开发者ID";
                    string ak_secret = "您的开发者密钥";
 
                    string method = "POST";
                    string accept = "application/json";
                    string contentType = accept;
                    string body = "";
                    if (ImageFileOrUrl.ToLower().IndexOf("http") == 0)
                    {
                        body = "{\"type\":0, \"image_url\":\"" + ImageFileOrUrl + "\"}";
                    }
                    else
                    {
                        body = "{\"type\":1, \"content\":\"" +ImgToBase64String(ImageFileOrUrl)+ "\"}";
                    }
                    debugMessage += "body:" + body;
                    byte[] data = Encoding.ASCII.GetBytes(body);
                    string date = DateTime.UtcNow.GetDateTimeFormats('r')[0].ToString();
                    string urlpra = "/face/attribute";
                    string bodyMd5 = Convert.ToBase64String(new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(body)));
                    string result = "";
 
                    //待加密
                    string stringToSign = method + "\n" + accept + "\n" + bodyMd5 + "\n" + contentType + "\n" + date + "\n" + urlpra;
 
                    //stringToSign计算 HMAC-SHA1得到signature
                    string signature = Convert.ToBase64String(new System.Security.Cryptography.HMACSHA1(Encoding.UTF8.GetBytes(ak_secret)).ComputeHash(Encoding.UTF8.GetBytes(stringToSign)));
 
                    //得到 authorization header
                    string authHeader = "Dataplus " + ak_id + ":" + signature;
                    WebRequest req = WebRequest.Create("https://dtplus-cn-shanghai.data.aliyuncs.com/face/attribute");
                    req.Method = method;
                    req.ContentType = accept;
 
                    req.GetRequestStream().Write(data, 0, data.Length);
 
                    //利用反射机制 解决:"此标头必须使用适当的属性进行修改" 异常
                    MethodInfo priMethod = req.Headers.GetType().GetMethod("AddWithoutValidate", BindingFlags.Instance | BindingFlags.NonPublic);
                    priMethod.Invoke(req.Headers, new[] { "Date", date });
                    priMethod.Invoke(req.Headers, new[] { "Authorization", authHeader });
                    priMethod.Invoke(req.Headers, new[] { "Accept", accept });
 
                    string t = DateTime.UtcNow.GetDateTimeFormats('r')[0].ToString();
                    try
                    {
                        ResultJson = new StreamReader(req.GetResponse().GetResponseStream()).ReadToEnd();
                    }
                    catch (WebException ex)
                    {
                        ErrorMessage="request error:"+ex.Message;
                        ErrorResultJson=new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
                    }
                    Newtonsoft.Json.Linq.JObject jsonObj = new JObject();
                    try
                    {
                        jsonObj = Newtonsoft.Json.Linq.JObject.Parse(ResultJson);
                    }
                    catch (Exception e)
                    {
                        ErrorMessage += " parse json error:\r\n"+e.Message;
                        return ResultJson;
                    }
                    Dictionary<string, string> jd = new Dictionary<string, string>();
                    jd.Add("face_num","int");
                    jd.Add("errno","int");
                    jd.Add("err_msg", "string");
                    jd.Add("request_id", "string");
                    jd.Add("face_rect","int[]");
                    jd.Add("face_prob","float[]");
                    jd.Add("pose","float[]");
                    jd.Add("landmark_num","int[]");
                    jd.Add("landmark","float[]");
                    jd.Add("iris","float[]");
                    jd.Add("gender","int[]");
                    jd.Add("age","int[]");
                    jd.Add("expression","int[]");
                    jd.Add("glass","int[]");
                    jd.Add("dense_fea_len","int");
                    jd.Add("dense_fea","float[]");
                    foreach (KeyValuePair<string, string> kvp in jd)
                    {
                        string key= kvp.Key;
                        string value = kvp.Value;
                        if (jsonObj[key] == null)
                        {
                            continue;
                        }
                        if (value == "string")
                        {
                            this.GetType().GetField(key, BindingFlags.Public | BindingFlags.Instance).SetValue(this, jsonObj[key].ToString());
                        }else if (value=="int"){
                            this.GetType().GetField(key, BindingFlags.Public | BindingFlags.Instance).SetValue(this, int.Parse(jsonObj[key].ToString()));
                        }else if (value=="int[]"){
                            string[] ss=jsonObj[key].ToString().Replace("[","").Replace("]","").Split(',');
                            int[] vs= Array.ConvertAll<string, int>(ss , int.Parse);
                            this.GetType().GetField(key, BindingFlags.Public | BindingFlags.Instance).SetValue(this,vs);
                        }else if (value=="float[]"){
                            string[] ss=jsonObj[key].ToString().Replace("[","").Replace("]","").Split(',');
                            float[] vs= Array.ConvertAll<string, float>(ss , float.Parse);
                            this.GetType().GetField(key, BindingFlags.Public | BindingFlags.Instance).SetValue(this,vs);
                        }
                       
                    }
 
                    return ResultJson;
                }
}

调用举例

假设 Page 页面有 ReportResult 文本框,用于接收调试信息,则调用示例代码如下:

AFR afr = new AFR();
string result = afr.matchAFR("d:\\test.png");
 
if (afr.face_num < 1)
{
    ReportResult.Text = "您上传的图片未通过检测,请上传证件照!" ;
    ReportResult.Text += "\r\n 错误码:" + afr.errno.ToString();
    ReportResult.Text += "\r\n 错误信息:" + afr.err_msg;
    ReportResult.Text += "\r\n 组件返回的错误信息:" + afr.ErrorMessage;
}
else
{
    ReportResult.Text = "人脸个数:" + afr.face_num.ToString();
    ReportResult.Text += "\r\n为测试仅显示第一张人脸的部分信息:";
    ReportResult.Text += "\r\n 请求ID:" + afr.request_id.ToString();
    ReportResult.Text += "\r\n 性别:" + (afr.gender[0] == 1 ? "男" : "女");
    ReportResult.Text += "\r\n 年龄:" + afr.age[0].ToString();
    ReportResult.Text += "\r\n 表情:" + (afr.expression[0] == 0 ? "中性" : "微笑");
    ReportResult.Text += "\r\n 是否佩戴眼镜:" + (afr.glass[0] == 0 ? "无眼镜" : "有眼镜");
    ReportResult.Text += "\r\n 相似度:" + afr.face_prob[0].ToString();
}
 
ReportResult.Text += "\r\n原始返回结果:\r\n" + result;

调用成功后会返回类似如下结果:

{"face_num":1,"face_rect":[88,117,136,174],"face_prob":[1.0],"pose":[3.063825845718384,4.910022258758545,-0.9108244180679321],"landmark_num":105,"landmark":[96.68414306640625,170.6302947998047,145.2351531982422,168.97509765625,120.00067138671875,159.82064819335938,120.90005493164062,167.8106689453125,102.38734436035156,163.5238494873047,110.8702163696289,160.14938354492188,129.0392608642578,161.15672302246094,137.828125,163.6239013671875,104.79263305664062,169.93443298339844,112.78489685058594,168.4033660888672,129.03677368164062,167.66854858398438,137.09991455078125,168.75784301757812,169.3986053466797,170.36138916015625,213.41302490234375,166.6717071533203,191.11814880371094,159.33004760742188,191.36776733398438,168.1770782470703,175.71771240234375,165.05921936035156,183.17724609375,161.55892944335938,199.36065673828125,159.0685577392578,207.3585968017578,161.0877227783203,176.7578125,169.98834228515625,184.0217742919922,168.75424194335938,198.7238311767578,167.7462158203125,206.08677673339844,167.45741271972656,113.46994018554688,183.4793701171875,138.22927856445312,183.2007598876953,116.0947036743164,181.07772827148438,119.22150421142578,179.37924194335938,122.52190399169922,178.04869079589844,126.01652526855469,177.38088989257812,129.57440185546875,177.42849731445312,132.95672607421875,178.52862548828125,135.92669677734375,180.48812866210938,116.26364135742188,185.11109924316406,119.41836547851562,185.83798217773438,122.64004516601562,186.1615447998047,125.87516021728516,186.29660034179688,129.1121826171875,186.2530517578125,132.31192016601562,185.76229858398438,135.388427734375,184.75466918945312,174.51666259765625,183.63681030273438,198.0377960205078,182.55035400390625,176.80075073242188,181.1608428955078,179.55935668945312,179.22967529296875,182.68472290039062,177.97528076171875,186.02232360839844,177.52073669433594,189.3846893310547,177.7332305908203,192.6211700439453,178.67042541503906,195.62161254882812,180.20301818847656,177.26760864257812,185.10821533203125,180.269775390625,185.95538330078125,183.34695434570312,186.46804809570312,186.46473693847656,186.57894897460938,189.5694122314453,186.27333068847656,192.59494018554688,185.51333618164062,195.48876953125,184.34902954101562,157.83877563476562,184.7027587890625,159.61050415039062,211.51937866210938,158.72714233398438,198.09765625,159.09381103515625,221.50299072265625,141.2174072265625,221.5289306640625,175.7108154296875,220.9249267578125,134.406494140625,247.30429077148438,178.79208374023438,248.2057647705078,139.58602905273438,246.75558471679688,174.0359344482422,247.6773681640625,155.92715454101562,239.45440673828125,150.44760131835938,237.02993774414062,162.19281005859375,237.405029296875,142.0148162841797,241.4398956298828,170.80972290039062,242.2832794189453,138.14230346679688,244.28314208984375,145.93763732910156,238.66595458984375,166.70745849609375,239.47509765625,174.8702850341797,245.1505584716797,155.89956665039062,255.2139434814453,144.44430541992188,253.2183837890625,168.098876953125,254.3019256591797,139.20443725585938,250.64041137695312,150.0730743408203,254.76480102539062,162.06033325195312,255.51461791992188,173.65682983398438,251.62850952148438,155.9151611328125,243.98104858398438,156.12539672851562,248.637451171875,147.54718017578125,244.04049682617188,147.9060821533203,247.2126007080078,165.25906372070312,244.3838653564453,165.06532287597656,247.87339782714844,143.5548858642578,245.36361694335938,143.73641967773438,247.17507934570312,151.72662353515625,243.6070556640625,152.0291748046875,247.8469696044922,160.60391235351562,243.82192993164062,160.600830078125,248.3178253173828,169.71737670898438,245.84439086914062,169.54925537109375,247.71495056152344,85.55014038085938,188.23446655273438,220.13031005859375,186.76321411132812,159.31922912597656,289.3772888183594,97.57391357421875,254.536865234375,212.1865234375,249.98770141601562,88.65830993652344,221.46817016601562,218.63357543945312,218.26873779296875,124.95125579833984,280.3636779785156,190.25814819335938,276.92132568359375],"iris":[127.3431396484375,180.98782348632812,4.834486961364746,185.8067626953125,181.27252197265625,4.834486961364746],"gender":[1],"age":[36],"expression":[0],"glass":[0],"dense_fea_len":1024,"dense_fea":[0.046098366379737854,-6.71264308039099E-4,-0.04782719165086746,0.024575287476181984,-0.011956856586039066,0.00994771346449852,0.012042451649904251,-0.024469321593642235,-0.0693206638097763,-0.051547855138778687,-0.0380408801138401,0.003723258851096034,-0.016651300713419914,0.009410679340362549,-0.02220778726041317,-0.04585975408554077,-0.03430444002151489,0.04101677983999252,0.0061532920226454735,-0.022750407457351685,0.025490060448646545,0.009641796350479126,0.02027544192969799,-0.025795429944992065,0.00767499627545476,0.05247596651315689,-0.04112763702869415,-0.01143421046435833,-0.04646250605583191,-0.010038233362138271,-0.08515710383653641,-0.0512097105383873,0.010260507464408875,0.050140686333179474,-0.04481654241681099,0.024572938680648804,0.039220020174980164,0.03973635658621788,0.0348416343331337,-0.02840936742722988,0.024055851623415947,-4.299356078263372E-4,0.02006477303802967,-0.00472356379032135,0.015026944689452648,-0.001800643396563828,0.026021158322691917,8.914683712646365E-4,0.03202429786324501,-0.020875710994005203,-0.009568466804921627,0.019307903945446014,0.022058874368667603,-0.0239229928702116,-0.022555990144610405,0.002026299713179469,0.0058197276666760445,0.026030197739601135,-0.038742631673812866,-0.007237780373543501,-0.04723525047302246,0.023245053365826607,-0.017935531213879585,-0.06149584427475929,0.018205370754003525,-0.04166051000356674,0.01970873400568962,-0.03297030180692673,0.04065690562129021,0.018878145143389702,0.001286179176531732,-0.01580703631043434,-0.022834142670035362,-0.02588523179292679,-0.009896446950733662,0.003595947287976742,-0.04144352674484253,-0.03006993792951107,0.019586637616157532,-0.017029091715812683,0.024741845205426216,0.004588205832988024,0.034021683037281036,-0.013066667132079601,0.023940367624163628,0.013429651036858559,-0.006202229764312506,-0.011916597373783588,0.00658544572070241,-0.014081558212637901,-0.027920402586460114,0.010319571010768414,-0.05490715801715851,-0.011843009851872921,0.013249965384602547,-0.016015952453017235,-0.05548230558633804,-0.04817170277237892,-0.007219419348984957,-0.05074333772063255,0.03419409319758415,0.02883487567305565,-0.02822851948440075,0.042120032012462616,-0.0259014293551445,-0.06002623587846756,0.024476297199726105,0.025707995519042015,-0.0023154662922024727,-0.003182301064953208,-0.014581164345145226,0.048548027873039246,-0.025726957246661186,-0.011910628527402878,-0.056597474962472916,0.02176598086953163,-0.03144316002726555,-0.018229017034173012,0.004834439139813185,0.03982521593570709,0.01487128809094429,-0.053356099873781204,-0.06713875383138657,0.007250113412737846,-0.020509006455540657,-0.020086590200662613,0.041489195078611374,0.02968605048954487,0.013819938525557518,-0.0023317018058151007,0.023585807532072067,0.026680395007133484,-0.03639465942978859,0.002184969838708639,-0.010289100930094719,-0.008941167034208775,-0.029526913538575172,-0.08292659372091293,0.01567981392145157,0.002083393046632409,0.01769087091088295,0.011819778010249138,0.03778193145990372,0.0156448595225811,-0.03581925109028816,0.09686168283224106,-0.015706153586506844,-0.05877096951007843,0.053371597081422806,-0.06051822006702423,0.026921290904283524,-0.02125437557697296,0.04431984946131706,0.016509877517819405,-0.032498326152563095,0.0022121132351458073,0.08357250690460205,-0.01952679641544819,-0.007574593182653189,-0.04997594282031059,0.030624892562627792,-0.006150553934276104,-0.0032196834217756987,1.8387327145319432E-4,-0.02910483628511429,0.033508650958538055,0.006045687478035688,0.03915591537952423,-0.030794063583016396,-0.005319458432495594,-0.002699719276279211,0.003698620479553938,-0.0361333005130291,-0.014225778169929981,0.028155842795968056,-0.012366476468741894,-3.1470623798668385E-4,0.012154013849794865,0.02391788922250271,-0.05614273250102997,-0.0037504557985812426,-0.055123813450336456,0.032101117074489594,0.016192371025681496,0.025027189403772354,-0.005011188797652721,0.02302613854408264,-0.017437759786844254,-6.190393469296396E-4,0.03759479895234108,0.05121184140443802,0.009007223881781101,-0.028247445821762085,-0.015224161557853222,-0.007448477670550346,0.05467884987592697,0.03183906897902489,0.01578877680003643,-0.01707996055483818,-0.056795455515384674,-0.0027535846456885338,-0.010993645526468754,0.030998973175883293,-0.018604883924126625,0.06411296129226685,-0.011472661048173904,-0.03212443366646767,0.028069468215107918,0.011681281961500645,0.012063701637089252,-0.02422752045094967,0.04214942827820778,0.010099263861775398,-0.01894347555935383,-7.227308815345168E-4,0.038807496428489685,-0.015528161078691483,-0.004697381053119898,-0.026295436546206474,-0.027459682896733284,0.06695588678121567,0.03605693206191063,0.001788342371582985,0.007324053905904293,-0.006911867763847113,0.05672544240951538,-0.013933929614722729,0.025119636207818985,0.06661804765462875,-1.74697761394782E-5,-0.04441161826252937,-0.025446267798542976,0.020759038627147675,-0.010488967411220074,-0.015811363235116005,-0.001666783238761127,0.017427105456590652,-0.0020737750455737114,0.08523579686880112,-0.007365501020103693,0.021137624979019165,0.04383460804820061,0.03901900723576546,0.059599775820970535,-0.01553331594914198,0.04973001778125763,0.011681744828820229,0.02379477582871914,0.030175162479281425,-0.005729227792471647,0.055196039378643036,0.023595087230205536,-7.811747491359711E-4,0.08565899729728699,0.04414742812514305,0.018586859107017517,0.0486346036195755,-0.0032156279776245356,0.00266343355178833,-0.02137160487473011,-0.03367803618311882,-0.06527025997638702,-0.013928694650530815,0.034616660326719284,0.012714034877717495,-0.0027374690398573875,-0.01115227211266756,-0.055543165653944016,-0.018943030387163162,0.059609562158584595,0.042653217911720276,-0.011277738958597183,-0.04793700948357582,0.039415258914232254,0.008964926935732365,-0.02774958685040474,-0.009237061254680157,-0.004266756121069193,0.0429048128426075,-0.01658814027905464,-0.010382259264588356,-0.003724124748259783,0.028747359290719032,-0.029354887083172798,-0.03389570116996765,0.05351246893405914,-0.03814150393009186,-0.023453818634152412,-0.025578871369361877,0.02358025312423706,0.05239211022853851,0.025013567879796028,0.036235783249139786,-0.03846418485045433,0.08222752809524536,-0.006683433428406715,0.006054144352674484,0.04769162833690643,0.030343396589159966,0.007076451554894447,0.0074782040901482105,0.004301365464925766,0.009559391997754574,0.020843515172600746,-0.007496431469917297,0.04584147408604622,0.01545964926481247,0.0281954575330019,0.01194671168923378,-0.018071569502353668,-0.015967803075909615,-0.027064206078648567,-0.0010250902269035578,0.022572876885533333,-0.013286945410072803,-0.014009052887558937,0.03669840097427368,-0.01956072822213173,0.025701066479086876,-0.024806736037135124,-0.046528443694114685,-0.022843381389975548,0.03378371521830559,0.023697858676314354,-0.007552714087069035,-0.009422911331057549,0.00909062847495079,0.005575489718466997,0.02755212038755417,-0.034416984766721725,-0.0755455493927002,-0.012405972927808762,-0.009336506016552448,0.02817823551595211,0.03397878631949425,0.010907605290412903,0.02829866297543049,-0.008499563671648502,0.0394478403031826,0.005227921064943075,0.001966093434020877,0.020760169252753258,0.006955691613256931,-0.011880512349307537,-0.009931779466569424,-0.0013733318774029613,-0.04375920444726944,0.07000423222780228,-0.027763793244957924,1.1471592733869329E-4,0.04239825904369354,-0.007110233884304762,-0.024497751146554947,-0.016543885692954063,0.026653572916984558,-0.03195270150899887,0.015029325149953365,-0.0031974948942661285,-0.04320753365755081,-0.0072418018244206905,-0.04422745853662491,-0.06942488998174667,0.02498607710003853,-0.06592237204313278,-0.014792978763580322,0.025868648663163185,-0.011704663746058941,0.006938941776752472,0.0019810651428997517,-0.025618165731430054,-0.01800321601331234,0.025920649990439415,0.018846651539206505,-0.006857919506728649,0.03450857475399971,0.06421802192926407,0.018945172429084778,-0.005990407895296812,-0.006838081870228052,0.041840601712465286,-0.012429466471076012,0.06826040148735046,0.06968232244253159,-0.021168740466237068,-0.005254740826785564,0.04616771638393402,-0.003416762687265873,-0.007398528046905994,-0.02508164569735527,0.028172984719276428,0.005021214950829744,0.002804630436003208,-0.04922198876738548,0.02427532896399498,0.0033365637063980103,-0.016465211287140846,-0.03310055285692215,-0.008823085576295853,-0.003428724827244878,0.012935836799442768,-0.0010746429907158017,-0.04378671571612358,0.013231053948402405,-0.013321802020072937,-0.02365310862660408,0.011615565046668053,-0.02816510945558548,0.051121074706315994,0.009798730723559856,0.042765408754348755,-0.03164001181721687,-0.01018852461129427,-0.008799298666417599,-0.052799828350543976,-0.026488032191991806,0.011124742217361927,0.016434231773018837,-0.023875145241618156,-0.008172458969056606,0.007127709686756134,-0.004477059934288263,0.045833613723516464,-0.002595317317172885,0.012784654274582863,-0.0029817211907356977,0.02709706500172615,0.04034063592553139,0.02166733331978321,-0.02164303883910179,-0.027411337941884995,-0.02576272003352642,0.007173748221248388,0.011844170279800892,0.025989722460508347,-0.013255820609629154,-0.012781473807990551,-0.005588081665337086,0.03077414445579052,-0.03454955667257309,0.07616812735795975,0.04746060445904732,0.012632296420633793,-0.03400208428502083,0.01869506947696209,0.03405948355793953,0.023115843534469604,0.0396537221968174,0.012893631123006344,-0.002018863568082452,0.04175565764307976,-0.03783119469881058,0.04711885005235672,-0.010974409058690071,0.009494112804532051,-0.010920274071395397,0.04562301188707352,0.018727866932749748,0.06414403021335602,-0.02759217843413353,-0.03776787593960762,-0.005315478425472975,0.01816570572555065,-0.0013201830442994833,-0.01054186187684536,-0.0010491673601791263,-0.03550121560692787,0.02227957174181938,-0.048662494868040085,0.010509212501347065,0.016164040192961693,-0.0050219944678246975,-0.05764542147517204,-0.011824581772089005,-0.029845861718058586,0.04689863696694374,-0.044920291751623154,-0.01719633676111698,-0.011735809035599232,-0.04819212481379509,-0.07940912246704102,-0.03247467055916786,0.004379361867904663,-0.031912367790937424,0.02150222845375538,0.008483336307108402,-0.034711360931396484,0.04574691504240036,-0.021607793867588043,0.011371716856956482,0.05866236612200737,-0.03779318183660507,-0.03697332367300987,0.005784536246210337,-0.025781407952308655,-0.037316326051950455,-0.004151006694883108,-0.026410983875393867,-0.01829512231051922,0.011081499978899956,-0.002845402341336012,0.0038088681176304817,0.02119711972773075,0.06542104482650757,-0.05227244272828102,-0.021060867235064507,0.017043419182300568,-0.008047985844314098,-0.007794016506522894,-0.02402089536190033,-0.028616324067115784,-0.02224254049360752,0.02712211199104786,0.010525933466851711,0.003283053869381547,-0.03649358078837395,0.01992100104689598,0.006446256302297115,-0.04267066717147827,0.001711661578156054,0.007079193368554115,-0.01037709042429924,0.015608016401529312,-0.016035137698054314,0.038639865815639496,-0.04433982074260712,-0.010364695452153683,-0.0012711880262941122,-0.03815930336713791,-0.040541354566812515,0.052281901240348816,0.017663246020674706,-0.001739747473038733,-0.007706786040216684,0.01226887572556734,0.00917840376496315,0.037817977368831635,0.0147253954783082,0.016249585896730423,0.016402747482061386,0.01998963952064514,-0.031327344477176666,-0.03245166316628456,0.0019439291208982468,-0.017593149095773697,0.02404206432402134,-0.007647906895726919,-0.02609139308333397,-0.01422876212745905,0.010994266718626022,-0.05848590284585953,-3.88165790354833E-5,-0.015225082635879517,0.013661902397871017,0.026243453845381737,0.018867217004299164,9.388386970385909E-4,0.018425721675157547,0.021578731015324593,-0.04429072514176369,-0.0024434213992208242,0.006844418589025736,-0.05330650135874748,-0.02472827211022377,0.009159152396023273,0.0868426263332367,0.006257991306483746,-0.017617257311940193,0.03296062350273132,0.03399207815527916,0.024330563843250275,-0.07238133996725082,-0.02402186580002308,0.02636890299618244,-0.018137065693736076,-0.036017220467329025,-0.005291709676384926,-0.008430050686001778,-0.02509935013949871,0.025999007746577263,-0.03830443695187569,0.017280319705605507,0.00826081819832325,-0.022457879036664963,-0.005171509459614754,-0.015371412970125675,-0.02849435806274414,0.007753286510705948,0.0100318668410182,-0.004830855876207352,-0.05461980402469635,0.027558373287320137,0.015954768285155296,-0.009137497283518314,-0.0346134752035141,0.04236646369099617,0.017787180840969086,0.0359770841896534,0.03945726528763771,-0.01084999181330204,0.003838460659608245,0.08463981747627258,-0.038179196417331696,3.55585478246212E-4,0.008895255625247955,-0.008687242865562439,-0.006586404982954264,0.06033679470419884,-0.04622187465429306,0.022566769272089005,0.005000170320272446,-0.012353934347629547,-0.08776552975177765,0.0054634008556604385,-0.03598298504948616,-0.015735115855932236,0.030039167031645775,-0.037342920899391174,-0.0683424174785614,0.017265185713768005,0.06703704595565796,0.023808486759662628,0.03252547234296799,-0.009048464708030224,-0.03950274735689163,-0.008595110848546028,-0.003350849263370037,-0.0012213325826451182,-0.009112697094678879,0.010335955768823624,0.006318800617009401,-0.026813780888915062,0.03977347910404205,-0.0034127843100577593,-0.03184081241488457,-0.0684078186750412,0.03586467728018761,-0.00634970236569643,-0.050553809851408005,0.04146411269903183,-0.0014245993224903941,-0.00487337913364172,-0.019653787836432457,-0.0037100741174072027,-0.003332022810354829,-0.04709351435303688,0.009862377308309078,1.0141170059796423E-4,-0.005185387097299099,-0.07750958949327469,-0.020029660314321518,0.04050485044717789,0.02146286517381668,-0.013386240229010582,0.0010873735882341862,0.004576343111693859,0.034100160002708435,0.017490115016698837,0.006981187034398317,0.05827717483043671,0.018332423642277718,0.005136334337294102,-0.03579206019639969,0.007324870675802231,-0.043481677770614624,0.0584150105714798,0.004905556794255972,0.004974208306521177,-0.0039247190579771996,0.0011720117181539536,-0.045013781636953354,-0.03729521855711937,-0.03563304618000984,0.05541308596730232,-0.01809542067348957,-0.023605819791555405,-0.022164903581142426,0.005083604250103235,-0.006750019732862711,-0.005573284812271595,0.050153423100709915,-0.01730191335082054,-0.045652057975530624,-0.02514016628265381,-0.008478670381009579,-0.009831557050347328,-0.021737007424235344,-0.014150639995932579,0.022989876568317413,-0.020733144134283066,-3.550718247424811E-4,8.10089404694736E-4,-0.009176768362522125,-0.023621056228876114,-0.018076106905937195,0.03732863813638687,-0.004968044348061085,0.023838486522436142,0.020870279520750046,0.005567742511630058,-0.09784911572933197,-0.017871031537652016,0.05009770393371582,0.001253468100912869,-0.038119446486234665,0.04245173558592796,-0.016353880986571312,0.05072353035211563,0.010442521423101425,0.0010466375388205051,-0.04152172431349754,0.015493846498429775,-0.05636255070567131,0.014922243542969227,-0.0575774721801281,-0.028614843264222145,0.040912073105573654,0.02353854849934578,-0.03208782523870468,0.030752060934901237,-0.03414686769247055,-3.968811361119151E-4,-0.003436314407736063,-0.00266649411059916,-0.03198679909110069,-0.00561189791187644,-0.03472297638654709,0.009018922224640846,0.006567689590156078,0.005222069099545479,-0.034085072576999664,0.0045139603316783905,-0.026450028643012047,0.029834048822522163,-0.010447927750647068,-0.0013030089903622866,-0.008778835646808147,0.030372977256774902,0.0035115713253617287,0.008075645193457603,0.008152916096150875,0.030069271102547646,-0.008231809362769127,-0.03703189268708229,0.017877915874123573,-0.026759441941976547,0.002190458122640848,-0.013803086243569851,-0.0069001722149550915,0.024105867370963097,0.004128130618482828,0.026204528287053108,-0.04844764992594719,-0.021519454196095467,0.0685441866517067,0.025668736547231674,0.06891996413469315,-0.00846133567392826,0.04511960595846176,0.024181148037314415,-0.003482079366222024,0.04875043034553528,-0.05269734561443329,0.02000235766172409,0.005627804435789585,0.0053778537549078465,0.02700876258313656,0.03791481629014015,-0.020188935101032257,0.01902942731976509,-0.013538057915866375,-0.023379258811473846,0.013395191170275211,0.0380120724439621,-0.05119737610220909,-0.022862674668431282,0.015366662293672562,0.004990730434656143,0.024477960541844368,0.003742068074643612,-0.029067886993288994,-0.062331393361091614,0.09853432327508926,0.013246615417301655,-3.734893398359418E-4,-0.011825240217149258,-0.041034430265426636,0.0146833136677742,0.03644806519150734,-0.03758235275745392,-0.011433130130171776,0.03224102035164833,0.02267034910619259,0.025023678317666054,0.04367513954639435,0.062453098595142365,-0.03770848736166954,-0.02442903071641922,0.02903309278190136,0.010565118864178658,0.009497910737991333,-0.03141751512885094,-0.005263542290776968,0.025923360139131546,-0.012498853728175163,0.034878719598054886,0.0018548640655353665,-0.014106028713285923,-0.00630922568961978,-0.05012325569987297,0.04243810102343559,-0.009512875229120255,-0.030330022796988487,-0.004282497800886631,0.048864781856536865,0.04613831266760826,0.027350975200533867,0.01132719125598669,0.036818042397499084,-0.018128924071788788,-0.0034697861410677433,0.051799483597278595,-0.021121114492416382,-0.020505467429757118,-0.005396438296884298,-0.0031763697043061256,-0.04959571361541748,-0.08756358921527863,0.04677051678299904,-0.009431014768779278,-0.0404658243060112,-0.005423735361546278,-0.0268268845975399,-0.0011845690896734595,0.0019027324160560966,0.001192347495816648,0.05121946707367897,0.044164691120386124,0.05209930241107941,0.025720590725541115,0.008681167848408222,0.018956104293465614,0.02052718587219715,-0.0034289571922272444,-0.04733676090836525,0.04150920361280441,0.005249937996268272,0.048198189586400986,0.005846400745213032,0.01507329661399126,0.019931165501475334,0.025619173422455788,-0.02369903028011322,0.014167199842631817,-0.031545523554086685,0.016427163034677505,0.034511320292949677,-0.024093246087431908,-0.0011124270968139172,-0.02014351263642311,0.0385294184088707,-0.06430519372224808,0.06338658928871155,0.08033989369869232,-0.04604881629347801,-0.003260957542806864,0.007014289032667875,-0.006509764585644007,0.032448794692754745,0.004113978240638971,0.046959038823843,0.01594088040292263,0.008450859226286411,-0.01898757740855217,-0.011967107653617859,-0.013715606182813644,-0.07815057039260864,-0.0023927337024360895,0.0018419703701511025,0.045809417963027954,0.009404969401657581,0.04066988453269005,-0.03084992617368698,-0.03278268873691559,-0.017783386632800102,0.011589063331484795,0.013812430202960968,0.016948319971561432,-0.014516439288854599,-0.007362728007137775,0.027640750631690025,-0.014882616698741913,0.008015790954232216,0.01756133884191513,0.022757846862077713,0.03725438937544823,-4.4384555076248944E-4,-0.0359828844666481,0.006984667386859655,-0.024221863597631454,0.038495372980833054,-0.006659496109932661,0.05353106930851936,-0.02329278364777565,-0.019569486379623413,0.0519571453332901,-0.011783297173678875,0.07815999537706375,0.0040413253009319305,-0.02553347870707512,0.03292779624462128,0.0375850535929203,0.05153266340494156,0.045967139303684235,-0.02776169404387474,0.04949985817074776,0.008587711490690708,-0.0215854924172163,0.01263812929391861,-0.027519002556800842,0.021379154175519943,0.024575477465987206,-0.017153698951005936,-0.016671255230903625,0.006899192929267883,0.03097766824066639,0.038666270673274994,-0.020874882116913795,0.022837961092591286,0.03101176954805851,0.008808244951069355,0.016345441341400146,-0.0037519088946282864,-0.005162370856851339,-0.00477592321112752,-0.06390006840229034,0.04874777793884277,0.0334639772772789,0.006088229361921549,0.0595535971224308,0.03382528945803642,-0.0024775885976850986,-0.04458514600992203,-0.007746003568172455,-0.0014172759838402271,0.03480374440550804,-0.01609194092452526,-0.011637239716947079,-0.05705007538199425,0.02083129808306694,0.02157306857407093,-0.04101663827896118,-0.0016045308439061046,0.03084835596382618,-0.03306267410516739,-0.03532320633530617,-0.010795843787491322,0.05550059303641319,0.02100982517004013,0.02261853963136673,-0.005094023887068033,-0.049683041870594025,0.055233292281627655,-0.05224499851465225,0.052492205053567886,-0.0421721450984478,0.01679825410246849,0.0025953392032533884,-0.016245242208242416,-0.016543596982955933,0.038936078548431396,-0.07768906652927399,-0.040931250900030136,-0.06273194402456284,0.02395947277545929,0.012735548429191113,-0.020136278122663498,0.02471533603966236,0.028705473989248276,0.023144977167248726,-0.05603986978530884,-0.015055697411298752,0.056995127350091934,0.01201104000210762,0.0017938473029062152,-0.01916900835931301,0.028124021366238594,0.049055662006139755,0.010067878291010857,0.012986293993890285,-0.039381347596645355,-0.02163478173315525,0.004451516084372997,-0.03092036582529545,-0.0013065304374322295,-0.021242894232273102,-0.007882985286414623,0.055700983852148056,-0.05095270648598671,0.036300089210271835,0.004554172977805138,0.0013377367286011577,0.04102218896150589,-0.004254851955920458,-0.01056316215544939,-0.014676363207399845,-0.005296064540743828,-0.04418013244867325,-0.02479986473917961,-0.010664338245987892,-0.06018121913075447,-0.016211986541748047,0.03328600525856018,0.02890518493950367,0.023685747757554054,0.05383971706032753,-0.001685754512436688,-0.038231730461120605,0.01357197854667902,-0.025019194930791855,0.02099664881825447,0.007210657931864262,-0.037038207054138184,-0.045909516513347626,-0.031112851575016975],"errno":0,"request_id":"806b019f-f370-40c6-a2e9-aa9956a7717e"}

 

小结

调用云接口服务需要费用,我们需要根据实际应用进行成本考虑,具体内容可以参照以下链接:

https://help.aliyun.com/zh/viapi/developer-reference/billing-is-introduced-3?spm=a2c4g.11186623.0.i27

方法代码中需要获取图片的Base64编码,如何获取base64数据的方法请参照我的文章:《C# 自动填充文字内容到指定图片》

感谢您的阅读,希望本文能够对您有所帮助。

相关文章
|
6月前
|
存储 安全 编译器
C# 11.0中的泛型属性:类型安全的新篇章
【1月更文挑战第23天】C# 11.0引入了泛型属性的概念,这一新特性为开发者提供了更高级别的类型安全性和灵活性。本文将详细探讨C# 11.0中泛型属性的工作原理、使用场景以及它们对现有编程模式的改进。通过深入了解泛型属性,开发者将能够编写更加健壮、可维护的代码,并充分利用C#语言的最新发展。
|
C# 对象存储
C#上传阿里云OSS工具类AliOSSTool
C#上传阿里云OSS工具类AliOSSTool
386 0
|
2月前
|
安全 C# 索引
C#一分钟浅谈:属性与索引器的定义
本文深入浅出地介绍了C#编程中的属性和索引器。属性让字段更安全,通过访问器方法在读写时执行额外操作,如验证数据有效性;索引器则赋予类数组般的访问方式,支持基于索引的数据访问模式。文章通过示例代码展示了如何定义及使用这两种特性,并提供了常见问题及其解决方案,帮助读者写出更健壮、易维护的代码。希望读者能从中学习到如何有效利用属性和索引器增强C#类的功能性。
92 12
|
6月前
|
存储 编译器 C#
|
3月前
|
存储 安全 编译器
C#中的属性
C#中的属性
45 7
|
5月前
|
开发框架 .NET 编译器
程序与技术分享:C#基础知识梳理系列三:C#类成员:常量、字段、属性
程序与技术分享:C#基础知识梳理系列三:C#类成员:常量、字段、属性
37 2
|
4月前
|
C#
C#中使用IntPtr.Size属性来判断当前系统是32位还是64位
这段代码首先检查 `IntPtr.Size`的值,如果是4,则输出"当前系统是32位";如果是8,则输出"当前系统是64位";如果都不是,就输出"未知系统位数"。
59 0
|
6月前
|
JSON API C#
C# 通过阿里云 API 实现企业工商数据查询
C# 通过阿里云 API 实现企业工商数据查询
|
6月前
|
JSON 文字识别 算法
C# 通过阿里云 API 实现企业营业执照OCR识别
C# 通过阿里云 API 实现企业营业执照OCR识别
|
6月前
|
Java C#
C#学习相关系列之多线程(七)---Task的相关属性用法
C#学习相关系列之多线程(七)---Task的相关属性用法