Exemplo n.º 1
0
        public Bitmap ToSaturationCorrection(Bitmap Im)
        {
            AForge.Imaging.Filters.SaturationCorrection Img = new SaturationCorrection();
            Bitmap bmImage = AForge.Imaging.Image.Clone(new Bitmap(Im), PixelFormat.Format24bppRgb);

            return(Img.Apply(bmImage));
        }
Exemplo n.º 2
0
        private void videoNewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap               bitmap           = (Bitmap)eventArgs.Frame.Clone();
            Threshold            thresholdFilter  = new Threshold(120);
            Grayscale            grayscaleFilter  = new Grayscale(0.2, 0.7, 0.07);
            BrightnessCorrection brightnessFilter = new BrightnessCorrection(brightnessVal);
            ContrastCorrection   contrastFilter   = new ContrastCorrection(contrastVal);
            SaturationCorrection saturationFilter = new SaturationCorrection(saturationVal);

            bitmap = brightnessFilter.Apply((Bitmap)bitmap.Clone());
            bitmap = contrastFilter.Apply((Bitmap)bitmap.Clone());
            bitmap = saturationFilter.Apply((Bitmap)bitmap.Clone());

            if (isGray)
            {
                bitmap = grayscaleFilter.Apply((Bitmap)bitmap.Clone());
            }
            if (isBW)
            {
                bitmap = grayscaleFilter.Apply((Bitmap)bitmap.Clone());
                bitmap = thresholdFilter.Apply(bitmap);
            }

            currentFrame = (Bitmap)bitmap.Clone();
            if (fileWriter != null)
            {
                fileWriter.WriteVideoFrame((Bitmap)bitmap.Clone());
            }
        }
Exemplo n.º 3
0
 private static Bitmap CreateGrayscale(Bitmap image)
 {
     
     const int size = 512;
     float scale = Math.Min(size / (float)image.Width, size / (float)image.Height);
     ResizeBicubic resize = new ResizeBicubic((int)(image.Width*scale), (int)(image.Height*scale));
     
     ImageStatistics stat = new ImageStatistics( image );
     LevelsLinear levelsLinear = new LevelsLinear
     {
         Output = new IntRange(0, 255),
         InRed = stat.Red.GetRange(.95),
         InBlue = stat.Blue.GetRange(.95),
         InGreen = stat.Green.GetRange(.95)
     };
     SaturationCorrection sc = new SaturationCorrection(-1);
     Bitmap square = new Bitmap(size, size);
     using(Bitmap resized = resize.Apply(sc.Apply(levelsLinear.Apply(image)).MakeGrayscale()))
     using (Graphics g = Graphics.FromImage(square))
     {
         g.DrawImage(resized, new Point((size-resized.Width) / 2 ,0));
     }
     
     return square;
 }
        public Bitmap GetNewFrame(Bitmap source)
        {
            var newFrame = saturationCorrection.Apply(source);

            source.Dispose();
            return(newFrame);
        }
Exemplo n.º 5
0
        private void CameraOne_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            if (isRecording1)
            {
                using (var bitmap = (Bitmap)eventArgs.Frame.Clone())
                {
                    if (firstFrameTime != null)
                    {
                        writer.WriteVideoFrame(bitmap, DateTime.Now - firstFrameTime.Value);
                    }
                    else
                    {
                        writer.WriteVideoFrame(bitmap);
                        firstFrameTime = DateTime.Now;
                    }
                }
            }

            Bitmap bitmap1 = (Bitmap)eventArgs.Frame.Clone();
            BrightnessCorrection br = new BrightnessCorrection(brightess1);
            ContrastCorrection cr = new ContrastCorrection(contrast1);
            SaturationCorrection sr = new SaturationCorrection(saturation1);
            bitmap1 = br.Apply((Bitmap)bitmap1.Clone());
            bitmap1 = cr.Apply((Bitmap)bitmap1.Clone());
            bitmap1 = sr.Apply((Bitmap)bitmap1.Clone());
            try
            { 
                pbCam1.Image = bitmap1;
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine("A problem with image loading occured! You may want to close other apps using your camera!");
            }
        }
        /// <summary>
        /// Applies filter to bitmap.
        /// </summary>
        /// <param name="image">Bitmap</param>
        /// <returns>Bitmap</returns>
        public Bitmap Apply(Bitmap image)
        {
            Bitmap clone = (Bitmap)image.Clone();

            if (sc.Saturation != 0)
            {
                sc.Apply(clone);
            }

            if (ce.Contrast != 0)
            {
                ce.Apply(clone);
            }

            if (this.bc.Brightness != 0)
            {
                bc.Apply(clone);
            }

            if (this.ec.Offset != 0)
            {
                ec.Apply(clone);
            }

            if (this.gc.Gamma != 1.0)
            {
                gc.Apply(clone);
            }

            return(clone);
        }
        private void reminiscentFilterButton_Click(object sender, EventArgs e)
        {
            SaturationCorrection filter = new SaturationCorrection((float)-0.2);

            processedImage            = filter.Apply(originImage);
            processedPictureBox.Image = processedImage;
        }
