예제 #1
0
        private void CalibrateBlockPositonsWidth(IotaVtiOcrProcessor stateManager, bool isOddField)
        {
            int maxRating = -1;

            int bestWidth = -1;
            var bestStartingPositions = new List<int>();

            // Determined previously
            int bestHeight = stateManager.BlockHeight;
            int bestYOffs = stateManager.BlockOffsetY(isOddField);

            int imageWidth = stateManager.CurrentImageWidth;
            var startingPositions = new List<int>();

            for (int width = m_MinBlockWidth; width <= m_MaxBlockWidth; width++)
            {
                int totalRating = 0;
                startingPositions.Clear();

                for (int x = 1; x < stateManager.CurrentImageWidth - width - 1; x++)
                {
                    bool prevTwoVerticalsAreWhite = true;

                    for (int y = bestYOffs; y < bestYOffs + bestHeight + 1; y++)
                    {
                        if (y >= stateManager.CurrentImageHeight) continue;

                        if (stateManager.CurrentImage[x - 1 + imageWidth * y] < 127 || stateManager.CurrentImage[x + imageWidth * y] < 127)
                        {
                            prevTwoVerticalsAreWhite = false;
                            break;
                        }
                    }

                    if (!prevTwoVerticalsAreWhite)
                        continue;

                    for (int y = bestYOffs; y < bestYOffs + bestHeight + 1; y++)
                    {
                        if (y >= stateManager.CurrentImageHeight) continue;

                        if (stateManager.CurrentImage[x + 1 + imageWidth * y] < 127)
                        {
                            totalRating++;

                            if (stateManager.CurrentImage[x + width - 1 + imageWidth * y] < 127 &&
                                stateManager.CurrentImage[x + width + imageWidth * y] > 127 &&
                                stateManager.CurrentImage[x + width + 1 + imageWidth * y] > 127)
                            {
                                startingPositions.Add(x);
                                totalRating++;
                            }
                        }
                    }
                }

                if (totalRating > maxRating)
                {
                    // Collect stats about the starting positions ??
                    maxRating = totalRating;
                    bestWidth = width;
                    bestStartingPositions.Clear();
                    bestStartingPositions.AddRange(startingPositions);
                }
            }

            stateManager.BlockWidth = bestWidth;

            var calibrationBlock = new CalibratedBlockPosition(stateManager.CurrentImage)
            {
                BlockWidth = bestWidth,
                BlockHeight = bestHeight,
                BlockOffsetY = bestYOffs,
                BestStartingPositions = bestStartingPositions.ToArray(),
                IsOddField = isOddField
            };
            m_CalibratedPositons.Add(calibrationBlock);
        }
예제 #2
0
        private void CalibrateBlockPositonsWidth(IotaVtiOcrProcessor stateManager, bool isOddField)
        {
            int maxRating = -1;

            int bestWidth             = -1;
            var bestStartingPositions = new List <int>();

            // Determined previously
            int bestHeight = stateManager.BlockHeight;
            int bestYOffs  = stateManager.BlockOffsetY(isOddField);

            int imageWidth        = stateManager.CurrentImageWidth;
            var startingPositions = new List <int>();

            for (int width = m_MinBlockWidth; width <= m_MaxBlockWidth; width++)
            {
                int totalRating = 0;
                startingPositions.Clear();

                for (int x = 1; x < stateManager.CurrentImageWidth - width - 1; x++)
                {
                    bool prevTwoVerticalsAreWhite = true;

                    for (int y = bestYOffs; y < bestYOffs + bestHeight + 1; y++)
                    {
                        if (y >= stateManager.CurrentImageHeight)
                        {
                            continue;
                        }

                        if (stateManager.CurrentImage[x - 1 + imageWidth * y] < 127 || stateManager.CurrentImage[x + imageWidth * y] < 127)
                        {
                            prevTwoVerticalsAreWhite = false;
                            break;
                        }
                    }

                    if (!prevTwoVerticalsAreWhite)
                    {
                        continue;
                    }

                    for (int y = bestYOffs; y < bestYOffs + bestHeight + 1; y++)
                    {
                        if (y >= stateManager.CurrentImageHeight)
                        {
                            continue;
                        }

                        if (stateManager.CurrentImage[x + 1 + imageWidth * y] < 127)
                        {
                            totalRating++;

                            if (stateManager.CurrentImage[x + width - 1 + imageWidth * y] < 127 &&
                                stateManager.CurrentImage[x + width + imageWidth * y] > 127 &&
                                stateManager.CurrentImage[x + width + 1 + imageWidth * y] > 127)
                            {
                                startingPositions.Add(x);
                                totalRating++;
                            }
                        }
                    }
                }

                if (totalRating > maxRating)
                {
                    // Collect stats about the starting positions ??
                    maxRating = totalRating;
                    bestWidth = width;
                    bestStartingPositions.Clear();
                    bestStartingPositions.AddRange(startingPositions);
                }
            }

            stateManager.BlockWidth = bestWidth;

            var calibrationBlock = new CalibratedBlockPosition(stateManager.CurrentImage)
            {
                BlockWidth            = bestWidth,
                BlockHeight           = bestHeight,
                BlockOffsetY          = bestYOffs,
                BestStartingPositions = bestStartingPositions.ToArray(),
                IsOddField            = isOddField
            };

            m_CalibratedPositons.Add(calibrationBlock);
        }