/// <summary>
        /// 根据图片的纵横灰度情况截取图片
        /// 使用Aforge类库
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public static Rectangle GetByGrayPoint(Bitmap image)
        {
            //灰度化
            Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
            // apply the filter
            var grayImg = g.Apply(image);
            //二值化
            var threshold = new Threshold();

            threshold.ThresholdValue = 80;
            var thresholdImage = threshold.Apply(grayImg);

            //找出纵横灰度值
            HorizontalIntensityStatistics hs = new HorizontalIntensityStatistics(thresholdImage);
            VerticalIntensityStatistics   vs = new VerticalIntensityStatistics(thresholdImage);
            var vThreshold = (image.Height / 4) * 255;
            var hThreshold = (image.Width / 4) * 255;
            var hGrays     = hs.Gray.Values.ToList();
            var vGrays     = vs.Gray.Values.ToList();
            var hmin       = FindPaperBorder(hGrays, true, hThreshold, 0);
            var hmax       = FindPaperBorder(hGrays, false, hThreshold, 0);
            var vmin       = FindPaperBorder(vGrays, true, vThreshold, 0);;
            var vmax       = FindPaperBorder(vGrays, false, vThreshold, 0);

            return(new Rectangle(hmin, vmin, hmax - hmin, vmax - vmin));
        }
Ejemplo n.º 2
0
        public static IAutoVoiLutApplicator Create(IPresentationImage image)
        {
            if (Grayscale.CanCreateFrom(image))
            {
                return new Grayscale {
                           Image = image
                }
            }
            ;

            if (Color.CanCreateFrom(image))
            {
                return new Color {
                           Image = image
                }
            }
            ;

            if (Other.CanCreateFrom(image))
            {
                return new Other {
                           Image = image
                }
            }
            ;

            return(null);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public IScanImage Scan(ISource source, ScannerOptions options)
        {
            var image = new Bitmap(source.Take());

            // create grayscale filter (BT709)
            var filter     = new Grayscale(0.2125, 0.7154, 0.0721);
            var mBinarized = filter.Apply(image);

            // Binarize Picture.
            var bin = new Threshold(options.Threshold);

            bin.ApplyInPlace(mBinarized);

            // create filter
            var inv = new Invert();

            inv.ApplyInPlace(mBinarized);

            // create an instance of blob counter algorithm
            var bc = new BlobCounter {
                ObjectsOrder = ObjectsOrder.XY
            };

            bc.ProcessImage(mBinarized);
            var blobsRect = bc.GetObjectsRectangles();

            var b = Order(blobsRect);

            return(new ScanImage(image, b));
        }
Ejemplo n.º 5
0
        private void GrayscaleImg(ref Bitmap frame, bool R, bool G, bool B)
        {
            // create filter
            Bitmap fr;

            if (!(!R && !G && !B) && (!R || !G || !B))
            {
                EuclideanColorFiltering filter = new EuclideanColorFiltering();
                // set center colol and radius
                filter.CenterColor = new AForge.Imaging.RGB(Color.FromArgb(30, 200, 30));
                filter.Radius      = 150;
                // apply the filter
                filter.ApplyInPlace(frame);
                Grayscale toGrFilter = new Grayscale(R ? 0.3 : 0, G ? .9 : 0, B ? 0.3 : 0);
                fr = toGrFilter.Apply(frame);
                GrayscaleToRGB toColFilter = new GrayscaleToRGB();
                frame = toColFilter.Apply(fr);
            }
            else
            {
                frame = Grayscale.CommonAlgorithms.RMY.Apply(frame);
                GrayscaleToRGB toColFilter = new GrayscaleToRGB();
                frame = toColFilter.Apply(frame);
            }
        }
Ejemplo n.º 6
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());
            }
        }
Ejemplo n.º 7
0
        void CannyToolStripMenuItemClick(object sender, EventArgs e)
        {
            //jika gambar kosong/null maka akan mengembalikan nilai kosong/null
            if (gambar == null)
            {
                return;
            }
            //clone variable gambar ke variable gambar2 dan menginisiasi class Rectangle
            //dan menerapkan format pixel 24bppRgb
            gambar2 = gambar.Clone(new Rectangle(0, 0, gambar.Width, gambar.Height),
                                   System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            //convert ke grayscale terlebih dahulu lalu aplikasikan filter Canny.
            //inisiasi filter grayscale disertai argumen
            Grayscale grayscaleF = new Grayscale(0.2125, 0.7154, 0.0721);

            //aplikasikan filter grayscale ke gambar2
            gambar2 = grayscaleF.Apply(gambar2);
            //inisiasi filter Canny
            CannyEdgeDetector cannyEdgeDetector = new CannyEdgeDetector();

            //aplikasikan filter pada gambar2
            cannyEdgeDetector.ApplyInPlace(gambar2);
            //tampilkan pada picturebox2
            pictureBox2.Image = gambar2;
        }
Ejemplo n.º 8
0
        private void button2_Click(object sender, EventArgs e)
        {
            Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);

            img2 = filter.Apply(img1);
            pictureBox2.Image = img2;
        }
