Пример #1
0
        private void btnMatch_Click(object sender, EventArgs e)
        {
            //Converting Template into GrayScale Image
            Bitmap    templateImage = new Bitmap(textBox2.Text);
            Grayscale gg            = new GrayscaleBT709();
            Bitmap    grayTemplate  = gg.Apply(templateImage);

            // create template matching algorithm's instance
            ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0);
            // find all matchings with specified above similarity
            Bitmap sourceImage = new Bitmap(textBox1.Text);
            Bitmap graySource  = gg.Apply(sourceImage);

            TemplateMatch[] matchings = tm.ProcessImage(graySource, grayTemplate);

            Graphics g = Graphics.FromImage(sourceImage);

            if (matchings[0].Similarity > 0.8f)
            {
                int X = matchings[0].Rectangle.X;
                int Y = matchings[0].Rectangle.Y;

                g.DrawRectangle(new Pen(Color.HotPink, 20), X, Y, matchings[0].Rectangle.Width, matchings[0].Rectangle.Height);
                PicTemplate.Image = sourceImage;
                MessageBox.Show("Match found...");
            }
            else
            {
                MessageBox.Show("Match Not Found...");
            }
        }
Пример #2
0
        private void grayScaleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GrayscaleBT709 gray = new GrayscaleBT709();

            pictureBox2.Image = gray.Apply((Bitmap)pictureBox1.Image);
            pictureBox5.Image = gray.Apply((Bitmap)pictureBox4.Image);
        }
Пример #3
0
        private void videoSourcePlayer1_NewFrame(object sender, ref Bitmap obraz)
        {
            int    x            = 0;
            Bitmap objectsImage = null;
            Bitmap mImage       = null;

            mImage             = (Bitmap)obraz.Clone();
            filter.CenterColor = Color.FromArgb(kolor.ToArgb());
            filter.Radius      = (short)range;
            objectsImage       = obraz;
            filter.ApplyInPlace(objectsImage);
            if (czyKolorWybrany == true)
            {
                BitmapData     objectsData = objectsImage.LockBits(new Rectangle(0, 0, obraz.Width, obraz.Height), ImageLockMode.ReadOnly, obraz.PixelFormat);
                UnmanagedImage grayImage   = filtrSzarosci.Apply(new UnmanagedImage(objectsData));
                objectsImage.UnlockBits(objectsData);
                licznikDrobin.ProcessImage(grayImage);
                Rectangle[] kwadraty = licznikDrobin.GetObjectRectangles();
                if (kwadraty.Length > 0)
                {
                    foreach (Rectangle aktualnyKwadrat in kwadraty)
                    {
                        Graphics grafika = Graphics.FromImage(mImage);
                        using (Pen pen = new Pen(Color.FromArgb(0, 255, 0), 2))
                        {
                            grafika.DrawRectangle(pen, aktualnyKwadrat);
                        }
                        RozmiaryFigury a = new RozmiaryFigury(aktualnyKwadrat.Height, aktualnyKwadrat.Width);  //tutaj wypelniaja sie liczniki (wewnatrz klasy RozmiaryFigury)
                        tablicaFigur[x] = a;
                        x++;
                        grafika.Dispose();
                    }
                    if (aktualnyStanWykresu == "dynamiczny")
                    {
                        backgroundWorker1.RunWorkerAsync();
                    }
                    if (aktualnyStanWykresu == "statyczny" && licznikResetu < 2)
                    {
                        backgroundWorker1.RunWorkerAsync();
                        licznikResetu++;
                        backgroundWorker1.CancelAsync();
                    }
                    if (aktualnyStanWykresu == "statyczny" && licznikResetu == 2)
                    {
                        backgroundWorker1.CancelAsync();
                    }
                }
            }
            obraz = mImage;
        }
        private void greyScaleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GrayscaleBT709 gb = new GrayscaleBT709();

            newImg            = gb.Apply(orgImg);
            pictureBox2.Image = newImg;
        }
Пример #5
0
        // New frame received by the player
        private void videoSourcePlayer_NewFrame(object sender, ref Bitmap image)
        {
            //DateTime now = DateTime.Now;
            Graphics g = Graphics.FromImage(image);

            // paint current time
            //SolidBrush brush = new SolidBrush( Color.Red );
            //g.DrawString( now.ToString( ), this.Font, brush, new PointF( 5, 5 ) );

            if (radioButtonFixPicNo.Checked)
            {
                Crop           filter   = new Crop(new Rectangle(50, 300, 400, 400));
                Bitmap         newImage = filter.Apply(image);
                ResizeBilinear filter1  = new ResizeBilinear(200, 200);
                newImage = filter1.Apply(newImage);
                GrayscaleBT709 filter2   = new GrayscaleBT709();
                Bitmap         grayImage = filter2.Apply(newImage);
                ResizeBilinear filter3   = new ResizeBilinear(28, 28);
                Bitmap         smallPic  = filter3.Apply(grayImage);

                pictureBox1.Image = grayImage;
                pictureBox2.Image = smallPic;
            }

            //brush.Dispose( );
            g.Dispose( );
        }
