예제 #1
0
        /// <inheritdoc />
        public override void Apply(byte[] data, bool eos)
        {
            if (this.FullTestFrame)
            {
                MMALLog.Logger.LogDebug("Have full test frame");

                // If we have a full test frame stored then we can start storing subsequent frame data to check.
                base.Apply(data, eos);
            }
            else
            {
                this.TestFrame.AddRange(data);

                if (eos)
                {
                    this.FullTestFrame = true;
                    MMALLog.Logger.LogDebug("EOS reached for test frame. Applying edge detection.");

                    // We want to apply Edge Detection to the test frame to make it easier to detect changes.
                    var edgeDetection = new EdgeDetection(this.MotionConfig.Sensitivity);
                    this.ImageContext.Data = this.TestFrame.ToArray();
                    edgeDetection.ApplyConvolution(edgeDetection.Kernel, EdgeDetection.KernelWidth, EdgeDetection.KernelHeight, this.ImageContext);
                }
            }

            if (this.FullFrame)
            {
                MMALLog.Logger.LogDebug("Have full frame, checking for changes.");

                // TODO: Check for changes.
                this.CheckForChanges(this.OnDetect);
            }
        }
예제 #2
0
        private void CheckForChanges(Action onDetect)
        {
            var edgeDetection = new EdgeDetection(EDStrength.Medium);

            this.ImageContext.Data = this.WorkingData.ToArray();
            edgeDetection.ApplyConvolution(EdgeDetection.MediumStrengthKernel, 3, 3, this.ImageContext);
            var diff = this.Analyse();

            MMALLog.Logger.LogDebug($"Diff size: {diff}");

            if (diff >= this.MotionConfig.Threshold)
            {
                MMALLog.Logger.LogInformation("Motion detected!");
                onDetect();
            }
        }