Esempio n. 1
0
        private void button7_Click(object sender, EventArgs e)
        {
            MatImage m1 = new MatImage(mimg);

            m1.Convert();

            mimgInGray = m1.Out();
            MatImage m2 = new MatImage(mimgInGray);

            m2.SmoothGaussian(3);
            m2.ThresholdBinaryInv(245, 255);
            // this causes an exception, and I don't know how to fix that yet.
            //The good news is that this really doesn't matter for small images
            //m2.MorphologyEx(2);
            mimgInGray = m2.Out();
            MatImage m3 = new MatImage(mimgInGray);
            VectorOfVectorOfPoint     contours = m3.FindContours();
            List <ColorfulContourMap> cmaps    = ColorfulContourMap.getAllContourMap(mimg, 0);



            //CvInvoke.DrawContours(mimg, contours,-1, new Bgr(255,0,0).MCvScalar,2);
            Mat mimg2 = new Mat(new Size(mimg.Width, mimg.Height), DepthType.Cv8U, 3);

            foreach (ColorfulContourMap cmap in cmaps)
            {
                cmap.DrawColorTo(mimg2);
            }
            pictureBox1.Image = mimg.Bitmap;

            pictureBox2.Image = mimg2.Bitmap;
        }
Esempio n. 2
0
        private Point pointTransform(Point p, ColorfulContourMap map)
        {
            Point  result         = new Point();
            double requiredWidth  = pic1.Width;
            double requiredHeight = pic2.Height;

            result.X = (int)((p.X + 0.0) / pictureBox1.Width * requiredWidth);
            result.Y = (int)((p.Y + 0.0) / pictureBox1.Height * requiredHeight);
            return(result);
        }
Esempio n. 3
0
        public ColorfulContourMap Clone()
        {
            ColorfulContourMap cmap = new ColorfulContourMap();

            cmap._points     = _points.ToList();
            cmap._polyPoints = _polyPoints.ToList();
            cmap.Width       = Width;
            cmap.Height      = Height;
            cmap.Center      = Center;
            return(cmap);
        }
Esempio n. 4
0
        private ColorfulContourMap AddCroppedImages(bool blackOrWhite, ColorfulContourMap cmap)
        {
            // get the image
            Mat img;

            if (blackOrWhite)
            {
                img = Form1.whiteSourceImages[cmap.imageIndex].Clone();
            }
            else
            {
                img = Form1.blackSourceImages[cmap.imageIndex].Clone();
            }
            // get the min max x y
            int minX = cmap.Center.X - cmap.Width / 2;
            int minY = cmap.Center.Y - cmap.Height / 2;
            int maxX = cmap.Center.X + cmap.Width / 2;
            int maxY = cmap.Center.Y + cmap.Height / 2;



            // crop the corresponding image
            Mat result = new Mat(img, new Rectangle(new Point(minX, minY), new Size(maxX - minX, maxY - minY)));

            /*Mat result = new Mat(new Size(maxX-minX,maxY-minY),DepthType.Cv8U,3);
             * CvInvoke.cvResetImageROI(img);
             * CvInvoke.cvSetImageROI(img, new Rectangle(new Point(minX, minY), new Size(maxX - minX, maxY - minY)));
             * CvInvoke.cvCopy(img, result,IntPtr.Zero);*/
            if (blackOrWhite)
            {
                CvInvoke.CopyMakeBorder(result, result, 100, 100, 100, 100, BorderType.Constant, new MCvScalar(255, 255, 255));
            }
            else
            {
                CvInvoke.CopyMakeBorder(result, result, 100, 100, 100, 100, BorderType.Constant, new MCvScalar(0, 0, 0));
            }

            // output the image
            //result = img;
            if (blackOrWhite)
            {
                Form1.whiteCroppedImages.Add(result);
                cmap = ColorfulContourMap.getAllContourMap(result, cmap.imageIndex, 0)[0]; // update the contour map for the new image
            }
            else
            {
                Form1.blackCroppedImages.Add(result);
                cmap = ColorfulContourMap.getAllContourMap(result, cmap.imageIndex, 1)[0]; // update the contour map for the new image
            }
            return(cmap);
        }
 public ColorfulContourMap Clone()
 {
     ColorfulContourMap cmap = new ColorfulContourMap();
     cmap._points = _points.ToList();
     cmap._polyPoints = _polyPoints.ToList();
     cmap.Width = Width;
     cmap.Height = Height;
     cmap.Center = Center;
     return cmap;
 }
 private Point pointTransform(Point p, ColorfulContourMap map)
 {
     Point result = new Point();
     double requiredWidth = pic1.Width;
     double requiredHeight =pic2.Height;
     result.X = (int)((p.X + 0.0) / pictureBox1.Width * requiredWidth);
     result.Y = (int)((p.Y + 0.0) / pictureBox1.Height * requiredHeight);
     return result;
 }
