コード例 #1
0
ファイル: frmRunTestCases.cs プロジェクト: hpavlov/tangra3
        private void RunOCRTestCases(string[] testCases)
        {
            lbErrors.Items.Clear();

            foreach (string folder in testCases)
            {
                string folderNameOnly = Path.GetFileName(folder);
                bool isTvSafeGuess = folderNameOnly.EndsWith("_tvsafe");
                bool[] REVERSE_OPTIONS = new bool[] { false, true };

                for (int option = 0; option <= 1; option++)
                {
                    lvlTestCaseDescription.Text = string.Format("Test case {0} {1}", folderNameOnly, (option == 0 ? "" : " (Reversed)"));
                    lvlTestCaseDescription.Update();

                    List<string> testFiles = TestCaseHelper.LoadTestImages(folder, REVERSE_OPTIONS[option]);

                    var ocrEngine = new IotaVtiOrcManaged();
                    bool isSuccess = false;
                    bool calibrated = false;
                    bool digitsPlotted = false;

                    for (int i = 0; i < testFiles.Count; i++)
                    {
                        Bitmap bmpOdd = (Bitmap)Bitmap.FromFile(testFiles[i]);
                        i++;
                        Bitmap bmpEven = (Bitmap)Bitmap.FromFile(testFiles[i]);

                        Pixelmap pixelmapOdd = Pixelmap.ConstructFromBitmap(bmpOdd, TangraConfig.ColourChannel.Red);
                        Pixelmap pixelmapEven = Pixelmap.ConstructFromBitmap(bmpEven, TangraConfig.ColourChannel.Red);

                        if (!calibrated)
                            calibrated = ocrEngine.ProcessCalibrationFrame(i / 2, pixelmapOdd.Pixels, pixelmapEven.Pixels, bmpOdd.Width, bmpOdd.Height, isTvSafeGuess);

                        if (calibrated)
                        {
                            if (!digitsPlotted)
                            {
                                PlotDigitPatterns(ocrEngine);
                                digitsPlotted = true;
                            }

                            DateTime dt;
                            isSuccess = ocrEngine.ExtractTime(i / 2, 1, pixelmapOdd.Pixels, pixelmapEven.Pixels, bmpOdd.Width, bmpOdd.Height, out dt);
                            if (!isSuccess)
                                break;
                        }
                    }

                    pbar.Value++;

                    if (isSuccess)
                        pbarSuccess.Value++;
                    else
                    {
                        pbarError.Value++;
                        lbErrors.Items.Add(string.Format("{0}{1} - {2}", folderNameOnly, (option == 0 ? "" : " (Reversed)"), calibrated ? "Error extracting times" : " Failed to calibrate"));
                    }

                    lblError.Text = string.Format("Errored {0}/{1}", pbarError.Value, pbar.Value);
                    lblSuccessful.Text = string.Format("Successful {0}/{1}", pbarSuccess.Value, pbar.Value);

                    Application.DoEvents();
                }
            }

            lvlTestCaseDescription.Text = "";
        }