Пример #6
0
        private void btnGriYap_Click(object sender, EventArgs e)
        {
            Bitmap         image    = new Bitmap(pictureBox1.Image);
            GrayscaleBT709 griResim = new GrayscaleBT709();

            pictureBox4.Image = griResim.Apply((Bitmap)pictureBox1.Image);
        }
        private void detectSkin()
        {
            //skin detection
            Color  clr       = Color.FromArgb(Color.White.ToArgb());
            Color  clr1      = Color.FromArgb(Color.Black.ToArgb());
            int    imgHeight = imageGot.Height;
            int    imgWidth  = imageGot.Width;
            String sc        = "";

            var rect  = new Rectangle(0, 0, imgWidth, imgHeight);
            var data  = imageGot.LockBits(rect, ImageLockMode.ReadWrite, imageGot.PixelFormat);
            var depth = Bitmap.GetPixelFormatSize(data.PixelFormat) / 8; //bytes per pixel

            var buffer = new byte[data.Width * data.Height * depth];

            //copy pixels to buffer
            Marshal.Copy(data.Scan0, buffer, 0, buffer.Length);
            ProcessDetectSkin(buffer, 0, 0, data.Width, data.Height, data.Width, depth);
            //Copy the buffer back to image
            Marshal.Copy(buffer, 0, data.Scan0, buffer.Length);

            imageGot.UnlockBits(data);

            GrayscaleBT709 gs = new GrayscaleBT709();

            imageGot = gs.Apply(imageGot);
            Threshold th = new Threshold();

            imageGot = th.Apply(imageGot);
        }
Пример #8
0
        public Bitmap Render()
        {
            if (this.IsReady == false)
            {
                return(null);
            }

            Bitmap r = null;

            lock (this)
            {
                IFilter grayscaleFilter = new GrayscaleBT709();
                Bitmap  b = grayscaleFilter.Apply(this.mBmp);
                r = new Bitmap(b.Width, b.Height);

                Graphics g = Graphics.FromImage(r);
                g.DrawImage(b, 0, 0, r.Width, r.Height);
                b.Dispose();

                if (this.ShowGrid)
                {
                    this.DrawGrid(g);
                }

                this.HighlightRegion(g, this.mBmp);

                this.DrawOutline(g);

                g.Dispose();
            }

            return(r);
        }
Пример #9
0
        private void CameraPanel_NewFrame(System.Drawing.Bitmap oBitmap)
        {
            #region 去除绿色以外其他色、绿色区域绘制边框
            Bitmap     objectImage = colorFilter.Apply(oBitmap);
            BitmapData objectData  = objectImage.LockBits(new Rectangle(0, 0, oBitmap.Width, oBitmap.Height),
                                                          ImageLockMode.ReadOnly, oBitmap.PixelFormat);
            UnmanagedImage grayImage = grayFilter.Apply(new UnmanagedImage(objectData));
            objectImage.UnlockBits(objectData);

            blobCounter1.ProcessImage(grayImage);
            Rectangle[] rects = blobCounter1.GetObjectsRectangles();

            if (rects.Length > 0)
            {
                Rectangle objectRect = rects[0];
                Graphics  g          = Graphics.FromImage(oBitmap);
                using (System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(160, 255, 160), 3))
                {
                    g.DrawRectangle(pen, objectRect);
                }
                g.Dispose();
            }

            UpdateObjectPicture(objectImage);
            #endregion


            //#region 去除绿色以外其他色
            //Bitmap objectImage = colorFilter.Apply(oBitmap);
            //UpdateObjectPicture(objectImage);
            //#endregion

            //Bitmap objectImage = SobelEdgeFilter.Apply(oBitmap);
            //UpdateObjectPicture(objectImage);
        }
Пример #10
0
        public static Bitmap ConvertToFormat(Bitmap image)
        {
            GrayscaleBT709 gg    = new GrayscaleBT709();
            Bitmap         akhir = gg.Apply(image);

            return(akhir);
        }
