Example #1
0
        private void ProcessFrame()
        {
            //Check for preprocess filter & filter to grey
            if (preFilter != null)
            {
                frame_pre = preFilter.Apply(frame_c);
                frame_gs  = gsFilter.Apply(frame_pre);
            }
            else
            {
                frame_gs = gsFilter.Apply(frame_c);
            }

            //Initialise Background
            if (back == null)
            {
                back = (Bitmap)frame_gs.Clone();
            }

            //Process frame for motion
            diffFilter.OverlayImage = back;
            frame_processed         = diffFilter.Apply(frame_gs);
            frame_processed         = motionFilter.Apply(frame_processed);

            CheckMotion();

            //Update Background
            morphFilter.OverlayImage = frame_gs;
            back = morphFilter.Apply(back);
        }
Example #2
0
        private Bitmap ProcessCurrentFrame()
        {
            Bitmap bmp;

            //curr_gs = pixelFilter.Apply(curr_gs);

            if (first)
            {
                back  = (Bitmap)curr_gs.Clone();
                first = false;
            }

            /* Detection */

            diffFilter.OverlayImage = back;
            bmp = diffFilter.Apply(curr_gs);
            bmp = thresholdFilter.Apply(bmp);
            bmp = blobFilter.Apply(bmp);
            //bmp = erosionFilter.Apply(bmp);
            //bmp = openFilter.Apply(bmp);
            //bmp = edgeFilter.Apply(bmp);

            try
            {
                //blobCount.Text = blobGrabber.Apply(bmp).Size.ToString();
            }
            catch (Exception)
            {
            }


            /* Transcribe to original image */

            // extract red channel from the original image
            //IFilter extrachChannel = new ExtractChannel(RGB.R);
            //Bitmap redChannel = extrachChannel.Apply(curr_c);
            //  merge red channel with motion regions
            //Merge mergeFilter = new Merge();
            //mergeFilter.OverlayImage = bmp;
            //Bitmap tmp4 = mergeFilter.Apply(redChannel);
            // replace red channel in the original image
            //ReplaceChannel replaceChannel = new ReplaceChannel(RGB.R,tmp4);
            //curr_c = replaceChannel.Apply(curr_c);

            /* Background Update */
            //towardsFilter.OverlayImage = curr_gs;
            //back = towardsFilter.Apply(back);
            morphFilter.OverlayImage = curr_gs;
            back = morphFilter.Apply(back);


            return(bmp);
        }
        // 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();
            }
        }
Example #4
0
        public mCompositeMorph(Bitmap UnderlayBitmap, Bitmap OverlayBitmap, double Parameter)
        {
            BitmapUnder = new mSetFormat(UnderlayBitmap, mFilter.BitmapTypes.Rgb24bpp).ModifiedBitmap;
            BitmapOver  = new  mSetFormat(OverlayBitmap, mFilter.BitmapTypes.Rgb24bpp).ModifiedBitmap;

            ModifiedBitmap = BitmapUnder;

            Effect = new Morph(BitmapOver);
            Effect.SourcePercent = Parameter;

            ModifiedBitmap = Effect.Apply(BitmapUnder);
        }
Example #5
0
//--------------------------------------------------------------------
        private void process_motion()
        {
            IFilter filt = new GrayscaleY();
            currentFrame = filt.Apply(currentFrame);
            backgroundFrame = filt.Apply(backgroundFrame);
            FiltersSequence filters = new FiltersSequence();
            Morph filt_morph = new Morph();
            filt_morph.OverlayImage = currentFrame;
            Bitmap tmp = filt_morph.Apply(backgroundFrame);
            filters.Add(new Difference(tmp));
            filters.Add(new Threshold(15));
            Bitmap tmp1 = filters.Apply(currentFrame);
            alarm = CalculateWhitePixels(tmp1);
        }
        Bitmap BlendImages(Bitmap dayImage, Bitmap nightImage, double blendFactor)
        {
            if (Math.Abs(blendFactor) < 0.00001)
            {
                return((Bitmap)dayImage.Clone());
            }
            if (Math.Abs(blendFactor - 1.0) < 0.00001)
            {
                return((Bitmap)nightImage.Clone());
            }

            var filter = new Morph(nightImage)
            {
                SourcePercent = 1.0 - blendFactor,
            };

            return(filter.Apply(dayImage));
        }
Example #7
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);
        }