Ejemplo n.º 9
0
        private void timerSampleMaker_Tick(object sender, EventArgs e)
        {
            if (_sourceImage != null)
            {
                try
                {
                    // Loading some file
                    Bitmap _sample = (Bitmap)AForge.Imaging.Image.Clone(_sourceImage);

                    // We must convert it to grayscale because
                    // the filter accepts 8 bpp grayscale images

                    Grayscale GF           = new Grayscale(0.2125, 0.7154, 0.0721);
                    Bitmap    GSampleImage = GF.Apply(_sample);

                    // Detecting image edges and saving the result
                    CannyEdgeDetector CED = new CannyEdgeDetector(0, 70);
                    CED.ApplyInPlace(GSampleImage);

                    Bitmap _temp = new Bitmap(320, 240);
                    _temp = GSampleImage;
                    pictureBoxSource.Image = _temp;

                    ProcessByImage(_temp);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Ejemplo n.º 10
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            OpenFileDialog openDialog  = new OpenFileDialog();
            var            returnValue = openDialog.ShowDialog();

            if (returnValue == DialogResult.OK)
            {
                originalImage     = new Bitmap(openDialog.FileName);
                pictureBox1.Image = originalImage;

                // pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage;
                Grayscale GrayImage = new Grayscale(0.2125, 0.7154, 0.0721);
                Bitmap    graycolor = GrayImage.Apply(originalImage);

                Threshold BinaryImageE = new Threshold();
                Bitmap    binaryimage  = BinaryImageE.Apply(graycolor);
                pictureBox1.Image = graycolor;
                //graycolor.Save(@"E:\Works\Machine Learning - OCR\raw\graycolor.jpg");

                List <Bitmap> temp_bound = new List <Bitmap>();
                //Bitmap boundedimage1 = new Bitmap("E://Works//Machine Learning - OCR//raw//graycolor.jpg");
                temp_bound.Add(graycolor);

                List <Bitmap> boundedimage = BoundImage(temp_bound);
                pictureBox2.Image = boundedimage[0];
                //boundedimage[0].Save(@"E:\Works\Machine Learning - OCR\raw\boundedimage.jpg");
                List <Bitmap> segments = Segment(boundedimage[0]);
                pictureBox2.Image = segments[0];
                List <float[]> test_feature = Zone(segments);
                write_testfile(test_feature);
                TestClassifier();
            }
        }
Ejemplo n.º 11
0
        private Bitmap ConvertToGray(Bitmap bitmap)
        {
            Grayscale filter = new Grayscale(0.3, 0.5, 0.1);

            bitmap = filter.Apply(bitmap);
            return(bitmap);
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            Bitmap bitmap_0 = new Bitmap(@"D:\Projects\hisdocpro\HisDocPro\HisDocProUI\bin\Debug\tokens\t_0_c000.png");
            //Bitmap bitmap_0 = new Bitmap(PageFileSelected);
            Bitmap bitmapTemp = new Grayscale(0.2125, 0.7154, 0.0721).Apply(bitmap_0);

            bitmapTemp = new Threshold(100).Apply(bitmapTemp);
            bitmapTemp = new Invert().Apply(bitmapTemp);

            double[,] image  = ToolsConvolution.BitMapToDoubleArray(bitmapTemp, 0.5);
            double[,] kernel = ToolsConvolution.BitMapToDoubleArray(bitmapTemp, 0.5);
            Print(image);
            Print(kernel);
            //double[,] image = new double[6, 6];
            //image[2, 1] = 1;
            //image[2, 2] = 1;
            //image[2, 3] = 1;
            //image[2, 4] = 1;
            //double[,] kernel = new double[3, 3];
            //kernel[0, 0] = 1;
            //kernel[0, 1] = 1;
            //kernel[0, 2] = 1;
            //kernel[2, 1] = 1;
            //Print(image);
            //Print(kernel);

            //double[,] result = ToolsConvolution.CorrelationFFT(image, kernel);

            //Print(result);
            //Console.ReadLine();
            double [,] result = ToolsConvolution.CorrelationFFT(image, kernel);
            Print(result);
            //List<string> page = ToolsPDF.Convert(@"D:\Projects\hisdocpro\page.pdf");
        }
Ejemplo n.º 13
0
        private static Bitmap ToGrayScale(this Bitmap thisBitmap)
        {
            Grayscale filter    = new Grayscale(0.2125, 0.7154, 0.0721);
            Bitmap    grayImage = filter.Apply(thisBitmap);

            return(grayImage);
        }
Ejemplo n.º 14
0
        protected IImage ToGrayScale(IImage image)
        {
            var bitmap    = image.ToBgr().Lock().AsAForgeImage();
            var grayScale = new Grayscale(0.2125, 0.7154, 0.0721).Apply(bitmap);

            return(grayScale.AsImage());
        }
Ejemplo n.º 15
0
        private void scala(Bitmap image)
        {
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinWidth     = 2;
            blobCounter.MinHeight    = 2;
            blobCounter.FilterBlobs  = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;

            Grayscale grayFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            Bitmap    grayImage  = grayFilter.Apply(image);

            blobCounter.ProcessImage(grayImage);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            foreach (Rectangle recs in rects)
            {
                if (rects.Length > 0)
                {
                    Rectangle objectRect = rects[0];
                    Graphics  g          = pictureBox1.CreateGraphics();
                    using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                    {
                        g.DrawRectangle(pen, objectRect);
                    }

                    X = objectRect.X + (objectRect.Width / 2);
                    Y = objectRect.Y + (objectRect.Height / 2);
                    g.DrawString(X.ToString() + "X" + Y.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));
                    g.Dispose();
                }
            }
        }
Ejemplo n.º 16
0
 void Awake()
 {
     audioSource    = GetComponent <AudioSource>();
     gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>();
     grayscale      = GetComponentInChildren <Grayscale>(true);
     motionblur     = GetComponentInChildren <MotionBlur>(true);
 }
Ejemplo n.º 17
0
        public mGrayscale(double redCoef, double greenCoef, double blueCoef, GrayscaleModes mode)
        {
            RedCoef   = redCoef;
            GreenCoef = greenCoef;
            BlueCoef  = blueCoef;
            Mode      = mode;

            BitmapType = mFilter.BitmapTypes.None;

            switch (Mode)
            {
            default:
                Effect = new Grayscale(RedCoef, GreenCoef, BlueCoef);
                break;

            case GrayscaleModes.BT709:
                Effect = Grayscale.CommonAlgorithms.BT709;
                break;

            case GrayscaleModes.RMY:
                Effect = Grayscale.CommonAlgorithms.RMY;
                break;

            case GrayscaleModes.Y:
                Effect = Grayscale.CommonAlgorithms.Y;
                break;
            }

            filter = Effect;
        }
Ejemplo n.º 18
0
        public string decodeBitmap(Bitmap img)
        {
            /////////图像处理
            //转为灰度图
            Grayscale grayscaleFilter = new Grayscale(0.299, 0.587, 0.114);
            Bitmap    bitmapGrayscale = grayscaleFilter.Apply(img);
            //二值化
            Threshold thresholdFilter = new Threshold(128);
            Bitmap    bitmapThreshold = thresholdFilter.Apply(bitmapGrayscale);
            ////////中值滤波
            Median mediafil  = new Median();
            Bitmap medianBit = mediafil.Apply(bitmapThreshold);
            //锐化
            Sharpen sharpPic = new Sharpen();
            Bitmap  sharpOut = sharpPic.Apply(medianBit);
            //统计点数
            HorizontalIntensityStatistics his = new HorizontalIntensityStatistics(sharpOut);
            Histogram histogram = his.Gray;

            int[] dato = histogram.Values;
            /////分割图像
            charCut(dato);
            shunfengdecoder decode   = new shunfengdecoder();
            string          backcode = decode.Decoder(sharpOut, div);

            return(backcode);
        }
        public double[] ConvertImageToDouble(Bitmap imageBitmap)
        {
            Grayscale     gs            = new Grayscale(0, 0, 0);
            ImageToMatrix imageToMatrix = new ImageToMatrix();

            imageBitmap = gs.Apply(imageBitmap);
            imageToMatrix.Convert(imageBitmap, out byte[][] imageBytes);

            foreach (byte[] t in imageBytes)
            {
                for (var j = 0; j < t.Length; j++)
                {
                    if (t[j] > 190)
                    {
                        t[j] = 1;
                    }
                    else
                    {
                        t[j] = 0;
                    }
                }
            }

            return(imageBytes.Flatten().ToDouble());
        }
Ejemplo n.º 20
0
        public string decoder(Bitmap img)
        {
            //灰度
            Grayscale grayscaleFilter = new Grayscale(0.299, 0.587, 0.114);
            Bitmap    bitmapGrayscale = grayscaleFilter.Apply(img);
            //二值化
            Threshold thresholdFilter = new Threshold(128);
            Bitmap    bitmapThreshold = thresholdFilter.Apply(bitmapGrayscale);

            /////统计点数分布

            HorizontalIntensityStatistics his = new HorizontalIntensityStatistics(bitmapThreshold);


            Histogram histogram = his.Gray;

            int[] dato = histogram.Values;

            /////分割验证码字符
            charCut(dato);
            ////////解码
            yuantongdecoder decode     = new yuantongdecoder();
            string          backNumber = decode.Decoder(bitmapThreshold, div);

            return(backNumber);
        }
        public override Bitmap ApplyFilter(List <Bitmap> bitmap)
        {
            Grayscale filter    = new Grayscale(red, green, blue);
            Bitmap    newBitmap = Image.Clone(bitmap[0], PixelFormat.Format32bppRgb);

            return(filter.Apply(newBitmap));
        }
Ejemplo n.º 22
0
        private void CameraOne_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap    bitmap1 = (Bitmap)(eventArgs.Frame.DeepClone());
            Grayscale filter  = new Grayscale(0.2, 0.7, 0.07);

            if (checkBox1.Checked)
            {
                bitmap1 = filter.Apply(bitmap1);
            }
            int x = 0;

            Invoke(new MethodInvoker(delegate
            {
                x = trackBar1.Value;
            }));
            RotateNearestNeighbor filterrot = new RotateNearestNeighbor(x, true);

            bitmap1 = filterrot.Apply(bitmap1);
            ResizeBicubic filterResizeBicubic = new ResizeBicubic(320, 240);

            bitmap1 = filterResizeBicubic.Apply(bitmap1);
            if (button1WasClicked)
            {
                Convolution conv = new Convolution(new[, ]
                {
                    { int.Parse(textBox1.Text), int.Parse(textBox2.Text), int.Parse(textBox3.Text) },
                    { int.Parse(textBox4.Text), int.Parse(textBox5.Text), int.Parse(textBox6.Text) },
                    { int.Parse(textBox7.Text), int.Parse(textBox8.Text), int.Parse(textBox9.Text) }
                });
                bitmap1 = conv.Apply(bitmap1);
            }
            pictureBox1.Image = bitmap1;
        }
