Пример #1
0
        public static Image DrawSonogram(BaseSonogram sonogram, IEnumerable <EventCommon> events)
        {
            var image = new Image_MultiTrack(sonogram.GetImage(false, true, doMelScale: false));

            image.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));

            ////image.AddTrack(ImageTrack.GetWavEnvelopeTrack(sonogram, image.sonogramImage.Width));
            image.AddTrack(ImageTrack.GetSegmentationTrack(sonogram));

            //############################################################################################ TODO TODO
            //convert blob events to acoustic events for drawing purposes
            var aeEvents = new List <AcousticEvent>();

            foreach (var be in events)
            {
                aeEvents.Add(EventConverters.ConvertSpectralEventToAcousticEvent((SpectralEvent)be));
            }

            image.AddEvents(
                aeEvents,
                sonogram.NyquistFrequency,
                sonogram.Configuration.FreqBinCount,
                sonogram.FramesPerSecond);

            return(image.GetImage());
        }
        /// <summary>
        /// Detect using EPR.
        /// </summary>
        /// <param name="wavFilePath">
        ///     The wav file path.
        /// </param>
        /// <param name="eprNormalisedMinScore">
        ///     The epr Normalised Min Score.
        /// </param>
        /// <returns>
        /// Tuple containing base Sonogram and list of acoustic events.
        /// </returns>
        public static Tuple <BaseSonogram, List <AcousticEvent> > Detect(FileInfo wavFilePath, Aed.AedConfiguration aedConfiguration, double eprNormalisedMinScore, TimeSpan segmentStartOffset)
        {
            Tuple <EventCommon[], AudioRecording, BaseSonogram> aed = Aed.Detect(wavFilePath, aedConfiguration, segmentStartOffset);

            var events    = aed.Item1;
            var newEvents = new List <AcousticEvent>();

            foreach (var be in events)
            {
                newEvents.Add(EventConverters.ConvertSpectralEventToAcousticEvent((SpectralEvent)be));
            }

            var aeEvents = newEvents.Select(ae => Util.fcornersToRect(ae.TimeStart, ae.TimeEnd, ae.HighFrequencyHertz, ae.LowFrequencyHertz)).ToList();

            Log.Debug("EPR start");

            var eprRects = EventPatternRecog.DetectGroundParrots(aeEvents, eprNormalisedMinScore);

            Log.Debug("EPR finished");

            var            sonogram     = aed.Item3;
            SonogramConfig config       = sonogram.Configuration;
            double         framesPerSec = 1 / config.GetFrameOffset(); // Surely this should go somewhere else
            double         freqBinWidth = config.NyquistFreq / (double)config.FreqBinCount;

            // TODO this is common with AED
            var eprEvents = new List <AcousticEvent>();

            foreach (var rectScore in eprRects)
            {
                var ae = new AcousticEvent(
                    segmentStartOffset,
                    rectScore.Item1.Left,
                    rectScore.Item1.Right - rectScore.Item1.Left,
                    rectScore.Item1.Bottom,
                    rectScore.Item1.Top);
                ae.SetTimeAndFreqScales(framesPerSec, freqBinWidth);
                ae.SetTimeAndFreqScales(sonogram.NyquistFrequency, sonogram.Configuration.WindowSize, 0);
                ae.SetScores(rectScore.Item2, 0, 1);
                ae.BorderColour           = aedConfiguration.AedEventColor;
                ae.SegmentStartSeconds    = segmentStartOffset.TotalSeconds;
                ae.SegmentDurationSeconds = aed.Item2.Duration.TotalSeconds;

                eprEvents.Add(ae);
            }

            return(Tuple.Create(sonogram, eprEvents));
        }