Пример #11
0
        private void grayScaleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GrayscaleBT709 grayObj = new GrayscaleBT709();

            grayImage         = grayObj.Apply(originalImage);
            pictureBox2.Image = grayImage;
        }
        /// <summary>
        /// Called when videoPlayer receives a new frame.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="image"></param>
        private void videoPlayer_NewFrame(object sender, ref System.Drawing.Bitmap image)
        {
            // conver frame to grayscale
            var grayscale = new GrayscaleBT709();
            var grayImage = grayscale.Apply(image);

            // convert image to dlib format
            var img = grayImage.ToArray2D <RgbPixel>();

            // detect face every 4 frames
            if (frameIndex % 4 == 0)
            {
                var faces = faceDetector.Detect(img);
                if (faces.Length > 0)
                {
                    currentFace = faces.First();
                }
            }

            // abort if we don't have a face at this point
            if (currentFace == default(DlibDotNet.Rectangle))
            {
                return;
            }

            // detect facial landmarks
            var shape = shapePredictor.Detect(img, currentFace);

            // detect eye state
            DetectEyeState(image, shape);

            // update frame counter
            frameIndex++;
        }
Пример #13
0
        private double[,] CreateGLCM(Bitmap image)
        {
            var grayLevelCooccurrenceMatrix = new GrayLevelCooccurrenceMatrix();

            image = grayscaleBT.Apply(image);

            return(grayLevelCooccurrenceMatrix.Compute(image));
        }
Пример #14
0
        private void differenceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GrayscaleBT709 grayObject = new GrayscaleBT709();

            pictureBox2.Image = grayObject.Apply((Bitmap)pictureBox1.Image);
            DifferenceEdgeDetector filter = new DifferenceEdgeDetector();

            pictureBox2.Image = filter.Apply((Bitmap)pictureBox2.Image);
        }
Пример #15
0
        private void homogenityToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GrayscaleBT709 grayObject = new GrayscaleBT709();

            pictureBox2.Image = grayObject.Apply((Bitmap)pictureBox1.Image);
            HomogenityEdgeDetector filter = new HomogenityEdgeDetector();

            pictureBox2.Image = filter.Apply((Bitmap)pictureBox2.Image);
        }
Пример #16
0
 private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (openFileDialog1.ShowDialog() == (System.Windows.Forms.DialogResult.OK))
     {
         pictureBox1.Image = (Bitmap)System.Drawing.Image.FromFile(openFileDialog1.FileName);
         GrayscaleBT709 gray = new GrayscaleBT709();
         pictureBox2.Image = gray.Apply((Bitmap)pictureBox1.Image);
     }
 }
Пример #17
0
        private Bitmap ProcessImage(Bitmap frame)
        {
            // convert the image to grayscale
            var grayConverter = new GrayscaleBT709();
            var grayFrame     = grayConverter.Apply(frame);

            // use a sobel edge detector to find color edges
            var edgeDetector = new SobelEdgeDetector();
            var edgeFrame    = edgeDetector.Apply(grayFrame);

            // threshold the edges
            var thresholdConverter = new Threshold(200);

            thresholdConverter.ApplyInPlace(edgeFrame);

            // use a blobcounter to find interesting shapes
            var detector = new BlobCounter()
            {
                FilterBlobs = true,
                MinWidth    = 25,
                MinHeight   = 25
            };

            detector.ProcessImage(edgeFrame);

            // find the circular shape
            var shapeDetector = new SimpleShapeChecker();
            var blobs         = detector.GetObjectsInformation();
            var circles       =
                from blob in blobs
                let edgePoints = detector.GetBlobsEdgePoints(blob)
                                 where shapeDetector.CheckShapeType(edgePoints) == ShapeType.Circle
                                 select blob;

            // show the traffic sign
            if (circles.Count() > 0)
            {
                var circleFrame = frame.Clone(circles.First().Rectangle, PixelFormat.DontCare);
                trafficSignBox.Image = circleFrame;
            }

            // highlight every circle in the image
            using (Graphics g = Graphics.FromImage(frame))
            {
                var rects = detector.GetObjectsRectangles();
                var pen   = new Pen(Color.Blue, 4);
                foreach (var circle in circles)
                {
                    g.DrawRectangle(pen, circle.Rectangle);
                }
            }

            // update picture boxes
            thresholdBox.Image = edgeFrame;

            return(frame);
        }
Пример #18
0
        private void binarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GrayscaleBT709 grayoject = new GrayscaleBT709();

            pictureBox2.Image = grayoject.Apply((Bitmap)pictureBox1.Image);
            Threshold filter = new Threshold();

            pictureBox2.Image = filter.Apply((Bitmap)pictureBox2.Image);
        }
