Exemplo n.º 1
0
        public void VectorsRotate120(Bitmap image, List <double[]> vector360Contur, List <double[]> vector360Hull)
        {
            int i;

            ProcessingImage             pi = new ProcessingImage();
            List <System.Drawing.Point> localPt;

            for (i = 180; i < 360; i++)
            {
                QuickHull qh    = new QuickHull();
                Contur    cont1 = new Contur();


                //медианный фильтр для шумов границ размытых объектов
                Median filter = new Median();
                filter.ApplyInPlace(image);


                //поворот на 1 градус
                Bitmap image1 = pi.RotateImg(image, i);
                image1  = pi.ProcImg(image1);
                localPt = pi.GetPoints(image1);
                //выделение выпуклой оболочки
                List <System.Drawing.Point> ConvexHullLocal = qh.quickHull(localPt);
                ConvexHullLocal = qh.DeleteAnglePoints(ConvexHullLocal);
                //и контура
                List <System.Drawing.Point> ConturLocal = cont1.kontur(image1);
                ConturLocal = cont1.DeleteAnglePoints(ConturLocal);
                Primary marks = new Primary(image1, ConturLocal, ConvexHullLocal);
                vector360Contur.Add(marks.Contour());
                vector360Hull.Add(marks.Convex());
            }
        }
