Example #1
0
        public Bitmap ToYCbCrExtractChannel(Bitmap Im)
        {
            AForge.Imaging.Filters.YCbCrExtractChannel Img = new YCbCrExtractChannel();
            Bitmap bmImage = AForge.Imaging.Image.Clone(new Bitmap(Im), PixelFormat.Format24bppRgb);

            return(Img.Apply(bmImage));
        }
Example #2
0
        public mFilterYCbCrChannel(wDomain Luminance, wDomain Blue, wDomain Red)
        {
            Y  = Luminance;
            Cb = Blue;
            Cr = Red;

            BitmapType = mFilter.BitmapTypes.None;

            Effect = new YCbCrExtractChannel();



            filter = Effect;
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Bitmap sourceImage = null;

            DA.GetData(0, ref sourceImage);

            sourceImage = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            YCbCrExtractChannel myFilter = new YCbCrExtractChannel(YCbCr.YIndex);

            DA.SetData(0, myFilter.Apply(sourceImage));

            myFilter = new YCbCrExtractChannel(YCbCr.CbIndex);
            DA.SetData(1, myFilter.Apply(sourceImage));

            myFilter = new YCbCrExtractChannel(YCbCr.CrIndex);
            DA.SetData(2, myFilter.Apply(sourceImage));
        }
Example #4
0
        public mSwapRGB(Bitmap BaseBitmap, int A, int R, int G, int B)
        {
            ExtractChannel cR = new ExtractChannel(RGB.R);
            ExtractChannel cG = new ExtractChannel(RGB.G);
            ExtractChannel cB = new ExtractChannel(RGB.B);

            ExtractChannel cA = new ExtractChannel(RGB.A);

            YCbCrExtractChannel cL = new YCbCrExtractChannel(YCbCr.YIndex);

            List <Bitmap> maps = new List <Bitmap>();

            Bitmap BmpA = new Bitmap(BaseBitmap.Width, BaseBitmap.Height, PixelFormat.Format16bppGrayScale);
            Bitmap BmpR = new Bitmap(BaseBitmap.Width, BaseBitmap.Height, PixelFormat.Format16bppGrayScale);
            Bitmap BmpG = new Bitmap(BaseBitmap.Width, BaseBitmap.Height, PixelFormat.Format16bppGrayScale);
            Bitmap BmpB = new Bitmap(BaseBitmap.Width, BaseBitmap.Height, PixelFormat.Format16bppGrayScale);
            Bitmap BmpL = new Bitmap(BaseBitmap.Width, BaseBitmap.Height, PixelFormat.Format16bppGrayScale);

            BmpA = cA.Apply(new Bitmap(BaseBitmap));
            BmpR = cR.Apply(new Bitmap(BaseBitmap));
            BmpG = cG.Apply(new Bitmap(BaseBitmap));
            BmpB = cB.Apply(new Bitmap(BaseBitmap));
            BmpL = cL.Apply(new Bitmap(BaseBitmap));

            maps.Add(BmpA);
            maps.Add(BmpR);
            maps.Add(BmpG);
            maps.Add(BmpB);
            maps.Add(BmpL);

            Bitmap bmp = new Bitmap(BaseBitmap.Width, BaseBitmap.Height, PixelFormat.Format32bppArgb);

            bmp.MakeTransparent();

            bmp = new ReplaceChannel(RGB.A, maps[A]).Apply(bmp);
            bmp = new ReplaceChannel(RGB.R, maps[R]).Apply(bmp);
            bmp = new ReplaceChannel(RGB.G, maps[G]).Apply(bmp);
            bmp = new ReplaceChannel(RGB.B, maps[B]).Apply(bmp);

            ModifiedBitmap = new Bitmap(bmp);
        }
