示例#1
0
        private Bitmap XXX(Bitmap bmpBefore, Bitmap bmpAfter)
        {
            var filter = new Grayscale(0.2125, 0.7154, 0.0721);

            bmpBefore = filter.Apply(bmpBefore);
            bmpAfter  = filter.Apply(bmpAfter);

            // create filters
            var     differenceFilter = new Difference();
            IFilter thresholdFilter  = new Threshold(15);

            // set backgroud frame as an overlay for difference filter
            differenceFilter.OverlayImage = bmpBefore;
            // apply the filters
            Bitmap  tmp1          = differenceFilter.Apply(bmpAfter);
            Bitmap  tmp2          = thresholdFilter.Apply(tmp1);
            IFilter erosionFilter = new Erosion();
            // apply the filter
            Bitmap tmp3 = erosionFilter.Apply(tmp2);

            IFilter pixellateFilter = new Pixellate();
            // apply the filter
            Bitmap tmp4 = pixellateFilter.Apply(tmp3);

            return(tmp4);
        }
示例#2
0
        private void PixellateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Pixellate rs = new Pixellate();
            Bitmap    s3 = rs.Apply(orImg);

            pictureBox5.Image = s3;
        }
示例#3
0
        public Bitmap ToPixellate(Bitmap Im)
        {
            AForge.Imaging.Filters.Pixellate Img = new Pixellate();
            Bitmap bmImage = AForge.Imaging.Image.Clone(new Bitmap(Im), PixelFormat.Format24bppRgb);

            return(Img.Apply(bmImage));
        }
        private void JpegLiveSource1LiveNotificationEvent(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                if (OnMainThread)
                {
                    LiveContentEventArgs args = e as LiveContentEventArgs;
                    if (args != null && args.LiveContent != null)
                    {
                        // UI thread is too busy - discard this frame from display
                        args.LiveContent.Dispose();
                    }
                    return;
                }
                OnMainThread = true;
                // Make sure we execute on the UI thread before updating UI Controls
                BeginInvoke(new EventHandler(JpegLiveSource1LiveNotificationEvent), new[] { sender, e });
            }
            else
            {
                LiveContentEventArgs args = e as LiveContentEventArgs;
                if (args != null)
                {
                    if (args.LiveContent != null)
                    {
                        // Display the received JPEG
                        //textBoxLength.Text = "" + args.LiveContent.Content.Length;

                        int width  = args.LiveContent.Width;
                        int height = args.LiveContent.Height;

                        MemoryStream ms = new MemoryStream(args.LiveContent.Content);
                        //Bitmap newBitmap = testBox();
                        Bitmap newBitmap = new Bitmap(ms);

                        if (referenceBitmap == null)
                        {
                            referenceBitmap = newBitmap;
                        }

                        textBoxResolution.Text = "" + width + "x" + height;

                        if (pictureBoxOriginal.Size.Width != 0 && pictureBoxOriginal.Size.Height != 0)
                        {
                            if ((newBitmap.Width != pictureBoxOriginal.Width || newBitmap.Height != pictureBoxOriginal.Height))
                            {
                                pictureBoxOriginal.Image = new Bitmap(newBitmap, pictureBoxOriginal.Size);
                            }
                            else
                            {
                                pictureBoxOriginal.Image = newBitmap;
                            }
                        }

                        textBoxDecodingStatus.Text = args.LiveContent.HardwareDecodingStatus;



                        ms.Close();
                        ms.Dispose();

                        _count++;
                        textBoxCount.Text = "" + _count;

                        args.LiveContent.Dispose();



                        /// Star processing frame
                        grayImage            = gfilter.Apply(newBitmap);
                        pictureBoxGray.Image = grayImage;

                        try
                        {
                            if (counter == 4000)
                            {
                                counter    = 0;
                                background = null;
                                analyticsImageProcessing.resetBackground();
                            }

                            if (background == null)
                            {
                                background = analyticsImageProcessing.GetBackGound(grayImage);

                                /// Show mensaje
                                Bitmap   bitmap = new Bitmap(320, 240);
                                Graphics g      = Graphics.FromImage(bitmap);
                                g.FillRectangle(System.Drawing.Brushes.Black, 0, 0, bitmap.Width, bitmap.Height);
                                g.DrawString("Processing Background...", new Font(FontFamily.GenericMonospace, 12), Brushes.White, new PointF(20, pictureBoxOriginal.Height / 2 - 20));
                                g.Dispose();
                                pictureBoxBackgound.Image = new Bitmap(bitmap, pictureBoxOriginal.Size);
                                bitmap.Dispose();
                            }
                            else
                            {
                                pictureBoxBackgound.Image = background;
                                background2 = gfilter.Apply(background);

                                Bitmap backgroundMask = analyticsImageProcessing.diff(grayImage, background2);
                                pictureBox1.Image = backgroundMask;


                                // create filter
                                //   Median filter = new Median();
                                // apply the filter
                                //   Bitmap backgroundMask2 = filter.Apply(backgroundMask);

                                //     pictureBox2.Image = backgroundMask2;

                                // create filter
                                Pixellate pxfilter = new Pixellate(20);
                                // apply the filter
                                Bitmap result = pxfilter.Apply(backgroundMask);
                                //      pictureBox3.Image = result;

                                // create filter
                                Threshold thfilter = new Threshold(1);
                                // apply the filter
                                Bitmap result2 = thfilter.Apply(result);

                                pictureBox4.Image = result2;

                                ApplyMask appmask = new ApplyMask(result2);
                                foreground = appmask.Apply(newBitmap);
                            }


                            /// PocessImage
                            if (foreground != null)
                            {
                                Blob[] blobs = analyticsImageProcessing.GetBlobs(foreground, blobCounter);
                                textBoxMetadata.Text = metadataHandler.SendMetadataBox(blobs, _jpegLiveSource.Width, _jpegLiveSource.Height);
                                PaintHeatMap(blobs);
                                pictureBoxHeatmap.Image = bitmapHeatMap;

                                /// Debug tool


                                if (blobs[0] != null && blobs.Length > 0)
                                {
                                    blobCounter.ExtractBlobsImage(foreground, blobs[0], false);
                                    pictureBoxBlob1.Image = blobs[0].Image.ToManagedImage();
                                    textBoxAreaBlob1.Text = blobs[0].Area.ToString();
                                    textBoxXBlob1.Text    = blobs[0].CenterOfGravity.X.ToString();
                                    textBoxYBlob1.Text    = blobs[0].CenterOfGravity.Y.ToString();
                                }
                                else
                                {
                                    pictureBoxBlob1.Image = null;
                                }

                                if (blobs[1] != null && blobs.Length > 1)
                                {
                                    blobCounter.ExtractBlobsImage(foreground, blobs[1], false);
                                    pictureBoxBlob2.Image = blobs[1].Image.ToManagedImage();
                                    textBoxAreaBlob2.Text = blobs[1].Area.ToString();
                                    textBoxXBlob2.Text    = blobs[1].CenterOfGravity.X.ToString();
                                    textBoxYBlob2.Text    = blobs[1].CenterOfGravity.Y.ToString();
                                }
                                else
                                {
                                    pictureBoxBlob2.Image = null;
                                }

                                if (blobs[2] != null && blobs.Length > 2)
                                {
                                    blobCounter.ExtractBlobsImage(foreground, blobs[2], false);
                                    pictureBoxBlob3.Image = blobs[2].Image.ToManagedImage();
                                    textBoxAreaBlob3.Text = blobs[2].Area.ToString();
                                    textBoxXBlob3.Text    = blobs[2].CenterOfGravity.X.ToString();
                                    textBoxYBlob3.Text    = blobs[2].CenterOfGravity.Y.ToString();
                                }
                                else
                                {
                                    pictureBoxBlob3.Image = null;
                                }

                                if (blobs[3] != null && blobs.Length > 3)
                                {
                                    blobCounter.ExtractBlobsImage(foreground, blobs[3], false);
                                    pictureBoxBlob4.Image = blobs[3].Image.ToManagedImage();
                                    textBoxAreaBlob4.Text = blobs[3].Area.ToString();
                                    textBoxXBlob4.Text    = blobs[3].CenterOfGravity.X.ToString();
                                    textBoxYBlob4.Text    = blobs[3].CenterOfGravity.Y.ToString();
                                }
                                else
                                {
                                    pictureBoxBlob4.Image = null;
                                }
                            }
                        }
                        catch (Exception r)
                        {
                            Console.WriteLine(r.Message);
                        }
                    }
                    else if (args.Exception != null)
                    {
                        // Handle any exceptions occurred inside toolkit or on the communication to the VMS

                        Bitmap   bitmap = new Bitmap(320, 240);
                        Graphics g      = Graphics.FromImage(bitmap);
                        g.FillRectangle(System.Drawing.Brushes.Black, 0, 0, bitmap.Width, bitmap.Height);
                        g.DrawString("Connection lost to server ...", new Font(FontFamily.GenericMonospace, 12), Brushes.White, new PointF(20, pictureBoxOriginal.Height / 2 - 20));
                        g.Dispose();
                        pictureBoxOriginal.Image = new Bitmap(bitmap, pictureBoxOriginal.Size);
                        bitmap.Dispose();
                    }
                }
                OnMainThread = false;
            }
        }
示例#5
0
        public static Bitmap ToPixellate(this Bitmap iBitmap, int pixelSize)
        {
            Pixellate filter = new Pixellate(pixelSize);

            return(filter.Apply(iBitmap));
        }
示例#6
0
        public static Bitmap ToPixalation(this Bitmap bitmap)
        {
            var pixellateFilter = new Pixellate();

            return(pixellateFilter.Apply(AForge.Imaging.Image.Clone(bitmap, PixelFormat.Format24bppRgb)));
        }