Ejemplo n.º 23
0
	void Start () {
		offset = transform.position;
		_grayscaleComponent = GetComponent<Grayscale>();
		_blurComponent = GetComponent<MotionBlur> ();
		_blurComponent.enabled = false;
		_grayscaleComponent.enabled = true;
	}
Ejemplo n.º 24
0
        public static Bitmap skew(Bitmap source)        // 기울어짐 바로잡기
        {
            // create grayscale filter (BT709)
            Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);       // 8비트 grayscale 로 바꾸고
            // apply the filter
            Bitmap grayImage = filter.Apply(source);

            // create instance of skew checker
            DocumentSkewChecker skewChecker = new DocumentSkewChecker(); // 8비트 grayscale 로 넣어줘야 함
            //    // get documents skew angle
            double angle = skewChecker.GetSkewAngle(grayImage);          // 기울어진 각도를 얻고

            Bitmap tmp = source;

            // convert to 24 bits per pixel
            source = imageProcess.Clone(tmp, PixelFormat.Format24bppRgb);       // 로테이션 전에 24비트로 바꿔주고
            // delete old image
            tmp.Dispose();

            // create rotation filter
            RotateBilinear rotationFilter = new RotateBilinear(-angle);

            rotationFilter.FillColor = Color.White;
            // rotate image applying the filter
            Bitmap rotatedImage = rotationFilter.Apply(source);  // 원래 이미지를 가져다가 각도만큼 돌리고(원래 이미지는 24비트로 넣어줘야함)

            return(rotatedImage);
        }
 void Start()
 {
     dialog = Object.FindObjectOfType<DialogBox>();
     cameraGrayscale = Object.FindObjectOfType<Grayscale>();
     camera = GetComponent<Camera>();
     camera.enabled = false;
 }
