Exemplo n.º 1
0
        private void logoDetectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (pictureBox1.Image == null)
                {
                    return;
                }
                var img = new Bitmap(pictureBox1.Image)
                          .ToImage <Bgr, byte>();

                Image <Bgr, byte> logo   = null;
                OpenFileDialog    dialog = new OpenFileDialog();

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    logo = new Image <Bgr, byte>(dialog.FileName);
                }

                var vp = Process(logo.Mat, img.Mat);

                if (vp != null)
                {
                    CvInvoke.Polylines(img, vp, true, new MCvScalar(0, 0, 255), 5);
                }
                pictureBox1.Image = img.AsBitmap();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void rotate270ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (imgInput == null)
            {
                MessageBox.Show("please select an image.");
                return;
            }
            var img = new Bitmap(pictureBox1.Image).ToImage <Bgr, byte>();

            img = img.Rotate(270, new Bgr(0, 0, 0), false);

            pictureBox2.Image    = img.AsBitmap();
            pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
        }
Exemplo n.º 3
0
        private void convexHullToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (pictureBox1.Image == null)
                {
                    return;
                }

                var img = new Bitmap(pictureBox1.Image)
                          .ToImage <Bgr, byte>();

                img = img.SmoothGaussian(3);
                var gray = img.Convert <Gray, byte>()
                           .ThresholdBinaryInv(new Gray(225), new Gray(255));
                VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
                Mat hier = new Mat();

                CvInvoke.FindContours(gray, contours, hier, Emgu.CV.CvEnum.RetrType.External, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);

                int    index   = -1;
                double maxarea = -100;
                for (int i = 0; i < contours.Size; i++)
                {
                    double area = CvInvoke.ContourArea(contours[i]);
                    if (area > maxarea)
                    {
                        maxarea = area;
                        index   = i;
                    }
                }

                if (index > -1)
                {
                    var biggestcontour = contours[index];
                    //Mat hull = new Mat();

                    VectorOfPoint hull = new VectorOfPoint();
                    CvInvoke.ConvexHull(biggestcontour, hull);

                    //CvInvoke.DrawContours(img, hull, -1, new MCvScalar(0, 0, 255), 3);
                    CvInvoke.Polylines(img, hull.ToArray(), true, new MCvScalar(0, 0.0, 255.0), 3);
                }
                pictureBox1.Image = img.AsBitmap();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 4
0
        private void templateMatchinToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (pictureBox1.Image == null)
                {
                    return;
                }

                if (rect == null)
                {
                    MessageBox.Show("Select a template");
                    return;
                }

                var img = new Bitmap(pictureBox1.Image)
                          .ToImage <Bgr, byte>();

                img.ROI = rect;
                var template = img.Copy();
                //template = template.Resize(0.5, Emgu.CV.CvEnum.Inter.Cubic);
                template = template.Rotate(90, new Bgr(0, 0, 0));
                img.ROI  = Rectangle.Empty;

                CvInvoke.Imshow("Template", template);

                Mat imgout = new Mat();
                CvInvoke.MatchTemplate(img, template, imgout, Emgu.CV.CvEnum.TemplateMatchingType.Sqdiff);

                double minVal = 0;
                double maxVal = 0;
                Point  minLoc = new Point();
                Point  maxLoc = new Point();

                CvInvoke.MinMaxLoc(imgout, ref minVal, ref maxVal, ref minLoc, ref maxLoc);

                Rectangle r = new Rectangle(minLoc, template.Size);
                CvInvoke.Rectangle(img, r, new  MCvScalar(255, 0, 0), 3);
                pictureBox1.Image = img.AsBitmap();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 5
0
        private void gaussianBlurToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                if (pictureBox1.Image == null)
                {
                    MessageBox.Show("Select an image to process");
                    return;
                }

                var img = new Bitmap(pictureBox1.Image).ToImage <Bgr, byte>().SmoothGaussian(3);
                pictureBox1.Image = img.AsBitmap();
                AddImage(img, "Gaussian");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 6
0
        private void ProcessROI()
        {
            try
            {
                if (pictureBox1.Image == null)
                {
                    return;
                }

                if (rect == null)
                {
                    MessageBox.Show("Select an ROI");
                    return;
                }

                var img = new Bitmap(pictureBox1.Image)
                          .ToImage <Bgr, byte>();

                img.ROI = rect;
                var img2 = img.Copy();
                var img3 = img2.SmoothGaussian(25);


                //var blue = img2.SmoothGaussian(15).Canny(150, 50)
                //Image<Bgr, byte> img3 = new Image<Bgr, byte>(new Image<Gray, byte>[] {
                //blue,
                //blue,
                //blue });

                img.SetValue(new Bgr(1, 1, 1));
                img._Mul(img3);

                img.ROI           = Rectangle.Empty;
                pictureBox1.Image = img.AsBitmap();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }