Example #1
0
        private void button_SaveConfig_Click(object sender, EventArgs e)
        {
            int x = 0, y = 0, width = 2, height = 2;

            try
            {
                x      = int.Parse(textBox_X.Text);
                y      = int.Parse(textBox_Y.Text);
                width  = int.Parse(textBox_Width.Text);
                height = int.Parse(textBox_Height.Text);
            }
            catch
            {
                MessageBox.Show("截图信息格式不正确,必须为数字");
                return;
            }

            Config.CutX           = x;
            Config.CutY           = y;
            Config.CutHeight      = height;
            Config.CutWidth       = width;
            Config.UseEmulator    = checkBox_PCScreen.Checked;
            Config.OCR_API_KEY    = textBox_API_KEY.Text;
            Config.OCR_SECRET_KEY = textBox_SECRET_KEY.Text;
            BaiDuOCR.InitBaiDuOCR(textBox_API_KEY.Text, textBox_SECRET_KEY.Text);
            Config.SaveConfig();
            MessageBox.Show("保存成功", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #2
0
        private void button_SaveConfig_Click(object sender, EventArgs e)
        {
            int x = 0, y = 0, width = 2, height = 2;

            try
            {
                x      = int.Parse(textBox_X.Text);
                y      = int.Parse(textBox_Y.Text);
                width  = int.Parse(textBox_Width.Text);
                height = int.Parse(textBox_Height.Text);
            }
            catch
            {
                MessageBox.Show("截图信息格式不正确,必须为数字");
                return;
            }

            Config.CutX              = x;
            Config.CutY              = y;
            Config.CutHeight         = height;
            Config.CutWidth          = width;
            Config.UseEmulator       = checkBox_PCScreen.Checked;
            Config.RemoveUselessInfo = checkBox_RemoveUselessInfo.Checked;
            Config.ShowABC           = checkBox_ShowABC.Checked;
            Config.UseSoGou          = checkBox_UseSoGou.Checked;
            Config.OCR_API_KEY       = textBox_API_KEY.Text;
            Config.OCR_SECRET_KEY    = textBox_SECRET_KEY.Text;
            Config.OCREnhance        = checkBox_Enhance.Checked;
            BaiDuOCR.InitBaiDuOCR(textBox_API_KEY.Text, textBox_SECRET_KEY.Text);

            if (radioButton_NoHighLighting.Checked)
            {
                Config.HighlightMode = HLMode.NoHighLighting;
            }
            else if (radioButton_Compatible.Checked)
            {
                Config.HighlightMode = HLMode.Compatible;
            }
            else
            {
                Config.HighlightMode = HLMode.Fast;
            }

            Config.SaveConfig();
            MessageBox.Show("保存成功", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #3
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            //便于并发请求同时进行
            ServicePointManager.MaxServicePoints                  = 512;
            ServicePointManager.DefaultConnectionLimit            = 512;
            System.Net.ServicePointManager.DefaultConnectionLimit = 64;

            //禁用跨线程UI操作检查
            Control.CheckForIllegalCrossThreadCalls = false;

            Config.LoadConfig();

            BaiDuOCR.InitBaiDuOCR(Config.OCR_API_KEY, Config.OCR_SECRET_KEY);

            browserForm = new BrowserForm();
            browserForm.Show();
            MainForm_Move(null, null);

            HotKey.RegisterHotKey(Handle, 100, HotKey.KeyModifiers.None, Keys.F7);
        }
Example #4
0
        private void SolveProblem()//答题
        {
            if (!checkBox_InPutProblem.Checked)
            {
                label_Message.Text      = "正在获取手机界面";
                label_Message.ForeColor = Color.Orange;
                //获取屏幕截图
                string screenShotPath;
                byte[] smallScreenShot;
                try
                {
                    if (Config.UseEmulator)//是否为模拟器
                    {
                        smallScreenShot = BitmapOperation.CutScreen(new Point(Config.CutX, Config.CutY), new Size(Config.CutWidth, Config.CutHeight));
                    }
                    else
                    {
                        screenShotPath  = ADB.GetScreenshotPath();
                        smallScreenShot = BitmapOperation.CutImage(screenShotPath, new Point(Config.CutX, Config.CutY), new Size(Config.CutWidth, Config.CutHeight));
                        System.IO.File.Delete(screenShotPath);
                    }
                }
                catch (Exception ex)
                {
                    throw new ADBException("获取的屏幕截图无效!" + ex);
                }

                label_Message.Text = "正在识别题目信息";
                //调用API识别文字
                string recognizeResult = BaiDuOCR.Recognize(smallScreenShot);

                string[] recRes = Regex.Split(recognizeResult, "\r\n|\r|\n");
                //检查识别结果正确性
                CheckOCRResult(recRes);
                //显示识别结果

                int notEmptyIndex = recRes.Length - 1;
                while (String.IsNullOrEmpty(recRes[notEmptyIndex]))//忽略空行
                {
                    notEmptyIndex--;
                }

                textBox_AnswerC.Text = AnalyzeProblem.RemoveABC(recRes[notEmptyIndex--]);
                textBox_AnswerB.Text = AnalyzeProblem.RemoveABC(recRes[notEmptyIndex--]);
                textBox_AnswerA.Text = AnalyzeProblem.RemoveABC(recRes[notEmptyIndex--]);

                string problem = recRes[0];

                int dotP = problem.IndexOf('.');
                if (dotP != -1)
                {
                    problem = problem.Substring(dotP + 1, problem.Length - dotP - 1);
                }

                for (int i = 1; i <= notEmptyIndex; i++)
                {
                    problem += recRes[i];
                }

                textBox_Problem.Text = problem;
            }

            //浏览器跳转到搜索页面

            if (Config.RemoveUselessInfo)//移除无用信息
            {
                browserForm.Jump("http://www.baidu.com/s?wd=" + SearchEngine.UrlEncode(AnalyzeProblem.RemoveUselessInfo(textBox_Problem.Text)));
            }
            else
            {
                browserForm.Jump("http://www.baidu.com/s?wd=" + SearchEngine.UrlEncode(textBox_Problem.Text));
            }

            browserForm.Show();
            browserForm.WindowState = FormWindowState.Normal;

            label_Message.Text = "正在分析题目";
            //分析问题
            string[]      answerArr = new string[] { textBox_AnswerA.Text, textBox_AnswerB.Text, textBox_AnswerC.Text };
            AnalyzeResult aRes      = AnalyzeProblem.Analyze(textBox_Problem.Text, answerArr);

            char[] ans = new char[3] {
                'A', 'B', 'C'
            };
            label_Message.Text = "最有可能选择:" + ans[aRes.Index] + "项!" + answerArr[aRes.Index];
            if (aRes.Oppose)
            {
                label_Message.Text += "(包含否定词)";
            }

            label_Message.ForeColor   = Color.Green;
            label_AnalyzeA.ForeColor  = Color.DarkGreen;
            label_AnalyzeB.ForeColor  = Color.DarkGreen;
            label_AnalyzeC.ForeColor  = Color.DarkGreen;
            textBox_AnswerA.ForeColor = Color.Black;
            textBox_AnswerB.ForeColor = Color.Black;
            textBox_AnswerC.ForeColor = Color.Black;

            switch (aRes.Index)
            {
            case 0: label_AnalyzeA.ForeColor = Color.Red;
                textBox_AnswerA.ForeColor    = Color.Red;
                break;

            case 1: label_AnalyzeB.ForeColor = Color.Red;
                textBox_AnswerB.ForeColor    = Color.Red;
                break;

            case 2: label_AnalyzeC.ForeColor = Color.Red;
                textBox_AnswerC.ForeColor    = Color.Red;
                break;
            }

            //显示概率
            label_AnalyzeA.Text = "概率:" + aRes.Probability[0].ToString() + "%";
            label_AnalyzeB.Text = "概率:" + aRes.Probability[1].ToString() + "%";
            label_AnalyzeC.Text = "概率:" + aRes.Probability[2].ToString() + "%";
        }