Ejemplo n.º 26
0
        private void cevreal(Bitmap image)// Algilanan rengi Çevrçevelemek veya hedeflemek için gerekli Method.
        {
            blobCounter.MinWidth     = 2;
            blobCounter.MinHeight    = 2;
            blobCounter.FilterBlobs  = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            Grayscale grayFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            Bitmap    grayImage  = grayFilter.Apply(image);

            blobCounter.ProcessImage(grayImage);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            foreach (Rectangle recs in rects)
            {
                if (rects.Length > 0)
                {
                    Rectangle objectRect = rects[0];
                    Graphics  g          = pictureBox1.CreateGraphics();
                    using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                    {
                        g.DrawRectangle(pen, objectRect);
                    }
                    objectX = objectRect.X + (objectRect.Width / 2);  //Dikdörtgenin Koordinatlari alınır.
                    objectY = objectRect.Y + (objectRect.Height / 2); //Dikdörtgenin Koordinatlari alınır.
                    g.DrawString(objectX.ToString() + "X" + objectY.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));
                    g.Dispose();
                }
            }
        }
Ejemplo n.º 27
0
        private void button3_Click(object sender, EventArgs e)
        {
            SetLabelVisibel(10, false);
            SetLabelVisibel(11, false);
            SetLabelVisibel(12, false);
            SetPictureBoxVisibel(2, false);
            SetPictureBoxVisibel(3, false);
            SetPictureBoxVisibel(4, false);
            SetChartVisibel(1, false);
            SetChartVisibel(2, false);
            if (openImg != null)
            {
                Grayscale trans   = new Grayscale();
                Bitmap    grayImg = new Bitmap(openImg);
                // transform image to grayscale
                grayImg = trans.Transform(openImg);
                if (grayImg != null)
                {
                    SetLabel(10, "Grayscale");
                    SetPictureBox(2, grayImg);

                    SetLabelVisibel(10, true);
                    SetPictureBoxVisibel(2, true);
                }
                else
                {
                    SetLabelVisibel(10, false);
                    SetPictureBoxVisibel(2, false);
                }
            }
        }
    public static Bitmap ConvertToGrayScale(this Bitmap me)
    {
        if (me == null)
        {
            return(null);
        }
        int radius = 20, x = me.Width / 2, y = me.Height / 2;

        // Generate a two-dimensional `byte` array that has the same size as the source image, which will be used as the mask.
        byte[,] mask = new byte[me.Height, me.Width];
        // Initialize all its elements to the value 0xFF (255 in decimal).
        Initialize(mask, 0xFF);
        // "Draw" a circle in the `byte` array setting the positions inside the circle with the value 0.
        DrawCircle(mask, x, y, radius, 0);
        var grayFilter = new Grayscale(0.2125, 0.7154, 0.0721);
        var rgbFilter  = new GrayscaleToRGB();
        var maskFilter = new ApplyMask(mask);
        // Apply the `Grayscale` filter to everything outside the circle, convert the resulting image back to RGB
        Bitmap img = rgbFilter.Apply(grayFilter.Apply(maskFilter.Apply(me)));

        // Invert the mask
        Invert(mask);
        // Get only the cirle in color from the original image
        Bitmap circleImg = new ApplyMask(mask).Apply(me);

        // Merge both the grayscaled part of the image and the circle in color in a single one.
        return(new Merge(img).Apply(circleImg));
    }
