コード例 #1
0
ファイル: Index.cshtml.cs プロジェクト: lmj123qwe/DeepCard
        public async Task <ActionResult> OnPostAsync()
        {
            if (PostData.ImageFiles == null || PostData.ImageFiles.Count == 0)
            {
                Message = "请上传图片。";
                return(Page());
            }

            var httpclient = _httpClientFactory.CreateClient();
            var client     = new RecognitionClient(httpclient);

            try
            {
                List <RecResult> res  = new List <RecResult>();
                List <string>    imgs = new List <string>();
                foreach (var f in PostData.ImageFiles)
                {
                    string encoded = "";
                    using (var memoryStream = new MemoryStream())
                    {
                        await f.CopyToAsync(memoryStream);

                        var bytes = memoryStream.ToArray();
                        encoded = Convert.ToBase64String(bytes);
                    }
                    imgs.Add(encoded);
                }
                foreach (var encoded in imgs)
                {
                    string c = "";
                    try
                    {
                        c = await client.RecognizeAsync(encoded);
                    }
                    catch (Exception ex)
                    {
                        c = "识别失败";
                        Console.WriteLine(ex.ToString());
                    }
                    res.Add(new RecResult {
                        ImageSrc = encoded, CardNumber = c
                    });
                }
                Results = res;
            }
            catch
            {
                Message = "访问服务器失败。";
            }
            return(Page());
        }
コード例 #2
0
        public async Task <string> Recognize([FromBody] string image)
        {
            var    httpclient = _httpClientFactory.CreateClient();
            var    client     = new RecognitionClient(httpclient);
            string res;

            try
            {
                res = await client.RecognizeAsync(image);
            }
            catch
            {
                res = "识别失败";
            }
            return(res);
        }