Пример #19
0
        void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Video          = (Bitmap)eventArgs.Frame.Clone();
            VideoClone     = (Bitmap)Video.Clone();
            original.Image = Video;

            if (GrayIsOn)
            {
                grayBmp       = grayFilter.Apply(VideoClone);
                process.Image = grayBmp;
            }

            if (EdgeBmpIsOn)
            {
                grayBmp       = grayFilter.Apply(VideoClone);
                EdgeBmp       = Sobeledgededector.Apply(grayBmp);
                process.Image = EdgeBmp;
            }
        }
Пример #20
0
        private void videoSourcePlayer1_NewFrame(object sender, ref Bitmap image)
        {
            Bitmap objectsImage = null;
            Bitmap mImage       = null;

            mImage             = (Bitmap)image.Clone();
            filter.CenterColor = Color.FromArgb(color.ToArgb());
            filter.Radius      = (short)range;

            objectsImage = image;
            filter.ApplyInPlace(objectsImage);

            BitmapData objectsData = objectsImage.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                                                           ImageLockMode.ReadOnly, image.PixelFormat);
            UnmanagedImage grayImage = grayscaleFilter.Apply(new UnmanagedImage(objectsData));

            objectsImage.UnlockBits(objectsData);


            blobCounter.ProcessImage(grayImage);
            Rectangle[] rects = blobCounter.GetObjectRectangles();

            if (rects.Length > 0)
            {
                foreach (Rectangle objectRect in rects)
                {
                    Graphics g = Graphics.FromImage(mImage);
                    using (Pen pen = new Pen(Color.FromArgb(160, 255, 160), 5))
                    {
                        g.DrawRectangle(pen, objectRect);
                    }

                    g.Dispose();
                }
            }

            image = mImage;
        }
Пример #21
0
        private void btnMatch_Click(object sender, EventArgs e)
        {
            //Przyswojenie bitmapy
            Bitmap    templateImage = new Bitmap(PicTemplate.Image);
            Grayscale gg            = new GrayscaleBT709();
            //Converting Template into GrayScale Image
            Bitmap grayTemplate = gg.Apply(templateImage);

            //Wyłowanie algorytmu tamplate mathicng
            // create template matching algorithm's instance
            ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0);

            //Przyswojenie drugiego obrazku
            Bitmap sourceImage = new Bitmap(PictureInput.Image);
            Bitmap graySource  = gg.Apply(sourceImage);

            // find all matchings with specified above similarity
            TemplateMatch[] matchings = tm.ProcessImage(graySource, grayTemplate);
            lbRes.Text = "Result:";

            Graphics g = Graphics.FromImage(sourceImage);

            if (matchings[0].Similarity > 0.8f)
            {
                int X = matchings[0].Rectangle.X;
                int Y = matchings[0].Rectangle.Y;
                //ramka dla poszukiwanego objektu
                g.DrawRectangle(new Pen(Color.Red, 3), X, Y, matchings[0].Rectangle.Width, matchings[0].Rectangle.Height);
                //Show Original
                PicTemplate.Image = sourceImage;
                //Pokaz modal okienko
                MessageBox.Show("Match found...");
            }
            else
            {
                MessageBox.Show("Match Not Found...");
            }
        }
Пример #22
0
        private void fillHoleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GrayscaleBT709 greyscale = new GrayscaleBT709();
            Bitmap         grey      = greyscale.Apply(skin);
            Threshold      filter    = new Threshold(100);

            filter.ApplyInPlace(grey);
            Closing close = new Closing();
            Bitmap  j     = close.Apply(grey);
            Opening open  = new Opening();

            k = open.Apply(j);
            pictureBox3.Image = k;
        }
        private void edgeDetect()
        {
            Bitmap         news = new Bitmap(imageGot);
            GrayscaleBT709 gs   = new GrayscaleBT709();

            imageGot = gs.Apply(imageGot);
            CannyEdgeDetector cn = new CannyEdgeDetector();

            cn.LowThreshold   = 0;
            cn.HighThreshold  = 0;
            cn.GaussianSigma  = 1.4;
            imageGot          = cn.Apply(imageGot);
            pictureBox1.Image = imageGot;
        }