Exemplo n.º 8
0
        public static Bitmap SaturationCorrection(Bitmap Imagem)
        {
            SaturationCorrection filter = new SaturationCorrection();

            Imagem = Imagem.Clone(new Rectangle(0, 0, Imagem.Width, Imagem.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            Imagem = filter.Apply(Imagem);
            return(Imagem);
        }
 private void streamedFrame(object sender, NewFrameEventArgs eventArgs)
 {
     try
     {
         if (_isRecording)
         {
             recordVideo(eventArgs);
         }
         using (var bitmap = (Bitmap)eventArgs.Frame.Clone())
         {
             if (_isMonochromatic)
             {
                 using (var isgrayscaledBitmap = Grayscale.CommonAlgorithms.BT709.Apply(bitmap))
                     using (var monochromaticcBitmap = new Threshold(100).Apply(isgrayscaledBitmap))
                     {
                         bitmapImage = monochromaticcBitmap.ToBitmapImage();
                     }
             }
             else if (_isGrayScaled)
             {
                 using (var isGrayscaledBitmap = Grayscale.CommonAlgorithms.BT709.Apply(bitmap))
                 {
                     bitmapImage = isGrayscaledBitmap.ToBitmapImage();
                 }
             }
             else if (contrast != 0)
             {
                 ContrastCorrection filter = new ContrastCorrection((int)contrast);
                 using (var contrastBitMap = filter.Apply(bitmap))
                     bitmapImage = contrastBitMap.ToBitmapImage();
             }
             else if (brightness != 0)
             {
                 BrightnessCorrection bfilter = new BrightnessCorrection((int)brightness);
                 using (var brightnessBitMap = bfilter.Apply(bitmap))
                     bitmapImage = brightnessBitMap.ToBitmapImage();
             }
             else if (saturation != 0)
             {
                 SaturationCorrection bfilter = new SaturationCorrection((int)brightness);
                 using (var saturationBitMap = bfilter.Apply(bitmap))
                     bitmapImage = saturationBitMap.ToBitmapImage();
             }
             else
             {
                 bitmapImage = bitmap.ToBitmapImage();
             }
         }
         bitmapImage.Freeze();
         Dispatcher.BeginInvoke(new ThreadStart(delegate { VideoSource.Source = bitmapImage; }));
         motionDetect(eventArgs);
     }
     catch (Exception e)
     {
         MessageBox.Show("Error:\n", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         StopCamera();
     }
 }
Exemplo n.º 10
0
        private void Saturation_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            SaturationLabel.Content = (int)(Saturation.Value * 100);
            saturation = (float)Saturation.Value;

            if (mainPhoto != null)
            {
                sc = new SaturationCorrection(saturation);
                System.Drawing.Bitmap tmp = sc.Apply((System.Drawing.Bitmap)mainPhoto.Clone());
                //BitmapImage tmpBmpIs = ToBitmapImage(tmp);

                Photography.Source = ToBitmapImage(tmp);

                UpdateHistograms(tmp);
                UpdateChannelPreviews(tmp);
            }
        }
        private void CameraTwo_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap bitmap2          = (Bitmap)eventArgs.Frame.Clone();
            BrightnessCorrection br = new BrightnessCorrection(brightess1);
            ContrastCorrection   cr = new ContrastCorrection(contrast1);
            SaturationCorrection sr = new SaturationCorrection(saturation1);

            bitmap2 = br.Apply((Bitmap)bitmap2.Clone());
            bitmap2 = cr.Apply((Bitmap)bitmap2.Clone());
            bitmap2 = sr.Apply((Bitmap)bitmap2.Clone());

            pbCam2.Image = bitmap2;

            if (isRecording2)
            {
                writer.WriteVideoFrame(bitmap2);
            }
        }
Exemplo n.º 12
0
        /// <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);
            int C = 0;

            DA.GetData(1, ref C);
            int B = 0;

            DA.GetData(2, ref B);
            double S = 0;

            DA.GetData(3, ref S);

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

            Bitmap filteredImage = sourceImage;

            if (C >= 0)
            {
                IFilter myFilterContrast = new ContrastCorrection(C);
                filteredImage = myFilterContrast.Apply(sourceImage);
            }
            else
            {
                IFilter myFilterContrast = new ContrastStretch();
                filteredImage = myFilterContrast.Apply(sourceImage);
            }

            IFilter myFilterBrightness = new BrightnessCorrection(B);

            filteredImage = myFilterBrightness.Apply(filteredImage);

            IFilter mySaturationFilter = new SaturationCorrection(Convert.ToSingle(S));

            filteredImage = mySaturationFilter.Apply(filteredImage);



            DA.SetData(0, filteredImage);
        }
