コード例 #1
0
        public void ocrTest()
        {
            string          test  = @"{""language"":""fr"",""orientation"":""Up"",""textAngle"":0.0,""regions"":[{""boundingBox"":""1012,1184,1156,269"",""lines"":[{""boundingBox"":""1176,1184,992,208"",""words"":[{""boundingBox"":""1176,1184,992,208"",""text"":""244:19 - 901""}]},{""boundingBox"":""1012,1419,614,34"",""words"":[{""boundingBox"":""1012,1422,252,31"",""text"":""09 - 8846150""},{""boundingBox"":""1276,1424,108,25"",""text"":""n•am""},{""boundingBox"":""1404,1419,222,29"",""text"":""HONDA""}]}]}]}";
            MatchCollection match = Regex.Matches(test, @"""boundingBox""\:""([^""]*)"",""text""\:""([^""]*)""}", RegexOptions.IgnoreCase);

            for (int i = 0; i < match.Count; i++)
            {
                string   res          = "{" + match[i].Value;
                matchBox msgDataPoint = JsonConvert.DeserializeObject <matchBox>(res);
                boxx = boxy = boxwidth; boxheigth = 0;
            }
        }
コード例 #2
0
        // Get Number of the car from json response from azure
        public string getNumberOfCarFromJson(byte[] byteData, string azureOcrresult)
        {
            string result = "";

            // We take the result with minimum 7 chars
            // We suppose we can get severl responses, so we match all occurences
            MatchCollection match = Regex.Matches(azureOcrresult, @"""boundingBox""\:""([^""]*)"",""text""\:""([^""]*)""}", RegexOptions.IgnoreCase);

            for (int i = 0; i < match.Count; i++)
            {
                string   res          = "{" + match[i].Value;
                matchBox msgDataPoint = JsonConvert.DeserializeObject <matchBox>(res);
                boxx = boxy = boxwidth; boxheigth = 0;

                // We take the first or the last having minimum 7 chars and not a phone number
                if (result == "" || msgDataPoint.text.Length >= 7 && msgDataPoint.text[0] != '0')
                {
                    // save region
                    string[] region = msgDataPoint.boundingBox.Split(',');
                    boxx      = int.Parse(region[0]);
                    boxy      = int.Parse(region[1]);
                    boxwidth  = int.Parse(region[2]);
                    boxheigth = int.Parse(region[3]);
                    if (boxx >= 20)
                    {
                        boxx -= 20; boxwidth += 20;
                    }
                    if (boxy >= 20)
                    {
                        boxy -= 20; boxheigth += 20;
                    }
                    // Should test height, width of original
                    boxwidth += 0; boxheigth += 0;

                    // Cut the region where the number was found
                    cutRegion(byteData, boxx, boxy, boxwidth, boxheigth);
                    // ocr result Number cleaned
                    result      = cleanResult = hardResult = msgDataPoint.text.Replace("'", "");
                    cleanResult = cleanResult.Replace("-", "").Replace(".", "").Replace(":", "").Replace("'", "");
                }
            }
            return(result);
        }