Пример #24
0
        private void blackAndWhiteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (checkifthereisimage() != 1)
            {
                return;
            }
            GrayscaleBT709 gray = new GrayscaleBT709();

            try
            {
                pictureBox1ImagePreview.Image = gray.Apply((Bitmap)pictureBox1ImagePreview.Image);
                imgFile = pictureBox1ImagePreview.Image;
            }
            catch (Exception ex)
            { }
        }
        /// <summary>
        /// Called when videoPlayer receives a new frame.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="image"></param>
        private void videoPlayer_NewFrame(object sender, ref Bitmap image)
        {
            // convert image to grayscale
            var gray  = new GrayscaleBT709();
            var frame = gray.Apply(image);

            // threshold image to only keep light pixels
            var threshold = new Threshold(125);

            threshold.ApplyInPlace(frame);

            // blank out everything but the road
            var horizonY = (int)(image.Height * 0.65);
            var fill     = new CanvasFill(new Rectangle(0, 0, image.Width, horizonY), Color.Red);

            fill.ApplyInPlace(frame);

            // detect edges
            var edgeDetector = new CannyEdgeDetector();

            edgeDetector.ApplyInPlace(frame);

            // do a hough line transformation, which will search for straight lines in the frame
            var transform = new HoughLineTransformation();

            transform.ProcessImage(frame);
            var rawLines = transform.GetMostIntensiveLines(50);

            // only keep non-horizontal lines that cross the horizon at the vanishing point
            var lines = from l in rawLines
                        let range = new Range(-75, -65)
                                    where range.IsInside(l.Radius) &&
                                    (l.Theta <= 85 || l.Theta >= 95)
                                    select l;

            // show the edge detection view in the bottom left box
            edgeBox.Image = frame;

            // show the lane detection view in the bottom right box
            var laneImg = new Bitmap(image.Width, image.Height);

            Utility.DrawHoughLines(lines, laneImg, Color.White, 1);
            laneBox.Image = laneImg;

            // draw the lanes on the main camera image too
            Utility.DrawHoughLines(lines, image, Color.LightGreen, 2);
        }
        /// <summary>
        /// Called when videoPlayer receives a new frame.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="image"></param>
        private void videoPlayer_NewFrame(object sender, ref Bitmap image)
        {
            // grayscale the image
            var grayscale = new GrayscaleBT709();
            var frame     = grayscale.Apply(image);

            // only detect once every 5 frames
            if (frameCounter++ % 5 == 0)
            {
                // scan the image and grab the first face
                var faces = faceDetector.ProcessFrame(frame);
                if (faces.Count() > 0)
                {
                    // copy the face
                    faceRect = faces.First();
                    var face = image.Clone(faces.First(), PixelFormat.DontCare);

                    // search the face for the nose
                    var noses = noseDetector.ProcessFrame(face);
                    if (noses.Count() > 0)
                    {
                        // record new nose location
                        noseRect = noses.First();
                        noseRect.Offset(faceRect.Location);
                    }
                }
            }

            // draw the mustache
            using (Graphics g = Graphics.FromImage(image))
            {
                // we want a mustache three times as wide as the nose
                int mustacheWidth  = 2 * noseRect.Width;
                int mustacheHeight = mustacheWidth * mustache.Height / mustache.Width;

                // center the mustache on the bottom of the nose
                int x1 = noseRect.X - (mustacheWidth / 4);
                int x2 = noseRect.X + noseRect.Width + (mustacheWidth / 4);
                int y1 = noseRect.Y + noseRect.Height - (mustacheHeight / 2);
                int y2 = noseRect.Y + noseRect.Height + (mustacheHeight / 2);

                // draw the mustache
                g.DrawImage(mustache, x1, y1, x2 - x1, y2 - y1);
            }
        }
Пример #27
0
        public static void ObjectDetection(ref Bitmap image)
        {
            Bitmap objectsImage = null;
            Bitmap mImage       = (Bitmap)image.Clone();

            eulideanColorFilter.CenterColor = Color.FromArgb(FilterColor.ToArgb());
            eulideanColorFilter.Radius      = (short)Range;

            objectsImage = image;
            eulideanColorFilter.ApplyInPlace(objectsImage);

            // lock image for further processing
            BitmapData objectsData = objectsImage.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);

            // grayscaling
            UnmanagedImage grayImage = grayscaleFilter.Apply(new UnmanagedImage(objectsData));

            // unlock image
            objectsImage.UnlockBits(objectsData);

            // locate blobs
            BlobCounterFilter.ProcessImage(grayImage);
            Rectangle[] rects = BlobCounterFilter.GetObjectRectangles();

            if (rects.Length > 0)
            {
                foreach (Rectangle objectRect in rects)
                {
                    // draw rectangle around derected object
                    Graphics g = Graphics.FromImage(mImage);
                    using (Pen pen = new Pen(Color.FromArgb(160, 255, 160), 5))
                    {
                        g.DrawRectangle(pen, objectRect);
                    }

                    g.Dispose();
                }
            }

            image = mImage;
        }
