Exemple #1
0
        public bool ExtractTime(int frameNo, int frameStep, uint[] data, bool debug, out DateTime time)
        {
            LastOddFieldOSD  = null;
            LastEvenFieldOSD = null;

            if (m_VideoController != null)
            {
                // Leave this to capture statistics
                m_VideoController.RegisterExtractingOcrTimestamps();
            }

            m_LatestFrameImage = data;

            // TODO: Add main OCR Implementation HERE


            // NOTE: if there is an error extracting the timestamp then call m_VideoController.RegisterOcrError(); for Tangra to show a counter in the status bar with number of errors so far
            // NOTE: This dummy implementation simply marks all frames as OCR errors
            if (m_VideoController != null)
            {
                m_VideoController.RegisterOcrError();
            }

            // NOTE: See IotaVtiOrcManaged.ExtractDateTime() for ideas about checking incorrectly extracted times and attempting to correct them.

            time = DateTime.MinValue;
            return(false);
        }
Exemple #2
0
        internal DateTime ExtractDateTimeBothFields(int frameNo, int frameStep, IVtiTimeStamp oddFieldOSD, IVtiTimeStamp evenFieldOSD, out string failedReason)
        {
            bool failedValidation = false;

            failedReason = null;

            if (oddFieldOSD == null || evenFieldOSD == null)
            {
                return(DateTime.MinValue);
            }

            if (frameStep != m_FrameStep)
            {
                m_FrameStep = frameStep;
                m_Corrector.Reset(m_VideoFormat);
            }

            if (oddFieldOSD.ContainsFrameNumbers)
            {
                if (oddFieldOSD.FrameNumber != evenFieldOSD.FrameNumber - 1 &&
                    oddFieldOSD.FrameNumber != evenFieldOSD.FrameNumber + 1)
                {
                    // Video fields are not consequtive
                    failedValidation = true;
                    failedReason     = "Video fields are not consequtive";
                }
            }


            try
            {
                DateTime oddFieldTimestamp = oddFieldOSD.ContainsDate
                    ? new DateTime(oddFieldOSD.Year, oddFieldOSD.Month, oddFieldOSD.Day, oddFieldOSD.Hours, oddFieldOSD.Minutes, oddFieldOSD.Seconds).AddMilliseconds(Math.Min(10000, oddFieldOSD.Milliseconds10) / 10.0f)
                    : new DateTime(1, 1, 1, oddFieldOSD.Hours, oddFieldOSD.Minutes, oddFieldOSD.Seconds).AddMilliseconds(Math.Min(10000, oddFieldOSD.Milliseconds10) / 10.0f);

                DateTime evenFieldTimestamp = evenFieldOSD.ContainsDate
                    ?  new DateTime(evenFieldOSD.Year, evenFieldOSD.Month, evenFieldOSD.Day, evenFieldOSD.Hours, evenFieldOSD.Minutes, evenFieldOSD.Seconds).AddMilliseconds(Math.Min(10000, evenFieldOSD.Milliseconds10) / 10.0f)
                    :  new DateTime(1, 1, 1, evenFieldOSD.Hours, evenFieldOSD.Minutes, evenFieldOSD.Seconds).AddMilliseconds(Math.Min(10000, evenFieldOSD.Milliseconds10) / 10.0f);

                double fieldDuration = Math.Abs(new TimeSpan(oddFieldTimestamp.Ticks - evenFieldTimestamp.Ticks).TotalMilliseconds);

                if (m_VideoFormat == VideoFormat.PAL &&
                    (Math.Abs(fieldDuration - FIELD_DURATION_PAL) > 1.0))
                {
                    // PAL field is not 20 ms
                    failedValidation = true;
                    failedReason     = string.Format("PAL field is not 20 ms. It is {0} ms. ", fieldDuration);
                }

                if (m_VideoFormat == VideoFormat.NTSC &&
                    (Math.Abs(fieldDuration - FIELD_DURATION_NTSC) > 1.0))
                {
                    // NTSC field is not 16.68 ms
                    failedValidation = true;
                    failedReason     = string.Format("NTSC field is not 16.68 ms. It is {0} ms. ", fieldDuration);
                }

                int oddEvenFieldDirection = oddFieldTimestamp.Ticks - evenFieldTimestamp.Ticks < 0 ? -1 : 1;
                if (m_Corrector.OddEvenFieldDirectionIsKnown() &&
                    oddEvenFieldDirection != m_Corrector.GetOddEvenFieldDirection())
                {
                    // Field timestamps are wrong have changed order (did they swap)?
                    failedValidation = true;
                    failedReason    += "Field timestamps are wrong have changed order (did they swap)? ";
                }

                if (Math.Max(m_Corrector.m_PrevOddTicks, m_Corrector.m_PrevEvenTicks) > Math.Min(oddFieldTimestamp.Ticks, evenFieldTimestamp.Ticks))
                {
                    failedValidation = true;
                    failedReason    += "Field timestamps are earlier than previous timestamps. ";
                }

                if (failedValidation)
                {
                    string correctionInfo;
                    failedValidation = !m_Corrector.TryToCorrect(frameNo, frameStep, null, oddFieldOSD, evenFieldOSD, m_EvenBeforeOdd, ref oddFieldTimestamp, ref evenFieldTimestamp, out correctionInfo);
                    failedReason    += ". " + correctionInfo;
                }

                if (failedValidation)
                {
                    string errorText = string.Format("OCR ERR: FrameNo: {0}, Odd Timestamp: {1}:{2}:{3}.{4} {5}, Even Timestamp: {6}:{7}:{8}.{9} {10}, {11}",
                                                     frameNo, oddFieldOSD.Hours, oddFieldOSD.Minutes, oddFieldOSD.Seconds, oddFieldOSD.Milliseconds10, oddFieldOSD.FrameNumber,
                                                     evenFieldOSD.Hours, evenFieldOSD.Minutes, evenFieldOSD.Seconds, evenFieldOSD.Milliseconds10, evenFieldOSD.FrameNumber, failedReason);

                    Trace.WriteLine(errorText);

                    if (m_CalibrationErrorProcessor.ErrorCount < 16)
                    {
                        var copy = new List <uint>();
                        copy.AddRange(m_GetCurrImageQuery());
                        m_CalibrationErrorProcessor.AddErrorImage(string.Format("ocrerr_{0}.bmp", frameNo), copy.ToArray(), 0, 0);
                        m_CalibrationErrorProcessor.AddErrorText(errorText);
                    }

                    if (m_VideoController != null)
                    {
                        m_VideoController.RegisterOcrError();
                    }

                    m_Corrector.RegisterUnsuccessfulTimestamp(frameNo, fieldDuration, frameStep, null);
                }
                else
                {
                    m_Corrector.RegisterSuccessfulTimestamp(frameNo, oddFieldOSD, evenFieldOSD, oddFieldTimestamp, evenFieldTimestamp);
                }

                if (failedValidation)
                {
                    return(DateTime.MinValue);
                }
                failedReason = null;

                if (oddFieldOSD.ContainsFrameNumbers)
                {
                    if (oddFieldOSD.FrameNumber == evenFieldOSD.FrameNumber - 1)
                    {
                        return(oddFieldTimestamp);
                    }
                    else
                    {
                        return(evenFieldTimestamp);
                    }
                }
                else
                {
                    if (m_EvenBeforeOdd)
                    {
                        return(evenFieldTimestamp);
                    }
                    else
                    {
                        return(oddFieldTimestamp);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.GetFullStackTrace());

                if (m_VideoController != null)
                {
                    m_VideoController.RegisterOcrError();
                }

                return(DateTime.MinValue);
            }
        }