Exemplo n.º 13
0
Arquivo: UsbCam.cs Projeto: Krl1/UP_L
        private void DisplayCapturedPicture(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap bitmap = new Bitmap(eventArgs.Frame, new Size(cameraPictureBox.Width, cameraPictureBox.Height));
            BrightnessCorrection brightnessCorrection = new BrightnessCorrection(Brightness);
            ContrastCorrection   contrastCorrection   = new ContrastCorrection(Contrast);
            SaturationCorrection saturationCorrection = new SaturationCorrection(Saturation * 0.1f);
            HueModifier          hueModifier          = new HueModifier(Hue);

            bitmap = brightnessCorrection.Apply((Bitmap)bitmap.Clone());
            bitmap = contrastCorrection.Apply((Bitmap)bitmap.Clone());
            bitmap = saturationCorrection.Apply((Bitmap)bitmap.Clone());
            bitmap = hueModifier.Apply((Bitmap)bitmap.Clone());

            if (connectedCameraIsRecording)
            {
                videoWriter.WriteVideoFrame(bitmap);
            }

            cameraPictureBox.Image = bitmap;
        }
Exemplo n.º 14
0
        private void recordEventHandler(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap bitmap           = (Bitmap)eventArgs.Frame.Clone();
            BrightnessCorrection br = new BrightnessCorrection(brightess);
            ContrastCorrection   cr = new ContrastCorrection(contrast);
            SaturationCorrection sr = new SaturationCorrection(saturation);

            bitmap = br.Apply((Bitmap)bitmap.Clone());
            bitmap = cr.Apply((Bitmap)bitmap.Clone());
            bitmap = sr.Apply((Bitmap)bitmap.Clone());

            if (isRecording)
            {
                writer.WriteVideoFrame(bitmap);
            }
            else
            {
                oldBitmap  = bitmap;
                view.Image = bitmap;
            }
        }
Exemplo n.º 15
0
        private void CameraTwo_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap bitmap2 = (Bitmap)eventArgs.Frame.Clone();
            BrightnessCorrection br = new BrightnessCorrection(brightess2);
            ContrastCorrection cr = new ContrastCorrection(contrast2);
            SaturationCorrection sr = new SaturationCorrection(saturation2);
            bitmap2 = br.Apply((Bitmap)bitmap2.Clone());
            bitmap2 = cr.Apply((Bitmap)bitmap2.Clone());
            bitmap2 = sr.Apply((Bitmap)bitmap2.Clone());

            try
            {
                pbCam2.Image = bitmap2;
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine("A problem with image loading occured! You may want to close other apps using your camera!");
            }

            if (isRecording2)
            {
                writer.WriteVideoFrame(bitmap2);
            }
        }
