Exemple #1
0
        public async Task <string> getAllStringInPicAsync(string path)
        {
            string res = "";

            Console.WriteLine("OCR ...");
            var    ocrTool    = new BingOCR();
            string jsonString = await ocrTool.MakeOCRRequestAsync(path);

            Console.WriteLine("OCR finished");
            JObject jo   = (JObject)JsonConvert.DeserializeObject(jsonString);
            JArray  text = jo["regions"][0]["lines"] as JArray;

            int lines = text.Count;

            for (int i = 0; i < lines; i++)
            {
                res += WordUtils.words2string(text[i]);
            }

            return(res);
        }
Exemple #2
0
        static void Basic3ChoicesImageProcess(string imageFilePath, out string question, out string[] option)
        {
            option  = new string[10];
            choices = 3;

            string questionPic = PicUtils.SplitPic(imageFilePath, gameCode, workspace);

            // Execute the REST API call.
            Console.WriteLine("OCR ...");

            var    ocrTool    = new BingOCR();
            string jsonString = ocrTool.MakeOCRRequestAsync(questionPic).Result;

            Console.WriteLine("OCR finished");
            JObject jo   = (JObject)JsonConvert.DeserializeObject(jsonString);
            JArray  text = jo["regions"][0]["lines"] as JArray;

            int    lines   = text.Count;
            string allText = "";

            for (int i = 0; i < lines; i++)
            {
                allText += WordUtils.words2string(text[i]);
            }

            int questionMarkIndex = Math.Max(allText.IndexOf("?"), allText.IndexOf("?"));

            question = allText.Substring(0, questionMarkIndex);
            // cut off the question number
            while (question[0] >= '0' && question[0] <= '9')
            {
                question = question.Substring(1, question.Length - 1);
            }

            for (int i = 0; i < choices; i++)
            {
                option[i] = WordUtils.words2string(text[lines - choices + i]);
            }
        }