Example #1
0
        public static dynamic Record3Ex(string[] paths)
        {
            dynamic ddata = new System.Dynamic.ExpandoObject();

            List <byte[]> bss = new List <byte[]>();

            for (int i = 0; i < paths.Length; i++)
            {
                try
                {
                    bss.Add(File.ReadAllBytes(paths[i]));
                }
                catch
                {
                }
            }

            var image_c = Identification.BytesLinkRecord3456(bss.ToArray());

            //为眼压剪裁
            var image_cc = Identification.CutBytes(image_c, Identification.BytesToBitmap(image_c).Width, 500, 0, 0);

#if DEBUG
            DEBUG_saveImage(image_cc);
#endif
            JObject jb_ad;
            try
            {
                jb_ad = Identification.IdentifyImage(image_cc, ApiVersion.General);
            }
            catch (NoApiTimesException e)
            {
                throw e;
            }

            int top    = 0;
            int left   = 0;
            int height = 60;
            int width  = Identification.BytesToBitmap(image_c).Width;

            foreach (var jd in jb_ad["words_result"])
            {
                string words = jd["words"].ToString();
                if (words.Contains("眼压") || (words.Contains("眼") && words.Contains("mmHg")))
                {
                    top    = Convert.ToInt32(jd["location"]["top"].ToString());
                    left   = Convert.ToInt32(jd["location"]["left"].ToString());
                    height = Convert.ToInt32(jd["location"]["height"].ToString());

                    break;
                }
            }
            var newB = Identification.CutBitmap(Identification.BytesToBitmap(image_c), width, height, top, left);
#if DEBUG
            DEBUG_saveImage(newB);
#endif
            var var_firstwidth = 125;
            var newC           = Identification.ReArrange(Identification.BitmapToBytes(newB), new List <(int width, int height, int top, int left)> {
                (var_firstwidth, height, 0, 0), (+(width - var_firstwidth * 2) / 2 - var_firstwidth * 1 / 3, height, 0, var_firstwidth), ((width - var_firstwidth) / 2, height, 0, var_firstwidth * 2 / 3 + (width - var_firstwidth * 2) / 2)
            });
#if DEBUG
            DEBUG_saveImage(newC);
#endif
            JObject jb;
            try
            {
                jb = Identification.IdentifyImage(newC, ApiVersion.AccurateBasic);
            }
            catch (NoApiTimesException e)
            {
                throw e;
            }


            //StringWriter strWriter = new StringWriter();
            //StringBuilder sb = strWriter.GetStringBuilder();
            //string words_all = "";
            //foreach (var jd in jb["words_result"])
            //{
            //    string words = jd["words"].ToString();
            //    sb.Insert(sb.Length, words);
            //}
            //words_all = sb.ToString();
            var regex_num = new Regex(@"\d+(.\d+)?");
            try
            {
                ddata.Right_Intraocular_Pressure = Convert.ToDouble(regex_num.Match(jb["words_result"][1]["words"].ToString()).Value);
            }
            catch (Exception e)
            {
            }
            try
            {
                ddata.Left_Intraocular_Pressure = Convert.ToDouble(regex_num.Match(jb["words_result"][2]["words"].ToString()).Value);
            }
            catch (Exception e)
            {
            }

            //var regstr = @"(\d+)[^\d]+(\d+)";
            //var a = Regex.Matches(words_all, regstr);
            //ddata.Right_Intraocular_Pressure = Convert.ToDouble(a[0].Groups[0].Value);
            //ddata.Left_Intraocular_Pressure = Convert.ToDouble(a[0].Groups[1].Value);

            //var a = Regex.Matches(words_all, @"(\d+)");



            return(ddata);
        }
Example #2
0
        public static dynamic Record2(string path)
        {
            dynamic ddata = new System.Dynamic.ExpandoObject();

            var jb = Identification.IdentifyImage(path, ApiVersion.General);

            int top    = 0;
            int left   = 0;
            int height = 60;
            int width  = 1000;

            foreach (var jd in jb["words_result"])
            {
                string words = jd["words"].ToString();
                if (Convert.ToInt32(words.Contains("体温")) + Convert.ToInt32(words.Contains("脉搏")) + Convert.ToInt32(words.Contains("呼吸")) + Convert.ToInt32(words.Contains("血压")) > 2)
                {
                    top    = Convert.ToInt32(jd["location"]["top"].ToString());
                    left   = Convert.ToInt32(jd["location"]["left"].ToString());
                    height = Convert.ToInt32(jd["location"]["height"].ToString());
                    width  = Convert.ToInt32(jd["location"]["width"].ToString());

                    break;
                }
            }

            Bitmap b    = new Bitmap(path);
            var    newB = Identification.CutBitmap(b, width, height, top, left);

#if DEBUG
            DEBUG_saveImage(newB);
#endif
            var newImage = BitmapToBytes(newB);
            //var newImage_g = Identification.BytesFilter(newImage,50);
            var newJb = Identification.IdentifyImage(newImage, ApiVersion.AccurateBasic);

            foreach (var jd in newJb["words_result"])
            {
                string words = jd["words"].ToString();

                if (words.Contains("体温") || words.Contains("脉搏") || words.Contains("呼吸") || words.Contains("血压"))
                {
                    string regex = @"-?(([1-9]\d*)|0)(\.\d*[1-9])?";
                    var    g     = Regex.Matches(words, @"-?(([1-9]\d*)|0)(\.\d*[1-9])?");
                    ddata.Temperature = Convert.ToDouble(g[0].Value);
                    ddata.Pulse       = Convert.ToDouble(g[1].Value);
                    ddata.Breath      = Convert.ToDouble(g[2].Value);

                    try
                    {
                        if (words.Contains("血压") && g.Count > 4)
                        {
                            ddata.Blood_Pressure_Systolic  = Convert.ToDouble(g[3].Value);
                            ddata.Blood_Pressure_Diastolic = Convert.ToDouble(g[4].Value);
                        }
                    }
                    catch (Exception e)
                    {
                        new NoFindContextException("找不到血压");
                    }



                    break;
                }
            }
            return(ddata);
        }