Exemplo n.º 16
0
        private void VideoCaptureDevice_NewFrame(object sender, NewFrameEventArgs e)
        {
            Bitmap image = (Bitmap)e.Frame.Clone();

            brightness = new BrightnessCorrection(jasnosc);
            image      = brightness.Apply((Bitmap)image.Clone());

            saturation = new SaturationCorrection(nasycenie);
            image      = saturation.Apply((Bitmap)image.Clone());

            contrast = new ContrastCorrection(kontrast);
            image    = contrast.Apply((Bitmap)image.Clone());

            if (recording == true)
            {
                writer.WriteVideoFrame(image);
            }

            if (detecting)
            {
                if (motionDetector.ProcessFrame(image) > 0.05)
                {
                    textBox4.Text     = "Wykryto ruch";
                    pictureBox1.Image = image;
                }
                else
                {
                    textBox4.Text     = "Brak ruchu";
                    pictureBox1.Image = image;
                }
            }
            else
            {
                pictureBox1.Image = image;
            }
        }
Exemplo n.º 17
0
        private void cBFilters_SelectedIndexChanged(object sender, EventArgs e)
        {
            Bitmap pictureTransform = (Bitmap)pbChoose.Image;

            if ((string)cBFilters.SelectedItem == "HSL_Filter")
            {
                AForge.Imaging.Filters.SaturationCorrection filter = new SaturationCorrection(0.1);
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            if ((string)cBFilters.SelectedItem == "Mediana")
            {
                AForge.Imaging.Filters.Median filter = new Median();
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            /*if ((string)cBFilters.SelectedItem == "Fourier_Transformation")
             * {
             * Complex[] dst = new Complex[n];
             *
             *  AForge.Math.FourierTransform filter = AForge.Math.FourierTransform.DFT();// .FromBitmap(pictureTransform);
             *  Bitmap newImage = filter.Apply();
             *  pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
             *  pBNew.Image = newImage;
             * }*/

            if ((string)cBFilters.SelectedItem == "Binarization")
            {
                pictureTransform = Grayscale.CommonAlgorithms.BT709.Apply(pictureTransform);
                Threshold threshold = new Threshold(127);
                threshold.ApplyInPlace(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = pictureTransform;
            }

            if ((string)cBFilters.SelectedItem == "Grayscale")
            {
                AForge.Imaging.Filters.Grayscale filter = new AForge.Imaging.Filters.Grayscale(0.2125, 0.7154, 0.0721);
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            if ((string)cBFilters.SelectedItem == "FillHoles")
            {
                pictureTransform = Grayscale.CommonAlgorithms.BT709.Apply(pictureTransform);
                Threshold threshold = new Threshold(127);
                threshold.ApplyInPlace(pictureTransform);
                AForge.Imaging.Filters.FillHoles filter = new AForge.Imaging.Filters.FillHoles();
                filter.MaxHoleHeight        = 5;
                filter.MaxHoleWidth         = 15;
                filter.CoupledSizeFiltering = false;
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            if ((string)cBFilters.SelectedItem == "Opening")
            {
                AForge.Imaging.Filters.Opening filter = new AForge.Imaging.Filters.Opening();
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            if ((string)cBFilters.SelectedItem == "Closing")
            {
                AForge.Imaging.Filters.Closing filter = new AForge.Imaging.Filters.Closing();
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            if ((string)cBFilters.SelectedItem == "Erosion")
            {
                AForge.Imaging.Filters.Erosion filter = new AForge.Imaging.Filters.Erosion();
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            if ((string)cBFilters.SelectedItem == "Dilatation")
            {
                AForge.Imaging.Filters.Dilatation filter = new AForge.Imaging.Filters.Dilatation();
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            if ((string)cBFilters.SelectedItem == "Edges")
            {
                AForge.Imaging.Filters.Edges filter = new AForge.Imaging.Filters.Edges();
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }
        }
Exemplo n.º 18
0
 public Bitmap Apply(Bitmap input)
 {
     _filter.AdjustValue = _param;
     return(_filter.Apply(input));
 }