Пример #28
0
        private void segmentationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Grayscale grayscale = new GrayscaleBT709();

            grayimage         = grayscale.Apply(original);
            pictureBox2.Image = grayimage;
            Threshold bw = new Threshold();

            thresholdimage    = bw.Apply(grayimage);
            pictureBox2.Image = thresholdimage;
            //  ResizeBicubic resize = new ResizeBicubic(200, thresholdimage.Height);
            //  thresholdimage = resize.Apply(thresholdimage);
            List <int> xC    = new List <int> ();
            int        xPrev = 0;

            for (int i = 0; i < thresholdimage.Width; i++)
            {
                count = 0;
                for (int j = 0; j < thresholdimage.Height; j++)
                {
                    Color p = thresholdimage.GetPixel(i, j);
                    if (p.R == 0 && p.G == 0 && p.B == 0)
                    {
                        count++;
                    }
                }
                if (count != 0)
                {
                    if (xC.Count == 0)
                    {
                        xC.Add(i);
                    }
                    else
                    {
                        if (i - xPrev > 1)
                        {
                            xC.Add(i);
                        }
                    }
                    xPrev = i;
                }
            }
            List <Bitmap> ni = new List <Bitmap>();

            for (int i = 0; i < xC.Count; i++)
            {
                int endbound;
                if (i + 1 >= xC.Count)
                {
                    endbound = thresholdimage.Width;
                }
                else
                {
                    endbound = xC[i + 1];
                }
                Crop cr = new Crop(new Rectangle(xC[i], 0, endbound - xC[i], thresholdimage.Height));
                newImage = cr.Apply(thresholdimage);
                ni.Add(newImage);
                pictureBox4.Image = newImage;
                //  newImage.Save(@"C:\users\rahul\desktop\sampleImage.png");
            }

            Invert inv = new Invert();

            invertimage       = inv.Apply(newImage);
            pictureBox5.Image = invertimage;

            ExtractBiggestBlob ebb = new ExtractBiggestBlob();

            blobimage         = ebb.Apply(invertimage);
            pictureBox5.Image = blobimage;

            Invert inv1 = new Invert();

            invertimage1      = inv1.Apply(blobimage);
            pictureBox5.Image = invertimage1;

            List <int> yC     = new List <int>();
            int        xPrev1 = 0;

            for (int j = 0; j < thresholdimage.Height; j++)
            {
                count = 0;
                for (int i = 0; i < thresholdimage.Width; i++)
                {
                    Color p = thresholdimage.GetPixel(i, j);
                    if (p.R == 0 && p.G == 0 && p.B == 0)
                    {
                        count++;
                    }

                    if (count != 0)
                    {
                        if (yC.Count == 0)
                        {
                            yC.Add(j);
                        }
                        else
                        {
                            if (j - xPrev1 > 1)
                            {
                                yC.Add(j);
                            }
                        }
                        xPrev1 = j;
                    }
                }
            }
            List <Bitmap> ni1 = new List <Bitmap>();

            for (int j = 0; j < yC.Count; j++)
            {
                int endbound;
                if (j + 1 >= yC.Count)
                {
                    endbound = thresholdimage.Height;
                }
                else
                {
                    endbound = yC[j + 1];
                }
                Crop cr = new Crop(new Rectangle(0, yC[j], thresholdimage.Height, endbound - yC[j]));
                newImage3 = cr.Apply(thresholdimage);
                ni1.Add(newImage3);
                pictureBox3.Image = newImage3;
                // newImage.Save(@"C:\users\rahul\desktop\sampleImage1.png");
            }
            Invert inv2 = new Invert();

            invertimage3      = inv2.Apply(newImage3);
            pictureBox6.Image = invertimage3;

            ExtractBiggestBlob ebb1 = new ExtractBiggestBlob();

            blobimage1        = ebb1.Apply(invertimage3);
            pictureBox6.Image = blobimage1;

            Invert inv3 = new Invert();

            invertimage2      = inv3.Apply(blobimage1);
            pictureBox6.Image = invertimage2;
        }
