public string Initialize(OcrConfiguration ocrConfig, int imageWidth, int imageHeight) { this.ocrConfig = ocrConfig; for (int i = 0; i < ocrConfig.Alignment.CharPositions.Count; i++) { int leftPos = ocrConfig.Alignment.CharPositions[i]; var ocredChar = new OcredChar(i, leftPos, ocrConfig.Alignment.CharWidth, ocrConfig.Alignment.CharHeight); ocredChar.PopulateZones(ocrConfig.Zones); ocredCharsOdd.Add(ocredChar); ocredChar = new OcredChar(i, leftPos, ocrConfig.Alignment.CharWidth, ocrConfig.Alignment.CharHeight); ocredChar.PopulateZones(ocrConfig.Zones); ocredCharsEven.Add(ocredChar); } zoneChecker = new OcrZoneChecker( ocrConfig, ocrConfig.Alignment.Width, ocrConfig.Alignment.Height, ocrConfig.Zones, ocrConfig.Alignment.CharPositions); charRecognizer = new OcrCharRecognizer( ocrConfig.Zones, ocrConfig.CharDefinitions); cameraImage = new CameraImage(); testContext = new StateContext(); generateDebugImages = false; return null; }
public static void SetupOcr(OcrConfiguration ocrConfig) { // Build the ocr zone matrix in managed world using the OcrZoneChecker var zoneChecker = new OcrZoneChecker( ocrConfig, ocrConfig.Alignment.Width, ocrConfig.Alignment.Height, ocrConfig.Zones, ocrConfig.Alignment.CharPositions); foreach (CharDefinition charDef in ocrConfig.CharDefinitions) { SetupOcrChar(charDef.Character[0], charDef.FixedPosition.HasValue ? charDef.FixedPosition.Value : -1); foreach (ZoneSignature zoneSignt in charDef.ZoneSignatures) { OcrZone zone = ocrConfig.Zones.Single(z => z.ZoneId == zoneSignt.ZoneId); int pixelsInZone = zone.Pixels.Count; SetupOcrCharDefinitionZone(charDef.Character[0], zoneSignt.ZoneId, (int)zoneSignt.ZoneValue, pixelsInZone); } } //for (int y = 0; y < ocrConfig.Alignment.Height; y++) //{ // for (int x = 0; x < ocrConfig.Alignment.Width; x++) // { // if (zoneChecker.OcrPixelMap[y, x] != 0) // { // int charId; // bool isOddField; // int zoneId; // int zonePixelId; // OcrZoneChecker.UnpackValue(zoneChecker.OcrPixelMap[y, x], out charId, out isOddField, out zoneId, out zonePixelId); // Trace.WriteLine(string.Format("[{0},{1}] = {2}|({3},{4},{5},{6})", x, y, zoneChecker.OcrPixelMap[y, x], charId, isOddField ? "O" : "E", zoneId, zonePixelId)); // } // } //} SetupOcrZoneMatrix(zoneChecker.OcrPixelMap); }