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]); } }
static void ZhihuImageProcess(string imageFilePath, out string question, out string[] option) { option = new string[10]; choices = 4; Bitmap pic = (Bitmap)Image.FromFile(imageFilePath); var questionPic = pic.Clone( new Rectangle(50, 550, 950, 300), pic.PixelFormat ); var picUtil = new PicUtils(); string questionPath = workspace + "QuestionSnap" + DateTime.Now.ToString().Replace(':', '-').Replace('/', '-') + ".png"; questionPic.Save(questionPath, pic.RawFormat); var questionAsync = picUtil.getAllStringInPicAsync(questionPath); var optionAsync = new Task <string> [choices]; for (int i = 0; i < choices; i++) { var temp = pic.Clone( new Rectangle(200, 950 + i * 200, 700, 175), pic.PixelFormat ); string tempPic = workspace + "QuestionSnap" + DateTime.Now.ToString().Replace(':', '-').Replace('/', '-') + ".png"; temp.Save(tempPic, pic.RawFormat); optionAsync[i] = picUtil.getAllStringInPicAsync(tempPic); } question = questionAsync.Result; for (int i = 0; i < choices; i++) { option[i] = optionAsync[i].Result; } }