Пример #29
0
        private void resultGestureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int           dir;
            int           no;
            List <string> filedir = new List <string>(Directory.GetDirectories(path));

            for (dir = 0, no = 0; (dir < filedir.Count && no <= 26); dir++, no++)
            {
                string[]      filePaths = Directory.GetFiles(filedir[dir].ToString());
                List <Bitmap> y         = new List <Bitmap>();
                foreach (var iI in filePaths)
                {
                    Bitmap Image = new Bitmap(iI);
                    y.Add(Image);
                }

                foreach (Bitmap img in y)
                {
                    pictureBox1.Image = img;
                    srcImg            = img;
                    dstImg            = img;
                    Bitmap skin  = new Bitmap(pictureBox1.Image);
                    var    rect  = new Rectangle(0, 0, skin.Width, skin.Height);
                    var    data  = skin.LockBits(rect, ImageLockMode.ReadWrite, skin.PixelFormat);
                    var    depth = Bitmap.GetPixelFormatSize(data.PixelFormat) / 8; //bytes per pixel

                    var buffer = new byte[data.Width * data.Height * depth];

                    //copy pixels to buffer
                    Marshal.Copy(data.Scan0, buffer, 0, buffer.Length);

                    System.Threading.Tasks.Parallel.Invoke(
                        () =>
                    {
                        //upper-left
                        Process(buffer, 0, 0, data.Width / 2, data.Height / 2, data.Width, depth);
                    },
                        () =>
                    {
                        //upper-right
                        Process(buffer, data.Width / 2, 0, data.Width, data.Height / 2, data.Width, depth);
                    },
                        () =>
                    {
                        //lower-left
                        Process(buffer, 0, data.Height / 2, data.Width / 2, data.Height, data.Width, depth);
                    },
                        () =>
                    {
                        //lower-right
                        Process(buffer, data.Width / 2, data.Height / 2, data.Width, data.Height, data.Width, depth);
                    }
                        );

                    //Copy the buffer back to image
                    Marshal.Copy(buffer, 0, data.Scan0, buffer.Length);

                    skin.UnlockBits(data);
                    pictureBox2.Image = skin;



                    Bitmap src = new Bitmap(pictureBox1.Image);
                    Bitmap res = new Bitmap(pictureBox2.Image);
                    src = resize(src, new Size(200, 200));
                    res = resize(res, new Size(200, 200));
                    pictureBox1.Image = src;
                    pictureBox2.Image = res;

                    GrayscaleBT709 grayoject = new GrayscaleBT709();
                    pictureBox2.Image = grayoject.Apply((Bitmap)pictureBox2.Image);

                    Dilatation filter = new Dilatation();
                    // apply the filter
                    pictureBox2.Image = filter.Apply((Bitmap)pictureBox2.Image);

                    ExtractBiggestBlob filter1 = new ExtractBiggestBlob();
                    pictureBox2.Image = filter.Apply((Bitmap)pictureBox2.Image);
                    blob = filter1.BlobPosition;

                    Bitmap src1   = new Bitmap(pictureBox1.Image);
                    Bitmap res1   = new Bitmap(pictureBox2.Image);
                    Bitmap newBmp = new Bitmap(src1.Width, res1.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);


                    //Threshold t = new Threshold();
                    //pictureBox2.Image = t.Apply((Bitmap)pictureBox2.Image);
                    for (int i = 0; i < res1.Width; i++)
                    {
                        for (int j = 0; j < res1.Height; j++)
                        {
                            System.Drawing.Color srcColor = src1.GetPixel(i + blob.X, j + blob.Y);
                            System.Drawing.Color dstColor = res1.GetPixel(i, j);
                            if (!(dstColor.R >= 0 && dstColor.R <= 10 && dstColor.G >= 0 && dstColor.G <= 10 && dstColor.B >= 0 && dstColor.B <= 10))
                            {
                                newBmp.SetPixel(i, j, srcColor);
                            }
                            else
                            {
                                newBmp.SetPixel(i, j, Color.Black);
                            }
                        }
                    }
                    res1 = newBmp;
                    pictureBox2.Image = newBmp;

                    List <double>  edgeCount  = new List <double>();
                    List <double>  ratio      = new List <double>();
                    int            pixelCount = 0;
                    Bitmap         Destimg    = new Bitmap(pictureBox2.Image);
                    GrayscaleBT709 go         = new GrayscaleBT709();
                    pictureBox2.Image = go.Apply((Bitmap)pictureBox2.Image);
                    Destimg           = go.Apply(Destimg);
                    CannyEdgeDetector filter2 = new CannyEdgeDetector(0, 0, 1.4);
                    pictureBox2.Image = filter2.Apply((Bitmap)pictureBox2.Image);
                    Destimg           = filter2.Apply(Destimg);


                    var imgarray = new System.Drawing.Image[36];

                    for (int i = 0; i < 6; i++)
                    {
                        for (int j = 0; j < 6; j++)
                        {
                            pixelCount++;
                            var index = i * 6 + j;
                            imgarray[index] = new Bitmap(40, 40);
                            var graphics = Graphics.FromImage(imgarray[index]);
                            graphics.DrawImage(Destimg, new Rectangle(0, 0, 40, 40), new Rectangle(i * 40, j * 40, 40, 40), GraphicsUnit.Pixel);
                            graphics.Dispose();
                        }
                    }

                    for (int n = 0; n < 36; n++)
                    {
                        int counter = 0;


                        Bitmap bufferImage = new Bitmap(imgarray[n]);
                        for (int i = 0; i < 40; i++)
                        {
                            for (int j = 0; j < 40; j++)
                            {
                                System.Drawing.Color hoefColor = bufferImage.GetPixel(i, j);
                                //if(hoefColor.R<=255 && hoefColor.R>=230 && hoefColor.G <= 255 && hoefColor.G >= 230 && hoefColor.B <= 255 && hoefColor.B >= 230)
                                if (!(hoefColor.R == 0 && hoefColor.G == 0 && hoefColor.B == 0))
                                {
                                    counter++;
                                }
                            }
                        }

                        edgeCount.Add(counter);
                    }

                    double total = edgeCount.Sum();
                    foreach (double x in edgeCount)
                    {
                        var a = (float)x / total;
                        ratio.Add(a);
                    }

                    FileStream   fs = new FileStream(@"D:\AI.txt", FileMode.Append, FileAccess.Write);
                    StreamWriter sw = new StreamWriter(fs);


                    sw.Write((no) + " ");
                    for (int i = 0; i < ratio.Count; ++i)
                    {
                        sw.Write(i + ":" + ratio[i].ToString() + " ");
                    }
                    sw.WriteLine();
                    sw.Close();
                    fs.Close();

                    Problem train = Problem.Read(@"D:\AI.txt");
                    Problem test  = Problem.Read(@"D:\test.txt");

                    Parameter parameters = new Parameter();

                    double C;
                    double Gamma;

                    parameters.C = 32; parameters.Gamma = 8;
                    Model model = Training.Train(train, parameters);
                    Prediction.Predict(test, @"D:\result.txt", model, false);
                }
            }
        }
