Beispiel #1
0
        public OcrConfiguration this[string configName]
        {
            get
            {
                OcrConfiguration rv = Configurations.SingleOrDefault(x => x.Name == configName);
                if (rv == null)
                    rv = new OcrConfiguration(true);

                return rv;
            }
        }
Beispiel #2
0
        public string Initialize(OcrConfiguration ocrConfig, int imageWidth, int imageHeight)
        {
            string initMsg = NativeHelpers.SetupBasicOcrMetrix(ocrConfig);
            if (initMsg == null)
                NativeHelpers.SetupOcr(ocrConfig);

            return initMsg;
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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;
        }
Beispiel #5
0
        public static string SetupBasicOcrMetrix(OcrConfiguration ocrConfig)
        {
            int[] zonePixels = ocrConfig.Zones.Any()
                ? ocrConfig.Zones.Select(x => x.Pixels.Count).ToArray()
                : new int[0];

            if (ocrConfig.Zones.Any(x => x.ZoneId < 0))
                return "ZoneIds must be greater or equal than zero.";

            if (ocrConfig.Zones.Any(x => x.ZoneId >= ocrConfig.Zones.Count))
                return "Each ZoneId must equal the index of the zone in the zone list.";

            SetupIntegrationPreservationArea(
                true,
                ocrConfig.Alignment.FrameTopOdd,
                ocrConfig.Alignment.FrameTopEven,
                ocrConfig.Alignment.CharHeight);

            int hr = SetupOcrAlignment(
                 ocrConfig.Alignment.Width,
                 ocrConfig.Alignment.Height,
                 ocrConfig.Alignment.FrameTopOdd,
                 ocrConfig.Alignment.FrameTopEven,
                 ocrConfig.Alignment.CharWidth,
                 ocrConfig.Alignment.CharHeight,
                 ocrConfig.Alignment.CharPositions.Count,
                 ocrConfig.Zones.Count,
                 (int)ocrConfig.Mode,
                 zonePixels);

            if (hr != 0)
                return "OCR config is incompatible with the current device.";
            else
                return null;
        }