Esempio n. 7
0
        private void button4_Click(object sender, EventArgs e)
        {
            // extract contour map
            if (Form1.blackSourceImages.Count + Form1.whiteSourceImages.Count != 0)
            {
                //DisplayBestMatch bestMatchView = new DisplayBestMatch();
                QueueView qv = new QueueView();

                // extract the contour maps, send the result into queueview
                int blackIndex = 0;
                int whiteIndex = 0;

                List <int> missBlackIndex = new List <int>();
                List <int> missWhiteIndex = new List <int>();
                for (int i = 0; i < Form1.blackSourceImages.Count; i++)
                {
                    List <ColorfulContourMap> cmap;
                    bool inProcess = false;
                    try {
                        cmap = ColorfulContourMap.getAllContourMap(Form1.blackSourceImages[i], blackIndex, 1);


                        for (int j = 0; j < cmap.Count; j++)
                        {
                            inProcess = true;
                            cmap[j]   = AddCroppedImages(false, cmap[j]);
                        }
                        Form1.blackContourMaps.AddRange(cmap);
                        blackIndex++;
                    }
                    catch
                    {
                        if (!inProcess)
                        {
                            MessageBox.Show("One of your input images seems to have a white background. That image will be moved into white category");
                            cmap = ColorfulContourMap.getAllContourMap(Form1.blackSourceImages[i], whiteIndex, 0);

                            //missBlackIndex.Add(blackIndex);
                            Form1.whiteSourceImages.Insert(whiteIndex, Form1.blackSourceImages[i]);

                            for (int j = 0; j < cmap.Count; j++)
                            {
                                cmap[j] = AddCroppedImages(true, cmap[j]);
                            }
                            Form1.whiteContourMaps.AddRange(cmap);
                            whiteIndex++;

                            Form1.blackSourceImages.Remove(Form1.blackSourceImages[i]);
                            i--;
                        }
                    }
                }

                for (int i = whiteIndex; i < Form1.whiteSourceImages.Count; i++)
                {
                    List <ColorfulContourMap> cmap;
                    bool inProcess = false;
                    try {
                        cmap = ColorfulContourMap.getAllContourMap(Form1.whiteSourceImages[i], whiteIndex, 0);


                        for (int j = 0; j < cmap.Count; j++)
                        {
                            inProcess = true;
                            cmap[j]   = AddCroppedImages(true, cmap[j]);
                        }
                        Form1.whiteContourMaps.AddRange(cmap);
                        whiteIndex++;
                    }
                    catch
                    {
                        if (!inProcess)
                        {
                            MessageBox.Show("One of your input images seems to have a black background. That image will be moved into black category");
                            cmap = ColorfulContourMap.getAllContourMap(Form1.whiteSourceImages[i], blackIndex, 1);

                            //missWhiteIndex.Add(whiteIndex);

                            for (int j = 0; j < cmap.Count; j++)
                            {
                                cmap[j] = AddCroppedImages(false, cmap[j]);
                            }
                            Form1.blackContourMaps.AddRange(cmap);
                            blackIndex++;

                            Form1.blackSourceImages.Add(Form1.whiteSourceImages[i]);
                            Form1.whiteSourceImages.Remove(Form1.whiteSourceImages[i]);
                            i--;
                        }
                    }
                }
                // move the images into their correct container if users misclassified them



                Hide();

                //bestMatchView.Show();
                qv.Show();
            }
            else
            {
                MessageBox.Show("Please input at least one image.");
            }

            // move to next form
        }