Exemplo n.º 2
0
        public void addetalons(Bitmap etalon)
        {
            ProcessingImage pi = new ProcessingImage();
            List <double[]> vector360Contur    = new List <double[]>();
            List <double[]> vector360Hull      = new List <double[]>();
            List <double[]> vector180360Contur = new List <double[]>();
            List <double[]> vector180360Hull   = new List <double[]>();

            Bitmap ImageForThread1 = etalon.Clone(
                new Rectangle(0, 0, etalon.Width, etalon.Height),
                System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            Bitmap Image24 = etalon.Clone(
                new Rectangle(0, 0, etalon.Width, etalon.Height),
                System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            List <Point> localPt = new List <System.Drawing.Point>();
            Thread       t1      = new Thread(() => VectorsRotate120(ImageForThread1, vector180360Contur, vector180360Hull));

            t1.Start();
            //рассчет вектора признаков для каждого поворота
            for (int i = 0; i < 180; i++)
            {
                QuickHull qh    = new QuickHull();
                Contur    cont1 = new Contur();

                //медианный фильтр для шумов границ размытых объектов
                Median filter = new Median();
                filter.ApplyInPlace(Image24);


                //поворот на 1 градус
                Bitmap image1 = pi.RotateImg(Image24, i);
                image1  = pi.ProcImg(image1);
                localPt = pi.GetPoints(image1);
                //выделение выпуклой оболочки
                List <System.Drawing.Point> ConvexHullLocal = qh.quickHull(localPt);
                ConvexHullLocal = qh.DeleteAnglePoints(ConvexHullLocal);
                //и контура
                List <System.Drawing.Point> ConturLocal = cont1.kontur(image1);
                ConturLocal = cont1.DeleteAnglePoints(ConturLocal);
                Primary marks = new Primary(image1, ConturLocal, ConvexHullLocal);
                vector360Contur.Add(marks.Contour());
                vector360Hull.Add(marks.Convex());
                progressBar1.Value = i + 1;
                cont1 = null;
            }
            progressBar1.Value = 0;

            for (int i = 0; i < vector180360Contur.Count; i++)
            {
                vector360Contur.Add(vector180360Contur[i]);
                vector360Hull.Add(vector180360Hull[i]);
            }

            //запись в файл по 1 объекту
            //WriteToFileBegin(vector360Contur, "Contours.txt");
            //WriteToFileBegin(vector360Hull, "Hulls.txt");


            //vector360Contur = ReadFromFile("Contours.txt", 18);
            //vector360Hull = ReadFromFile("Hulls.txt", 28);


            GetConturHullCentroid(vector360Contur, vector360Hull);
            GetConturHullMedoid(vector360Contur, vector360Hull, Contourvec, Hullvec);
        }
Exemplo n.º 3
0
        private void recognize_Click(object sender, EventArgs e)
        {
            label15.Text = "";
            if (etalonimages.Count == 0)
            {
                foreach (PictureBox pb in etalonpanel.Controls.OfType <PictureBox>())
                {
                    if (pb.Image != null)
                    {
                        etalonimages.Add((Bitmap)pb.Image);
                    }
                }

                //чтение из файлов параметров

                ContourEtalCentr = ReadFromFile("ContourCentr.txt", 18);
                HullEtalCentr    = ReadFromFile("HullCentr.txt", 28);

                ContourEtalMedoid = ReadFromFile("ContourMed.txt", 18);
                HullEtalMedoid    = ReadFromFile("HullCentrMed.txt", 28);
            }
            Grayscale grayfilter = new Grayscale(0.2125, 0.7154, 0.0721);

            // применяем фильтр
            grayImage = grayfilter.Apply((Bitmap)vebpb.Image);
            //выводим на пичербокс
            //pictureBox1.Image = grayImage;

            //Application.Idle -= GetVideo;
            mainImage = grayImage.Clone(
                new Rectangle(0, 0, grayImage.Width, grayImage.Height),
                System.Drawing.Imaging.PixelFormat.Format8bppIndexed);


            //медианный фильтр для шумов границ размытых объектов
            Median filter1 = new Median();

            filter1.ApplyInPlace(mainImage);


            OtsuThreshold filter = new OtsuThreshold();

            // apply the filter

            filter.ApplyInPlace(mainImage);
            // check threshold value
            Invert filter2 = new Invert();

            // apply the filter
            filter2.ApplyInPlace(mainImage);


            // исправили потомучто надо
            //RecursiveBlobCounter bc = new RecursiveBlobCounter();
            BlobCounter bc = new BlobCounter();

            // process binary image
            bc.ProcessImage(mainImage);

            Rectangle[] rects = bc.GetObjectsRectangles();

            List <Bitmap> images         = new List <Bitmap>();
            List <Bitmap> imagesWithEdge = new List <Bitmap>();
            Bitmap        bp;
            int           i = 0;

            foreach (Rectangle rect in rects)
            {
                images.Add(new Bitmap(mainImage.Width, mainImage.Height));
                Graphics   g = Graphics.FromImage(images[i]);                               //получаю объект графики из битмап
                SolidBrush b = new SolidBrush(Color.Black);                                 //кисть для заливки
                g.FillRectangle(b, new Rectangle(0, 0, images[i].Width, images[i].Height)); //заполняю
                bp = mainImage.Clone(rects[i], System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
                g.DrawImage(bp, rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height);
                i++;
            }

            //List <List<System.Drawing.Point>> convexHull = new List<List<System.Drawing.Point>>();
            ProcessingImage             pi      = new ProcessingImage();
            QuickHull                   qh      = new QuickHull();
            Contur                      cont    = new Contur();
            List <System.Drawing.Point> localPt = new List <System.Drawing.Point>();

            foreach (Bitmap img in images)
            {
                //формирование выпуклой оболочки
                localPt = pi.GetPoints(img);
                List <System.Drawing.Point> ConvexHullLocal = qh.quickHull(localPt);
                ConvexHullLocal = qh.DeleteAnglePoints(ConvexHullLocal);
                convexHull.Add(ConvexHullLocal);
                //и контура
                List <System.Drawing.Point> ConturLocal = cont.kontur(img);
                ConturLocal = cont.DeleteAnglePoints(ConturLocal);
                edgePoint.Add(ConturLocal);
                imagesWithEdge.Add(img.Clone(new Rectangle(0, 0, img.Width, img.Height), System.Drawing.Imaging.PixelFormat.Format32bppRgb));
            }

            int hullimagenum = 0;

            foreach (PictureBox pb in Hullpanel.Controls)
            {
                if (hullimagenum < images.Count)
                {
                    pb.Image = images[hullimagenum];
                }
                hullimagenum++;
            }


            //выделение векторов признаков
            List <Primary>  marks                 = new List <Primary>();
            List <double[]> objectMarksHull       = new List <double[]>();
            List <double[]> objectMarksContur     = new List <double[]>();
            List <double[]> etallMarksCentrHull   = new List <double[]>();
            List <double[]> etallMarksCentrContur = new List <double[]>();
            List <double[]> etallMarksMedHull     = new List <double[]>();
            List <double[]> etallMarksMedContur   = new List <double[]>();

            for (i = 0; i < images.Count; i++)
            {
                marks.Add(new Primary(images[i], edgePoint[i], convexHull[i]));
                objectMarksContur.Add(marks[i].Contour());
                objectMarksHull.Add(marks[i].Convex());
            }

            //Отрисовка выпуклой оболочки
            for (i = 0; i < convexHull.Count; i++)
            {
                Graphics gr1 = Graphics.FromImage(images[i]);
                List <System.Drawing.Point> pt = new List <System.Drawing.Point>(convexHull[i]);
                for (int j = 0; j < pt.Count; j++)
                {
                    qh.PutPixel(gr1, Color.Red, pt[j].X, pt[j].Y, 255);
                }
                gr1 = Graphics.FromImage(imagesWithEdge[i]);
                List <System.Drawing.Point> pt1 = new List <System.Drawing.Point>(edgePoint[i]);
                for (int j = 0; j < pt1.Count; j++)
                {
                    cont.PutPixel(gr1, Color.Red, pt1[j].X, pt1[j].Y, 255);
                }
            }

            int contourimagenum = 0;

            foreach (PictureBox pb in Contourpanel.Controls)
            {
                if (contourimagenum < imagesWithEdge.Count)
                {
                    pb.Image = imagesWithEdge[contourimagenum];
                }
                contourimagenum++;
            }

            //int hullimagenum = 0;
            //foreach (PictureBox pb in Hullpanel.Controls)
            //{
            //    if (hullimagenum < images.Count)
            //        pb.Image = images[hullimagenum];
            //    hullimagenum++;
            //}


            for (int j = 0; j < etalonimages.Count; j++)
            {
                etallMarksCentrContur.Add(ContourEtalCentr[j]);
                etallMarksMedContur.Add(ContourEtalMedoid[j]);
                etallMarksCentrHull.Add(HullEtalCentr[j]);
                etallMarksMedHull.Add(HullEtalMedoid[j]);
            }


            for (int l = 0; l < images.Count; l++)
            {
                compareobjects(objectMarksHull,
                               objectMarksContur,
                               etallMarksCentrContur,
                               etallMarksMedContur,
                               etallMarksCentrHull,
                               etallMarksMedHull, l);
            }


            images.Clear();
            convexHull.Clear();
            edgePoint.Clear();
            imagesWithEdge.Clear();
            marks.Clear();
            //contourMarks.Clear();
            i = 0;
        }