Ejemplo n.º 1
0
        public override void Process(IotaVtiOcrProcessor stateManager, Graphics graphics, int frameNo, bool isOddField)
        {
            if (m_Width != stateManager.CurrentImageWidth || m_Height != stateManager.CurrentImageHeight)
            {
                Reinitialise(stateManager.CurrentImageWidth, stateManager.CurrentImageHeight);
                ROUTH_START_FRAME_NUMBER_BLOCKS = (int)Math.Round(IotaVtiOcrProcessor.COEFF_FIRST_FRAME_NO_DIGIT_POSITION * stateManager.CurrentImageWidth);
            }

            CalibrateBlockPositonsTop(stateManager, isOddField);
            CalibrateBlockPositonsWidth(stateManager, isOddField);

            if (m_CalibratedPositons.Count == 10)
            {
                stateManager.BlockOffsetYOdd  = m_CalibratedPositons.Where(x => x.IsOddField).MostCommonValue(x => x.BlockOffsetY);
                stateManager.BlockOffsetYEven = m_CalibratedPositons.Where(x => !x.IsOddField).MostCommonValue(x => x.BlockOffsetY);

                var  normalizedPositions = new List <CalibratedBlockPosition>();
                bool swapped;
                if (CalibrateFrameNumberBlockPositions(stateManager, stateManager.IsTvSafeModeGuess, out normalizedPositions, out swapped) &&
                    RecognizedTimestampsConsistent(stateManager, normalizedPositions, swapped))
                {
                    stateManager.ChangeState <IotaVtiOcrCalibratedState>();
                    stateManager.Process(stateManager.CurrentImage, stateManager.CurrentImageWidth, stateManager.CurrentImageHeight, graphics, frameNo, isOddField);
                    return;
                }
                else if (CalibrateFrameNumberBlockPositions(stateManager, !stateManager.IsTvSafeModeGuess, out normalizedPositions, out swapped) &&
                         RecognizedTimestampsConsistent(stateManager, normalizedPositions, swapped))
                {
                    stateManager.ChangeState <IotaVtiOcrCalibratedState>();
                    stateManager.Process(stateManager.CurrentImage, stateManager.CurrentImageWidth, stateManager.CurrentImageHeight, graphics, frameNo, isOddField);
                    return;
                }
                else
                {
                    // Make sure we always remove the whole frame, so swapped fields create less issues when learning the characters
                    m_CalibratedPositons.RemoveAt(0);
                    m_CalibratedPositons.RemoveAt(0);
                }
            }

            if (graphics != null)
            {
                base.PlotImage(graphics, stateManager, isOddField);
            }
        }