Beispiel #1
0
 protected void PlotImage(Graphics graphics, IotaVtiOcrProcessor stateManager, bool isOddField)
 {
     if (stateManager.BlockOffsetsX != null &&
         stateManager.BlockOffsetsX.Length == IotaVtiOcrProcessor.MAX_POSITIONS &&
         stateManager.BlockOffsetsX[1] > 0)
     {
         for (int i = 0; i < IotaVtiOcrProcessor.MAX_POSITIONS; i++)
         {
             if (stateManager.BlockOffsetsX[i] > 0)
             {
                 graphics.DrawRectangle(
                     Pens.Chartreuse,
                     stateManager.BlockOffsetsX[i],
                     stateManager.BlockOffsetY(isOddField),
                     stateManager.BlockWidth,
                     stateManager.BlockHeight);
             }
         }
     }
     else
     {
         graphics.DrawRectangle(
             Pens.Chartreuse,
             0,
             stateManager.BlockOffsetY(isOddField),
             m_Width,
             stateManager.BlockHeight);
     }
 }
Beispiel #2
0
        private int GetLastFrameNoDigitStartPosition(IotaVtiOcrProcessor stateManager)
        {
            uint[] result = new uint[m_CalibratedPositons[0].Image.Length];
            for (int i = 0; i < m_CalibratedPositons.Count - 2; i++)
            {
                uint[] prev = m_CalibratedPositons[i].Image;
                uint[] next = m_CalibratedPositons[i + 1].Image;

                for (int j = 0; j < result.Length; j++)
                {
                    int x = j % stateManager.CurrentImageWidth;
                    if (x > ROUTH_START_FRAME_NUMBER_BLOCKS && prev[j] != next[j])
                    {
                        result[j]++;
                    }
                }
            }

            int bestRating        = -1;
            int bestStartPosition = -1;
            int oneOfEvenOrOddY   = stateManager.BlockOffsetY(false);

            for (int x = ROUTH_START_FRAME_NUMBER_BLOCKS; x < stateManager.CurrentImageWidth - stateManager.BlockWidth; x++)
            {
                int currentRating = 0;

                for (int y = 0; y < stateManager.BlockHeight; y++)
                {
                    for (int k = 0; k < stateManager.BlockWidth; k++)
                    {
                        if (result[x + k + (oneOfEvenOrOddY + y) * stateManager.CurrentImageWidth] > 0)
                        {
                            currentRating++;
                        }
                    }
                }

                if (currentRating > bestRating)
                {
                    bestStartPosition = x;
                    bestRating        = currentRating;
                }
            }

            return(bestStartPosition);
        }
Beispiel #3
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);
        }