Esempio n. 1
0
        private InkData GetInkData()
        {
            var data = new InkData();

            data.language = "zh-CN";
            data.strokes  = new List <InkStroke>();

            int id = 0;

            foreach (var stroke in this.inkCanvas.InkPresenter.StrokeContainer.GetStrokes())
            {
                var points = stroke.GetInkPoints();

                var convertPoints = ConvertPixelsToMillimeters(points);

                var inkStorke = new InkStroke();
                inkStorke.id = id++;

                var sb = new StringBuilder();
                foreach (var point in convertPoints)
                {
                    sb.Append(point.X);
                    sb.Append(",");
                    sb.Append(point.Y);
                    sb.Append(",");
                }
                inkStorke.points = sb.ToString().TrimEnd(',');

                data.strokes.Add(inkStorke);
            }

            return(data);
        }
Esempio n. 2
0
        /// <summary>
        /// 开始识别笔迹
        /// </summary>
        /// <param name="imgPath"></param>
        /// <returns></returns>
        private async Task <string> InkRec(InkData data)
        {
            string inkRecognitionUrl = "/inkrecognizer/v1.0-preview/recognize";
            string endPoint          = "https://inkrec-01.cognitiveservices.azure.com/";
            string subscriptionKey   = "e51e7d9ff5ea4cf3bc5b24f2bc078c7e";

            using (HttpClient client = new HttpClient {
                BaseAddress = new Uri(endPoint)
            })
            {
                System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
                var jsonData = JsonConvert.SerializeObject(data);
                var content  = new StringContent(jsonData, Encoding.UTF8, "application/json");
                var res      = await client.PutAsync(inkRecognitionUrl, content);

                if (res.IsSuccessStatusCode)
                {
                    var result = await res.Content.ReadAsStringAsync();

                    return(result);
                }
                else
                {
                    var err = $"ErrorCode: {res.StatusCode}";

                    return(err);
                }
            }
        }