Пример #1
0
        // Constructor
        public MorphForm( Bitmap overlay )
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent( );

            // create filter
            filter = new Morph( overlay );
            // set percent value on track bar
            percentageBar.Value = (int) ( filter.Percent * 100 );
            // set filter for preview window
            filterPreview.Filter = filter;
        }
Пример #2
0
        /// <summary>
        /// processes Frame for Motion Detection based on background generation
        /// </summary>
        /// <param name="frame">
        /// Takes in 2 Bitmap parameters, currentFrame and backgroundFrame
        /// </param>
        /// <returns>
        /// frame in which motion is marked
        /// </returns>
        public Bitmap processFrame(params Bitmap[] frame)
        {
            Bitmap currentFrame = frame[0];
            // create grayscale filter (BT709)
            Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
            Bitmap GScurrentFrame = filter.Apply(currentFrame);
            if (this.backgroundFrame == null)
            {
                this.backgroundFrame = (Bitmap)GScurrentFrame.Clone();
                GScurrentFrame.Dispose();
                return currentFrame;
            }
            else
            {
                Morph filterx = new Morph(GScurrentFrame);
                filterx.SourcePercent = 0.75;
                Bitmap tmp = filterx.Apply(backgroundFrame);
                // dispose old background
                backgroundFrame.Dispose();
                backgroundFrame = tmp;

                // create processing filters sequence
                FiltersSequence processingFilter = new FiltersSequence();
                processingFilter.Add(new Difference(backgroundFrame));
                processingFilter.Add(new Threshold(threshold_val));
                processingFilter.Add(new Opening());
                processingFilter.Add(new Edges());
                // apply the filter
                Bitmap tmp1 = processingFilter.Apply(GScurrentFrame);

                IFilter extractChannel = new ExtractChannel(RGB.R);
                Bitmap redChannel = extractChannel.Apply(currentFrame);
                Merge mergeFilter = new Merge();
                mergeFilter.OverlayImage = tmp1;
                Bitmap t3 = mergeFilter.Apply(redChannel);
                ReplaceChannel rc = new ReplaceChannel(RGB.R, t3);
                t3 = rc.Apply(currentFrame);
                redChannel.Dispose();
                tmp1.Dispose();
                GScurrentFrame.Dispose();
                return t3;
            }
        }
Пример #3
0
        private void InitFilters()
        {
            L_brownFilter = new ColorFiltering();
            D_brownFilter = new ColorFiltering();

            L_brownFilter.Red = new IntRange(125, 140);
            L_brownFilter.Green = new IntRange(95, 110);
            L_brownFilter.Blue = new IntRange(110, 130);

            D_brownFilter.Red = new IntRange(55, 85);
            D_brownFilter.Green = new IntRange(45, 75);
            D_brownFilter.Blue = new IntRange(45, 75);

            blobFilter = new BlobsFiltering();
            blobFilter.CoupledSizeFiltering = true;
            blobFilter.MinWidth = 70;
            blobFilter.MinHeight = 70;

            diffFilter = new Difference();
            diffFilter.OverlayImage = back;

            thresholdFilter = new Threshold(40);

            erosionFilter = new Erosion();

            edgeFilter = new Edges();

            openFilter = new Opening();

            pixelFilter = new Pixellate();

            morphFilter = new Morph();
            morphFilter.SourcePercent = 0.9;

            towardsFilter = new MoveTowards();
            towardsFilter.StepSize = 10;

            blobCounter = new BlobCounter();
            blobGrabber = new ExtractBiggestBlob();
        }
Пример #4
0
 private void InitFilters()
 {
     gsFilter = new Grayscale(0.33, 0.33, 0.33);
     diffFilter = new Difference();
     motionFilter = new FiltersSequence();
     motionFilter.Add(new Threshold(THRESHOLD));
     motionFilter.Add(new BlobsFiltering(MIN_BLOB, MIN_BLOB, MAX_BLOB, MAX_BLOB, true));
     morphFilter = new Morph();
     morphFilter.SourcePercent = MORPH_PERCENT;
     blobCount = new BlobCounter();
     blobCount.MinHeight = MIN_BLOB;
     blobCount.MaxHeight = MAX_BLOB;
 }
Пример #5
0
        private Bitmap getChangingBackgroundDifference(Bitmap frame)
        {
            if (background == null || lastFrame == null)
            {
                background = frame;
                return null;
            }

            if (background != lastFrame)
            {
                Morph filter = new Morph(background);
                filter.SourcePercent = 0.5;
                background = filter.Apply(lastFrame);
            }

            Difference differenceFilter = new Difference(background);
            Bitmap differenceBitmap = differenceFilter.Apply(frame);

            return differenceBitmap;
        }
 // Process max 200 frames (5 min) in 320x240 resolution. So 76KB memory per frame (grayscale). 1200 frames is max 93 MB of RAM (normally less because of area)
 private void processFilePart()
 {
     int nrofframes = imageStack.Length;
     int i;
     int sum;
     // create filters
     Morph morphFilter = new Morph(); // filter for adapting background
     morphFilter.SourcePercent = 0.8;
     Difference differenceFilter = new Difference(); // filter for subtracting two frames
     Threshold thresholdFilter = new Threshold(); // filter for thresholding
     FiltersSequence filters = new FiltersSequence(); // all filters in one
     filters.Add(morphFilter);
     filters.Add(differenceFilter);
     filters.Add(thresholdFilter);
     thresholdFilter.ThresholdValue = threshold;
     // Process here
     for (i = 0; i < nrofframes; i++)
     {
         // move background towards current frame
         morphFilter.OverlayImage = imageStack[i];
         Bitmap Temp = morphFilter.Apply(backgroundFrame);
         backgroundFrame = Temp.Clone(new Rectangle(0, 0, Temp.Width, Temp.Height), Temp.PixelFormat);
         Temp.Dispose();
         // apply rest of the filters
         differenceFilter.OverlayImage = imageStack[i];
         Bitmap Temp2 = filters.Apply(backgroundFrame);
         sum = 0;
         // Calculate sum of white pixels
         for (int j = 0; j < Temp2.Width; j++)
         {
             for (int k = 0; k < Temp2.Height; k++)
             {
                 if (Temp2.GetPixel(j, k) != Color.FromArgb(255, 0, 0, 0))
                 {
                     sum += 1;
                 }
             }
         }
         Temp2.Dispose();
         if (sum > objectsize)
         {
             tracker.addFrame(currentFrame);
         }
         currentFrame += 1;
     }
     // Discard Array
     for (i = 0; i < nrofframes; i++)
     {
         imageStack[i].Dispose();
     }
 }