Пример #30
0
        private void hOGToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <double>  edgeCount  = new List <double>();
            List <double>  ratio      = new List <double>();
            int            pixelCount = 0;
            Bitmap         Destimg    = new Bitmap(pictureBox2.Image);
            GrayscaleBT709 go         = new GrayscaleBT709();

            pictureBox2.Image = go.Apply((Bitmap)pictureBox2.Image);
            Destimg           = go.Apply(Destimg);
            CannyEdgeDetector filter = new CannyEdgeDetector(0, 0, 1.4);

            pictureBox2.Image = filter.Apply((Bitmap)pictureBox2.Image);
            Destimg           = filter.Apply(Destimg);


            var imgarray = new System.Drawing.Image[36];

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    pixelCount++;
                    var index = i * 6 + j;
                    imgarray[index] = new Bitmap(40, 40);
                    var graphics = Graphics.FromImage(imgarray[index]);
                    graphics.DrawImage(Destimg, new Rectangle(0, 0, 40, 40), new Rectangle(i * 40, j * 40, 40, 40), GraphicsUnit.Pixel);
                    graphics.Dispose();
                }
            }
            for (int n = 0; n < 36; n++)
            {
                int counter = 0;


                Bitmap bufferImage = new Bitmap(imgarray[n]);
                for (int i = 0; i < 40; i++)
                {
                    for (int j = 0; j < 40; j++)
                    {
                        System.Drawing.Color hoefColor = bufferImage.GetPixel(i, j);
                        //if(hoefColor.R<=255 && hoefColor.R>=230 && hoefColor.G <= 255 && hoefColor.G >= 230 && hoefColor.B <= 255 && hoefColor.B >= 230)
                        if (!(hoefColor.R == 0 && hoefColor.G == 0 && hoefColor.B == 0))
                        {
                            counter++;
                        }
                    }
                }

                edgeCount.Add(counter);


                //HistogramEqualization

                /*if (File.Exists(@"D:\AI.txt"))
                 * {
                 *  using (StreamWriter ssw = new StreamWriter(@"D:\AI.txt"))
                 *  {
                 *      ssw.Write(counter);
                 *      //tw.WriteLine(Lists.edgeCount);
                 *      //tw.Close();
                 *
                 *
                 *  }
                 * }*/
            }
            double total = edgeCount.Sum();

            foreach (double x in edgeCount)
            {
                var a = (float)x / total;
                ratio.Add(a);
            }

            FileStream   fs = new FileStream(@"D:\AI.txt", FileMode.Append, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);

            for (int i = 0; i < ratio.Count; ++i)
            {
                sw.Write(i + ":" + ratio[i].ToString() + " ");
            }
            sw.WriteLine();
            sw.Close();
            fs.Close();
        }