private void PlotDigitPatterns(IotaVtiOrcManaged ocrEngine) { List <uint[]> patterns = ocrEngine.GetLearntDigitPatterns(); if (patterns.Count > 12) { Bitmap bmpZero = Pixelmap.ConstructBitmapFromBitmapPixels(patterns[0], ocrEngine.BlockWidth, ocrEngine.BlockHeight); picZero.Image = bmpZero; picZero.Update(); Bitmap bmpOne = Pixelmap.ConstructBitmapFromBitmapPixels(patterns[1], ocrEngine.BlockWidth, ocrEngine.BlockHeight); picOne.Image = bmpOne; picOne.Update(); Bitmap bmpTwo = Pixelmap.ConstructBitmapFromBitmapPixels(patterns[2], ocrEngine.BlockWidth, ocrEngine.BlockHeight); picTwo.Image = bmpTwo; picTwo.Update(); Bitmap bmpThree = Pixelmap.ConstructBitmapFromBitmapPixels(patterns[3], ocrEngine.BlockWidth, ocrEngine.BlockHeight); picThree.Image = bmpThree; picThree.Update(); Bitmap bmpFour = Pixelmap.ConstructBitmapFromBitmapPixels(patterns[4], ocrEngine.BlockWidth, ocrEngine.BlockHeight); picFour.Image = bmpFour; picFour.Update(); Bitmap bmpFive = Pixelmap.ConstructBitmapFromBitmapPixels(patterns[5], ocrEngine.BlockWidth, ocrEngine.BlockHeight); picFive.Image = bmpFive; picFive.Update(); Bitmap bmpSix = Pixelmap.ConstructBitmapFromBitmapPixels(patterns[6], ocrEngine.BlockWidth, ocrEngine.BlockHeight); picSix.Image = bmpSix; picSix.Update(); Bitmap bmpSeven = Pixelmap.ConstructBitmapFromBitmapPixels(patterns[7], ocrEngine.BlockWidth, ocrEngine.BlockHeight); picSeven.Image = bmpSeven; picSeven.Update(); Bitmap bmpEight = Pixelmap.ConstructBitmapFromBitmapPixels(patterns[8], ocrEngine.BlockWidth, ocrEngine.BlockHeight); picEight.Image = bmpEight; picEight.Update(); Bitmap bmpNine = Pixelmap.ConstructBitmapFromBitmapPixels(patterns[9], ocrEngine.BlockWidth, ocrEngine.BlockHeight); picNine.Image = bmpNine; picNine.Update(); Bitmap bmp83 = Pixelmap.ConstructBitmapFromBitmapPixels(patterns[10], ocrEngine.BlockWidth, ocrEngine.BlockHeight); pic83.Image = bmp83; pic83.Update(); Bitmap bmp86 = Pixelmap.ConstructBitmapFromBitmapPixels(patterns[11], ocrEngine.BlockWidth, ocrEngine.BlockHeight); pic86.Image = bmp86; pic86.Update(); Bitmap bmp89 = Pixelmap.ConstructBitmapFromBitmapPixels(patterns[12], ocrEngine.BlockWidth, ocrEngine.BlockHeight); pic89.Image = bmp89; pic89.Update(); } }
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 = ""; }