Ejemplo n.º 1
0
        public override IObservable <TArray> Process <TArray>(IObservable <Tuple <TArray, TArray> > source)
        {
            var outputFactory = ArrFactory <TArray> .TemplateFactory;

            return(source.Select(input =>
            {
                var first = input.Item1;
                var second = input.Item2;
                var output = outputFactory(first);
                CV.AbsDiff(first, second, output);
                return output;
            }));
        }
Ejemplo n.º 2
0
        public override IObservable <IplImage> Process(IObservable <IplImage> source)
        {
            return(Observable.Defer(() =>
            {
                int averageCount = 0;
                IplImage image = null;
                IplImage difference = null;
                IplImage background = null;
                return source.Select(input =>
                {
                    if (background == null || background.Size != input.Size)
                    {
                        averageCount = 0;
                        image = new IplImage(input.Size, IplDepth.F32, input.Channels);
                        difference = new IplImage(input.Size, IplDepth.F32, input.Channels);
                        background = new IplImage(input.Size, IplDepth.F32, input.Channels);
                        background.SetZero();
                    }

                    var output = new IplImage(input.Size, IplDepth.U8, input.Channels);
                    if (averageCount < BackgroundFrames)
                    {
                        averageCount++;
                        output.SetZero();
                        CV.Acc(input, background);
                        if (averageCount == BackgroundFrames)
                        {
                            CV.ConvertScale(background, background, 1.0 / averageCount, 0);
                        }
                    }
                    else
                    {
                        CV.Convert(input, image);
                        switch (SubtractionMethod)
                        {
                        case SubtractionMethod.Bright:
                            CV.Sub(image, background, difference);
                            break;

                        case SubtractionMethod.Dark:
                            CV.Sub(background, image, difference);
                            break;

                        case SubtractionMethod.Absolute:
                        default:
                            CV.AbsDiff(image, background, difference);
                            break;
                        }

                        if (AdaptationRate > 0)
                        {
                            CV.RunningAvg(image, background, AdaptationRate);
                        }

                        CV.Threshold(difference, output, ThresholdValue, 255, ThresholdType);
                    }

                    return output;
                });
            }));
        }