Example #5
0
        public void  video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap globaly, globalcb, globalcr, yChannel, cbChannel, crChannel;


            Bitmap img      = (Bitmap)eventArgs.Frame.Clone();
            Bitmap imgsmoke = (Bitmap)eventArgs.Frame.Clone();

            // create filter
            //Erosion filterer = new Erosion();
            // apply the filter
            //filterer.Apply(img);



            globaly = (Bitmap)eventArgs.Frame.Clone(); //bitmap image to store Y extract

            // create filter
            BrightnessCorrection filterb1 = new BrightnessCorrection(-0.3);

            // apply the filter
            filterb1.ApplyInPlace(globaly);

            globalcb = (Bitmap)eventArgs.Frame.Clone(); //bitmap image to store Cb extract

            // create filter
            BrightnessCorrection filterb2 = new BrightnessCorrection(-0.3);

            // apply the filter
            filterb2.ApplyInPlace(globalcb);

            globalcr = (Bitmap)eventArgs.Frame.Clone(); //bitmap image to store Cr extract
            //globaly.Height = globalcb.Height = globalcr.Height = 25;
            //globaly.Width = globalcb.Width = globalcr.Width = 50;


            YCbCrExtractChannel filtery = new YCbCrExtractChannel(YCbCr.YIndex);

            // apply the filter and extract Y channel
            globaly.Clone();
            yChannel = filtery.Apply(globaly);


            yChannel.Clone();
            Bitmap y2Channel = (Bitmap)yChannel.Clone();



            YCbCrExtractChannel filtercb = new YCbCrExtractChannel(YCbCr.CbIndex);

            // apply the filter and extract Cb channel
            globalcb.Clone();
            cbChannel = filtercb.Apply(globalcb);


            cbChannel.Clone();
            Bitmap cb2Channel = (Bitmap)cbChannel.Clone();



            YCbCrExtractChannel filtercr = new YCbCrExtractChannel(YCbCr.CrIndex);

            // apply the filter and extract Cr channel
            globalcr.Clone();
            crChannel = filtercr.Apply(globalcr);

            crChannel.Clone();
            Bitmap cr2Channel = (Bitmap)crChannel.Clone();



            //fire pixel processing
            BitmapData subdata2 = cb2Channel.LockBits(new Rectangle(0, 0, cb2Channel.Width, cb2Channel.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
            BitmapData subdata1 = y2Channel.LockBits(new Rectangle(0, 0, y2Channel.Width, y2Channel.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
            // BitmapData subdata3 = cr2Channel.LockBits(new Rectangle(0, 0, cr2Channel.Width, cr2Channel.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);

            int stride1 = subdata2.Stride;
            int stride0 = subdata1.Stride;

            //int stride2 = subdata3.Stride;

            System.IntPtr Scan01 = subdata2.Scan0;
            System.IntPtr Scan02 = subdata1.Scan0;
            //System.IntPtr Scan2 = subdata3.Scan0;


            unsafe
            {
                byte *q = (byte *)(void *)Scan01;
                byte *p = (byte *)(void *)Scan02;

                //byte* r = (byte*)(void*)Scan2;


                int cnt = 0;
                //int nOffset1 = stride1 - cbChannel.Width * 3;



                for (int y = 0; y < cbChannel.Height; y++)    //scanning pixels horizontally
                {
                    for (int x = 0; x < cbChannel.Width; x++) //scanning pixels vertically
                    {
                        int x1 = int.Parse(p[0].ToString());  //y
                        int y1 = int.Parse(q[0].ToString());  //cb
                        //int z1 = int.Parse(r[0].ToString());//cr
                        int z1 = x1 - y1;

                        if (z1 > 125) //defining condition for difference between y and cb channel for a fire pixel
                        {
                            cnt++;
                        }
                        p += 1;
                        //r +=1;
                        q += 1;
                    }

                    //q += nOffset1;
                }


                if (cnt > 25)
                {
                    Form frm = new fire_alert();
                    frm.ShowDialog();
                }

                cb2Channel.UnlockBits(subdata2);
                y2Channel.UnlockBits(subdata1);
            }
            pictureBox1.Image = img; //picturebox stores cloned image of frame
            pictureBox2.Image = yChannel;
            pictureBox3.Image = cbChannel;
            pictureBox4.Image = crChannel;


            ////smoke pixel processing

            ////creating instance of color filtering for detectiong of laser light
            //ColorFiltering colr_filter = new ColorFiltering();

            ////setting the color filter properties colour values for smoke
            //colr_filter.Red.Min = 126  ;
            //colr_filter.Red.Max = 156;

            //colr_filter.Green.Min = 155;
            //colr_filter.Green.Max = 179;

            //colr_filter.Blue.Min = 179;
            //colr_filter.Blue.Max = 211;

            ////apply filter and storing filtered image in another bitmap
            //imgsmoke = colr_filter.Apply(imgsmoke);

            ////filter to convert RGB image to 8bpp gray scale for image processing
            //IFilter gray_filter = new GrayscaleBT709();
            //imgsmoke = gray_filter.Apply(imgsmoke);

            ////thrsholding a image
            //Threshold th_filter = new Threshold(40);
            //th_filter.ApplyInPlace(imgsmoke);

            ////erosion filter to filter out small unwanted pixels
            //Erosion3x3 err_filter = new Erosion3x3();
            //err_filter.ApplyInPlace(imgsmoke);

            ////count blob
            ////initialize a blob counting object to count blobs in image
            //BlobCounter bc = new BlobCounter();
            ////arrange blobs by area
            //bc.ObjectsOrder = ObjectsOrder.Area;
            //bc.MinHeight = 4;
            //bc.MinWidth = 5;

            ////process image for blobs
            //bc.ProcessImage(imgsmoke);

            ////MessageBox.Show(bc.ObjectsCount.ToString());
            //if (bc.ObjectsCount > 10)
            //{
            //    //Form frm1 = new smoke_alert();
            //    //frm1.ShowDialog();
            //}

            ////pictureBox5.Image = imgsmoke;
        }
        public mExtractYCbCrChannel(short Channel)
        {
            BitmapType = mFilter.BitmapTypes.None;

            filter = new YCbCrExtractChannel(Channel);
        }
Example #7
0
        public void  video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap globaly, globalcb, globalcr, yChannel, cbChannel, crChannel;


            Bitmap img = (Bitmap)eventArgs.Frame.Clone();

            // Bitmap imgsmoke = (Bitmap)eventArgs.Frame.Clone();
            // create filter
            //Erosion filterer = new Erosion();
            // apply the filter
            //filterer.Apply(img);



            globaly = (Bitmap)eventArgs.Frame.Clone(); //bitmap image to store Y extract

            // create filter
            BrightnessCorrection filterb1 = new BrightnessCorrection(-0.5);

            // apply the filter
            filterb1.ApplyInPlace(globaly);

            globalcb = (Bitmap)eventArgs.Frame.Clone(); //bitmap image to store Cb extract

            // create filter
            BrightnessCorrection filterb2 = new BrightnessCorrection(-0.5);

            // apply the filter
            filterb2.ApplyInPlace(globalcb);

            globalcr = (Bitmap)eventArgs.Frame.Clone(); //bitmap image to store Cr extract
            //globaly.Height = globalcb.Height = globalcr.Height = 25;
            //globaly.Width = globalcb.Width = globalcr.Width = 50;


            YCbCrExtractChannel filtery = new YCbCrExtractChannel(YCbCr.YIndex);

            // apply the filter and extract Y channel
            //globaly.Clone();
            yChannel = filtery.Apply(globaly);


            yChannel.Clone();
            Bitmap y2Channel = (Bitmap)yChannel.Clone();



            YCbCrExtractChannel filtercb = new YCbCrExtractChannel(YCbCr.CbIndex);

            // apply the filter and extract Cb channel
            globalcb.Clone();
            cbChannel = filtercb.Apply(globalcb);


            cbChannel.Clone();
            Bitmap cb2Channel = (Bitmap)cbChannel.Clone();



            YCbCrExtractChannel filtercr = new YCbCrExtractChannel(YCbCr.CrIndex);

            // apply the filter and extract Cr channel
            globalcr.Clone();
            crChannel = filtercr.Apply(globalcr);

            crChannel.Clone();
            Bitmap cr2Channel = (Bitmap)crChannel.Clone();



            //fire pixel processing
            BitmapData subdata2 = cb2Channel.LockBits(new Rectangle(0, 0, cb2Channel.Width, cb2Channel.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
            BitmapData subdata1 = y2Channel.LockBits(new Rectangle(0, 0, y2Channel.Width, y2Channel.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
            // BitmapData subdata3 = cr2Channel.LockBits(new Rectangle(0, 0, cr2Channel.Width, cr2Channel.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);

            int stride1 = subdata2.Stride;
            int stride0 = subdata1.Stride;

            //int stride2 = subdata3.Stride;

            System.IntPtr Scan01 = subdata2.Scan0;
            System.IntPtr Scan02 = subdata1.Scan0;
            //System.IntPtr Scan2 = subdata3.Scan0;


            unsafe
            {
                byte *q = (byte *)(void *)Scan01;
                byte *p = (byte *)(void *)Scan02;

                //byte* r = (byte*)(void*)Scan2;


                int cnt = 0;
                //int nOffset1 = stride1 - cbChannel.Width * 3;



                for (int y = 0; y < cbChannel.Height; y++)    //scanning pixels horizontally
                {
                    for (int x = 0; x < cbChannel.Width; x++) //scanning pixels vertically
                    {
                        int x1 = int.Parse(p[0].ToString());  //y
                        int y1 = int.Parse(q[0].ToString());  //cb
                        //int z1 = int.Parse(r[0].ToString());//cr
                        int z1 = x1 - y1;

                        if (z1 > 125) //defining condition for difference between y and cb channel for a fire pixel of ligter flame (trial & error)
                        {
                            cnt++;
                        }
                        p += 1;
                        //r +=1;
                        q += 1;
                    }

                    //q += nOffset1;
                }


                if (cnt > 125)
                {
                    //SoundPlayer simpleSound = new SoundPlayer(@"C:\voice.wav");
                    //simpleSound.Play();

                    SoundPlayer simpleSound = new SoundPlayer(@"D:\fire detected_MAIN - Copy\fire detected_MAIN - Copy\Resources\\fewsec.wav");
                    //SoundPlayer simpleSound = new SoundPlayer(@"F:\fire detected_MAIN - Copy\fire detected_MAIN - Copy\\Resources\\");
                    simpleSound.Play();
                    if (cnt < 150)
                    {
                        setLabel1TextSafe("Fire Detected!!! \n Low Intesity");
                    }
                    else if (cnt > 150 && cnt < 300)
                    {
                        setLabel1TextSafe("Fire Detected!!! \n Medium intesity");
                    }
                    else if (cnt > 300 && cnt <= 500)
                    {
                        setLabel1TextSafe("Fire Detected!!! \n High intesity");
                    }
                }
                else
                {
                    setLabel1TextSafe(" ");
                }

                cb2Channel.UnlockBits(subdata2);
                y2Channel.UnlockBits(subdata1);
            }
            pictureBox1.Image = img; //picturebox stores cloned image of frame
            pictureBox2.Image = yChannel;
            pictureBox3.Image = cbChannel;
            pictureBox4.Image = crChannel;
        }