Ejemplo n.º 29
0
        void VideoSourcePlayerNewFrame(object sender, ref Bitmap image)
        {
            lock (this)
            {
                Bitmap    img_copy    = new Bitmap(image);
                Grayscale gray_filter = new Grayscale(0.2125, 0.7154, 0.0721);
                img_copy = gray_filter.Apply(img_copy);
                Threshold thresh = new Threshold(thresh_val);
                img_copy = thresh.Apply(img_copy);
                BlobCounter bc = new BlobCounter();
                bc.FilterBlobs = true;
                bc.MinHeight   = min_size_val;
                bc.MinWidth    = min_size_val;
                bc.MaxHeight   = min_size_val + 50;
                bc.MaxWidth    = min_size_val + 50;
                bc.ProcessImage(img_copy);
                Rectangle[] rects = bc.GetObjectsRectangles();

                Graphics g = videoSourcePlayer.CreateGraphics();
                using (Pen p = new Pen(Color.Red))
                {
                    foreach (Rectangle r in rects)
                    {
                        g.DrawRectangle(p, r);
                        g.DrawString("a", new Font("Consolas", 10), Brushes.Red, r.X, r.Y);
                    }
                }
                image = img_copy;
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Binarize a given bitmap based on the given threshold value.
        /// First the bitmap is converted to a grayscale, then there is a binarization based on the threshold value
        /// and finally there is an optional mirror filter.
        /// </summary>
        /// <param name="bmp">Bitmap to binarize</param>
        /// <param name="treshold">Threshold value (0 - 255)</param>
        /// <param name="mirrorChecked">If true, the image will be mirrored</param>
        /// <returns>Binarized with threshold value bitmap</returns>
        public static Bitmap imageBinarization(Bitmap bmp, int threshold, bool mirrorChecked)
        {
            // Create bitmap with grayScale pixelformat
            Bitmap bitmap = new Bitmap(bmp.Width, bmp.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            // Create grayscale filter (BT709) and apply filter
            Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);

            bitmap = filter.Apply(bmp);

            // Create Threshold (binarization) filter and apply
            Threshold filter1 = new Threshold(threshold);

            filter1.ApplyInPlace(bitmap);

            // Create mirror filter if checkbox was checked
            if (mirrorChecked == true)
            {
                Mirror filter2 = new Mirror(false, true);
                filter2.ApplyInPlace(bitmap);
            }

            // Return binarized bitmap
            return(bitmap);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Applies the grayscale and treshold filter to the original bitmap.
        /// </summary>
        /// <param name="bmp">Original bitmap.</param>
        /// <returns>Bitmap with filters applied.</returns>
        private Bitmap PreProcess(Bitmap bmp)
        {
            bmp = new Grayscale(0.2125, 0.7154, 0.0721).Apply(bmp);
            new BradleyLocalThresholding().ApplyInPlace(bmp);

            return(bmp);
        }
Ejemplo n.º 32
0
        private void borderFollow(ushort j)
        {
            cvsim.Source = images[j];

            cvsbmp = UtilFn.BitmapImage2Bitmap(images[j]);
            Bitmap    resbmp  = UtilFn.ResizeBitmap(cvsbmp, (int)cvsim.Width, (int)(cvsim.Width * images[j].Height / images[j].Width));
            Grayscale gfilter = new Grayscale(0.2125, 0.7154, 0.0721);

            Bitmap grayImage = gfilter.Apply(cvsbmp);

            BorderFollowing bf = new BorderFollowing();

            List <Accord.IntPoint> contour = bf.FindContour(resbmp);

            imageInfo.Text = contour.Count + ": ";
            foreach (var c in contour)
            {
                Ellipse dot = new Ellipse();
                dot.Width           = 4;
                dot.Height          = 4;
                dot.StrokeThickness = 2;
                dot.Stroke          = System.Windows.Media.Brushes.Violet;
                Canvas.SetTop(dot, c.Y - 1 + (int)((cvs.Height - resbmp.Height) / 2));
                Canvas.SetLeft(dot, c.X - 1);
                imageInfo.Text += "(" + c.X + ", " + c.Y + ");";
                cvs.Children.Add(dot);
            }

            imagesEdited.Add(UtilFn.rtbToBitmapImage(UtilFn.ExportToPng(null, cvs)).Clone());
            cvs.Children.RemoveRange(1, cvs.Children.Count);
        }
 public override void ApplyEffect()
 {
     gs = Camera.main.gameObject.AddComponent<Grayscale>();
         gs.shader=GameWorldController.instance.greyScale;//Shader.Find ("Hidden/Grayscale Effect");
     //Pick a random palette to use
         gs.textureRamp = (Texture)Resources.Load(_RES +"/Palettes/palette_000" + Random.Range(0,7));
         base.ApplyEffect ();
 }
    void Start()
    {
        red = this.gameObject.GetComponent<Red>();
        green = this.gameObject.GetComponent<Green>();
        blue = this.gameObject.GetComponent<Blue>();

        gray = this.gameObject.GetComponent<Grayscale>();
        lastSwitch = Time.time;

        current = "grey";
    }
    public override void ApplyEffect()
    {
        if (inUse==false)
        {
            gs = Camera.main.gameObject.AddComponent<Grayscale>();
            //gs.shader=Shader.Find ("Hidden/Grayscale Effect");
            gs.shader=GameWorldController.instance.greyScale;
        }

        base.ApplyEffect ();
    }
Ejemplo n.º 36
0
    void Start()
    {
        // Since they're taking turns, enforce this
        if (TolstoyDialog.Length - TeaganDialog.Length > 1)
            Debug.LogError("Tolstoy dialog piece needs to be at most one longer than the other.");

        // These are probably going to be uniqe so grab them this way
        cameraControl = Object.FindObjectOfType<CameraFollow>();
        dialog = Object.FindObjectOfType<DialogBox>();
        grayscale = Object.FindObjectOfType<Grayscale>();

        StartCoroutine(StartRoomCoroutine());
    }
Ejemplo n.º 37
0
    void Start()
    {
        camera = GetComponent<Camera>();
        bloom = GetComponent<BloomOptimized>();
        motionBlur = GetComponent<MotionBlur>();
        grayscale = GetComponent<Grayscale>();

        bloom.enabled = false;
        motionBlur.enabled = false;
        isInThePast = false;
        difference = normalRoom.transform.position - pastRoom.transform.position;
        pastMusicSource.volume = 0;

        player = GameObject.FindGameObjectWithTag("Player");
        if (player == null)
            throw new UnassignedReferenceException("No player found.");
    }
Ejemplo n.º 38
0
    // Use this for initialization
    void Start () {
        m_camera = GameObject.FindWithTag("MainCamera");
        m_grayScale = m_camera.GetComponent<Grayscale>();
	}
Ejemplo n.º 39
0
	// Use this for initialization
	void Start () {
        tw = GetComponent<Twirl>();
        g = GetComponent<Grayscale>();
        v = GetComponent<VignetteAndChromaticAberration>();
        Search();
	}
Ejemplo n.º 40
0
 void Start()
 {
     grayScript = mainCam.GetComponent<Grayscale>();
     noiseScript = mainCam.GetComponent<NoiseAndGrain>();
 }
Ejemplo n.º 41
0
    private void Start()
    {
        _introState = IntroState.Loading;
        _starTime = Time.realtimeSinceStartup;

        _rotSpeed = 10;
        _lastDataCheck = -1;
        _storyPlaneId = 1;

        _webcamTex = new Texture2D(1920, 1080, TextureFormat.RGBA32, false);
        //_webcamTex = new Texture2D(1024, 768, TextureFormat.RGBA32, false);

        Planes.SetActive(false);

        _audioSource = GetComponent<AudioSource>();
        _audioSource.clip = Resources.Load<AudioClip>("Audio/intro2");

        _planeRenderer = Plane.GetComponent<Renderer>();

        StoryPlane.transform.localScale = new Vector3(0.0001f, 0, 0.0001f);
        _tempTargetPos = new Vector3(Random.Range(-0.01f, 0.01f), Random.Range(-0.01f, 0.01f), _planeStartPos.z);

        var nextTex = Resources.Load<Texture2D>("Textures/Story/Story1");
        StoryPlane.GetComponent<Renderer>().material.mainTexture = nextTex;

        _cccScriptLeft = leftCam.GetComponent<ColorCorrectionCurves>();
        _cccScriptRight = rightCam.GetComponent<ColorCorrectionCurves>();

        _grayScriptLeft = leftCam.GetComponent<Grayscale>();
        _grayScriptRight = rightCam.GetComponent<Grayscale>();
        _grayScriptLeft.enabled = false;
        _grayScriptRight.enabled = false;

        _twirlScriptLeft = leftCam.GetComponent<Twirl>();
        _twirlScriptRight = rightCam.GetComponent<Twirl>();
        _twirlScriptLeft.enabled = false;
        _twirlScriptRight.enabled = false;
    }
Ejemplo n.º 42
0
 void Start()
 {
     grayscale = FindObjectOfType<Grayscale>();
     dialog = FindObjectOfType<DialogBox>();
     gameObject.SetActive(false);
 }
Ejemplo n.º 43
0
 void Start()
 {
     audio = GetComponent<AudioSource>();
     grayscale = FindObjectOfType<Grayscale>();
     convoManager = FindObjectOfType<ConversationManager>();
 }
Ejemplo n.º 44
0
 private void Awake()
 {
     BleedBehavior.BloodAmount = 0f;
     BleedBehavior.BloodReductionRatio = 1f;
     this.explodeHash = Animator.StringToHash("explode");
     this.DSpots = GameObject.FindWithTag("DeadSpots").GetComponent<DeadSpotController>();
     this.Hud = Scene.HudGui;
     this.Ocean = GameObject.FindWithTag("Ocean");
     this.mutantControl = Scene.MutantControler;
     this.sceneInfo = Scene.SceneTracker;
     this.Player = base.gameObject.GetComponent<PlayerInventory>();
     this.camFollow = base.GetComponentInChildren<camFollowHead>();
     this.hitReaction = base.GetComponent<playerHitReactions>();
     this.Atmos = Scene.Atmosphere;
     this.FrostScript = LocalPlayer.MainCam.GetComponent<Frost>();
     this.Tuts = LocalPlayer.Tuts;
     this.Sfx = LocalPlayer.Sfx;
     this.animator = LocalPlayer.Animator;
     this.DyingVision = LocalPlayer.MainCam.GetComponent<Grayscale>();
     this.Fullness = 1f;
     this.bloodPropertyBlock = new MaterialPropertyBlock();
     if (!LevelSerializer.IsDeserializing)
     {
         CoopPlayerVariations component = base.GetComponent<CoopPlayerVariations>();
         this.PlayerVariation = UnityEngine.Random.Range(0, component.Variations.Length);
         this.PlayerVariationBody = UnityEngine.Random.Range(0, component.BodyMaterials.Length);
     }
     if (this.CurrentArmorTypes == null || this.CurrentArmorTypes.Length != this.ArmorModel.Length)
     {
         this.CurrentArmorTypes = new PlayerStats.ArmorTypes[this.ArmorModel.Length];
         for (int i = 0; i < this.CurrentArmorTypes.Length; i++)
         {
             this.CurrentArmorTypes[i] = PlayerStats.ArmorTypes.None;
             this.ArmorModel[i].SetActive(false);
         }
     }
     if (this.CurrentArmorHP == null || this.CurrentArmorHP.Length != this.ArmorModel.Length)
     {
         this.CurrentArmorHP = new int[this.ArmorModel.Length];
     }
     this.CaveDoors = GameObject.FindGameObjectsWithTag("CaveDoor");
 }
Ejemplo n.º 45
0
    // Use this for initialization
    void Start()
    {
        foreach (GameObject go in  UnityEngine.Object.FindObjectsOfType<GameObject>()) {
            if ((go.layer == LayerMask.NameToLayer("Hidden KeyObjects") || go.layer == LayerMask.NameToLayer("Hidden Geometry"))) {
                MeshRenderer meshrenderer = go.GetComponent<MeshRenderer>();
                if (meshrenderer != null) meshrenderer.enabled = false;
            }

            foreach (Transform t in go.transform) {
                if ((t.gameObject.layer != LayerMask.NameToLayer("Hidden KeyObjects") && t.gameObject.layer != LayerMask.NameToLayer("Hidden Geometry"))) continue;
                List<MeshRenderer> renderers = new List<MeshRenderer>();
                renderers.AddRange(t.GetComponentsInChildren<MeshRenderer>());
                foreach (MeshRenderer m in renderers) {
                    m.enabled = false;
                }
            }
        }
        vignet = GetComponent<VignetteAndChromaticAberration>();
        grayscale = GetComponent<Grayscale>();

        playerController = GameObject.FindWithTag("Player").GetComponent<TwinStickController>();
        if (!Application.isEditor) {
            Cursor.lockState = CursorLockMode.Confined;
            Cursor.visible = false;
        }
    }
Ejemplo n.º 46
0
	void Awake() 
    {
        dialog = FindObjectOfType<DialogBox>();
        grayscale = FindObjectOfType<Grayscale>();
        gameMenu = FindObjectOfType<GameMenu>();
	}
Ejemplo n.º 47
0
 public IVoiLut GetLut(Grayscale applicator)
 {
     return _lutGetter(applicator);
 }
Ejemplo n.º 48
0
                private static AdjustableDataLut GetPresentationDataLut(Grayscale applicator)
                {
                    IDicomVoiLutsProvider voiLutsProvider = applicator.DicomVoiLutsProvider;
                    if (voiLutsProvider == null)
                        return null;

                    AutoVoiDataLut dataLut = AutoPresentationVoiDataLut.CreateFrom(voiLutsProvider);
                    if (dataLut == null)
                        return null;
                    return new AdjustableAutoVoiDataLut(dataLut);
                }
Ejemplo n.º 49
0
 private static AutoVoiLutLinear GetPresentationLinearLut(Grayscale applicator)
 {
     IDicomVoiLutsProvider voiLutsProvider = applicator.DicomVoiLutsProvider;
     if (voiLutsProvider == null)
         return null;
     return AutoPresentationVoiLutLinear.CreateFrom(voiLutsProvider);
 }