示例#1
0
        public void nesnebul(Bitmap image)
        {
            BlobCounter blobCounter = new BlobCounter();

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



            BitmapData objectsData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);

            Grayscale      grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage       = grayscaleFilter.Apply(new UnmanagedImage(objectsData));

            image.UnlockBits(objectsData);


            blobCounter.ProcessImage(image);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Blob[]      blobs = blobCounter.GetObjectsInformation();
            pictureBox2.Image = image;



            Rectangle objectRect;

            foreach (Rectangle recs in rects)
            {
                if (rects.Length > 0)
                {
                    objectRect = rects[0];

                    Graphics g = pictureBox1.CreateGraphics();
                    using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                    {
                        g.DrawRectangle(pen, objectRect);
                    }

                    g.Dispose();

                    if (chkCisimEbat.Checked)
                    {
                        this.Invoke((MethodInvoker) delegate
                        {
                            richTextBox1.Text = "Genişlik : " + objectRect.Width.ToString() + ",\t \nYükseklik: " + objectRect.Height.ToString() + "\n" + richTextBox1.Text + "\n";;

                            px = objectRect.Width;
                            py = objectRect.Height;
                        });
                    }
                }
            }
        }
示例#2
0
文件: Form1.cs 项目: m1s1t1f/proje
        private void ortalama(Bitmap res)
        {
            BlobCounter blop = new BlobCounter();

            blop.MinWidth     = 20;
            blop.MinHeight    = 20;
            blop.FilterBlobs  = true;
            blop.ObjectsOrder = ObjectsOrder.Size;

            Grayscale grı    = new Grayscale(0.2125, 0.7154, 0.0721);
            Bitmap    grıres = grı.Apply(res);

            blop.ProcessImage(grıres);
            Rectangle[] rects = blop.GetObjectsRectangles();

            foreach (Rectangle recs in rects)
            {
                if (rects.Length > 0)
                {
                    Rectangle nesneRect = rects[0];
                    Graphics  b         = Graphics.FromImage(res);
                    using (Pen pe = new Pen(Color.FromArgb(240, 3, 25), 2))
                    {
                        b.DrawRectangle(pe, nesneRect);
                    }
                    int nesneX = nesneRect.X + (nesneRect.Width / 2);
                    int nesneY = nesneRect.Y + (nesneRect.Height / 2);
                    b.DrawString(nesneX.ToString() + "X" + nesneY.ToString(), new Font("Times New Roman", 50), Brushes.White, new System.Drawing.Point(0, 0));
                    b.Dispose();

                    if (nesneX > 0 && nesneX <= 146)
                    {
                        ld = 1;
                    }
                    else if (nesneX > 146 && nesneX <= 292)
                    {
                        ld = 2;
                    }
                    else if (nesneX > 292 && nesneX <= 440)
                    {
                        ld = 3;
                    }
                    if (onceki != ld)
                    {
                        onceki = ld;
                        if (serialPort1.IsOpen)
                        {
                            serialPort1.Write(ld.ToString());
                        }
                    }
                }
            }
        }
示例#3
0
        public void nesnebul(Bitmap image)
        {
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinWidth     = 5;
            blobCounter.MinHeight    = 5;
            blobCounter.FilterBlobs  = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            //Grayscale griFiltre = new Grayscale(0.2125, 0.7154, 0.0721);
            //Grayscale griFiltre = new Grayscale(0.2, 0.2, 0.2);
            //Bitmap griImage = griFiltre.Apply(image);

            BitmapData objectsData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);
            // grayscaling
            Grayscale      grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage       = grayscaleFilter.Apply(new UnmanagedImage(objectsData));

            // unlock image
            image.UnlockBits(objectsData);


            blobCounter.ProcessImage(image);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Blob[]      blobs = blobCounter.GetObjectsInformation();
            pictureBox2.Image = image;



            if (radio_single_object_track.Checked)
            {
                //Single Object Tracking Single Tracking--------

                foreach (Rectangle recs in rects)
                {
                    if (rects.Length > 0)
                    {
                        Rectangle objectRect = rects[0];
                        //Graphics g = Graphics.FromImage(image);
                        Graphics g  = pictureBox1.CreateGraphics();
                        Graphics g2 = pictureBox2.CreateGraphics();
                        using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                        {
                            g.DrawRectangle(pen, objectRect);
                        }
                        //Coordinates of the rectified rectangle are taken.
                        int objectX = objectRect.X + (objectRect.Width / 2);
                        int objectY = objectRect.Y + (objectRect.Height / 2);
                        g.DrawString(objectX.ToString() + "X" + objectY.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));
                        Rectangle rec = new Rectangle(objectX, objectY, 5, 5);
                        g2.DrawEllipse(Pens.White, rec);
                        g.Dispose();

                        if (chek_show_coordi.Checked)
                        {
                            this.Invoke((MethodInvoker) delegate
                            {
                                richTextBox1.Text = objectRect.Location.ToString() + "\n" + richTextBox1.Text + "\n";;
                            });
                        }
                    }
                }
            }



            if (radio_multi_obj_track.Checked)
            {
                //Multi tracking Çoklu cisim Takibi-------

                for (int i = 0; rects.Length > i; i++)
                {
                    Rectangle objectRect = rects[i];
                    //Graphics g = Graphics.FromImage(image);
                    Graphics g = pictureBox1.CreateGraphics();
                    using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                    {
                        g.DrawRectangle(pen, objectRect);
                        g.DrawString((i + 1).ToString(), new Font("Arial", 12), Brushes.Red, objectRect);
                    }
                    //Cizdirilen Dikdörtgenin Koordinatlari aliniyor.
                    int objectX = objectRect.X + (objectRect.Width / 2);
                    int objectY = objectRect.Y + (objectRect.Height / 2);
                    g.DrawString(objectX.ToString() + "X" + objectY.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));


                    if (chck_dis_meter.Checked)
                    {
                        if (rects.Length > 1)
                        {
                            for (int j = 0; j < rects.Length - 1; j++)
                            {
                                int ilkx = (rects[j].Right + rects[j].Left) / 2;
                                int ilky = (rects[j].Top + rects[j].Bottom) / 2;

                                int ikix = (rects[j + 1].Right + rects[j + 1].Left) / 2;
                                int ikiy = (rects[j + 1].Top + rects[j + 1].Bottom) / 2;

                                g = pictureBox1.CreateGraphics();
                                g.DrawLine(Pens.Red, rects[j].Location, rects[j + 1].Location);
                                g.DrawLine(Pens.Blue, rects[0].Location, rects[rects.Length - 1].Location);
                                g.DrawLine(Pens.Red, ilkx, ilky, ikix, ikiy);
                            }
                        }

                        if (rects.Length == 2)
                        {
                            Rectangle ilk = rects[0];
                            Rectangle iki = rects[1];

                            int ilkX = ilk.X + (ilk.Width / 2);
                            int ilkY = ilk.Y + (ilk.Height / 2);

                            int ikiX = iki.X + (iki.Width / 2);
                            int ikiY = iki.Y + (iki.Height / 2);

                            //1 pixel (X) = 0.0264583333333334 centimeter [cm]

                            double formul = Math.Floor((Math.Sqrt((Math.Pow((ilkX - ikiX), 2)) + Math.Pow((ilkY - ikiY), 2))) * 0.0264);

                            string uzaklikY = "Y-" + Convert.ToString(ilkX - ikiX);
                            string uzaklikX = "X-" + Convert.ToString(ilkY - ikiY);

                            string distance = uzaklikX + " " + uzaklikY;

                            AForge.Imaging.Drawing.Line(objectsData, new IntPoint((int)ilkX, (int)ilkY), new IntPoint((int)ikiX, (int)ikiY), Color.Blue);


                            this.Invoke((MethodInvoker) delegate
                            {
                                richTextBox2.Text = formul.ToString() + " cm\n" + richTextBox2.Text + " cm\n";;
                            });


                            if (check_dist_coord.Checked)
                            {
                                this.Invoke((MethodInvoker) delegate
                                {
                                    richTextBox3.Text = distance.ToString() + "\n" + richTextBox3.Text + "\n";;
                                });
                            }
                        }
                    }


                    g.Dispose();

                    //     this.Invoke((MethodInvoker)delegate
                    //{
                    //    richTextBox1.Text = objectRect.Location.ToString() + "\n" + richTextBox1.Text + "\n"; ;
                    //});
                }
            }



            if (radio_geometric.Checked)
            {
                SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

                Graphics g         = pictureBox1.CreateGraphics();
                Pen      yellowPen = new Pen(Color.Yellow, 2); // circles
                Pen      redPen    = new Pen(Color.Red, 2);    // quadrilateral
                Pen      brownPen  = new Pen(Color.Brown, 2);  // quadrilateral with known sub-type
                Pen      greenPen  = new Pen(Color.Green, 2);  // known triangle
                Pen      bluePen   = new Pen(Color.Blue, 2);   // triangle

                for (int i = 0, n = blobs.Length; i < n; i++)
                {
                    List <IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);

                    AForge.Point center;
                    float        radius;

                    // is circle ?
                    if (shapeChecker.IsCircle(edgePoints, out center, out radius))
                    {
                        g.DrawEllipse(yellowPen,
                                      (float)(center.X - radius), (float)(center.Y - radius),
                                      (float)(radius * 2), (float)(radius * 2));
                    }
                    else
                    {
                        List <IntPoint> corners;

                        // is triangle or quadrilateral
                        if (shapeChecker.IsConvexPolygon(edgePoints, out corners))
                        {
                            // get sub-type
                            PolygonSubType subType = shapeChecker.CheckPolygonSubType(corners);

                            Pen pen;

                            if (subType == PolygonSubType.Unknown)
                            {
                                pen = (corners.Count == 4) ? redPen : bluePen;
                            }
                            else
                            {
                                pen = (corners.Count == 4) ? brownPen : greenPen;
                            }

                            g.DrawPolygon(pen, ToPointsArray(corners));
                        }
                    }
                }

                yellowPen.Dispose();
                redPen.Dispose();
                greenPen.Dispose();
                bluePen.Dispose();
                brownPen.Dispose();
                g.Dispose();
            }
        }
示例#4
0
        public void nesnebul(Bitmap image)
        {
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinWidth     = 5;
            blobCounter.MinHeight    = 5;
            blobCounter.FilterBlobs  = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            BitmapData     objectsData     = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);
            Grayscale      grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage       = grayscaleFilter.Apply(new UnmanagedImage(objectsData));

            image.UnlockBits(objectsData);
            blobCounter.ProcessImage(image);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Blob[]      blobs = blobCounter.GetObjectsInformation();
            pictureBox2.Image = image;
            if (rdiobtnCokCisimTakibi.Checked)
            {
                for (int i = 0; rects.Length > i; i++)
                {
                    Rectangle objectRect = rects[i];
                    Graphics  g          = pictureBox1.CreateGraphics();
                    if (objectRect.Width * objectRect.Height < 2000 && objectRect.Width * objectRect.Height > 1000)
                    {
                        using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                        {
                            g.DrawRectangle(pen, objectRect);
                            g.DrawString((i + 1).ToString(), new Font("Arial", 12), Brushes.Red, objectRect);
                        }
                        //Cizdirilen Dikdörtgenin Koordinatlari aliniyor.
                        int objectX = objectRect.X + (objectRect.Width / 2);
                        int objectY = objectRect.Y + (objectRect.Height / 2);
                        //g.DrawString(objectX.ToString() + "X" + objectY.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));
                        //g.DrawString(objectRect.Width.ToString() + "X" + objectRect.Height.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));
                        //label1.Text = objectRect.Width.ToString();
                        //label2.Text = objectRect.Height.ToString();
                        //Control.CheckForIllegalCrossThreadCalls = false;

                        if (objectY < 80)
                        {
                            if (objectX < 160)
                            {
                                WriteToPort("a");
                            }
                            else
                            {
                                WriteToPort("d");
                            }
                        }
                        else if (objectY > 160)
                        {
                            if (objectX > 160)
                            {
                                WriteToPort("c");
                            }
                            else
                            {
                                WriteToPort("f");
                            }
                        }
                        else
                        {
                            if (objectX < 160)
                            {
                                WriteToPort("b");
                            }
                            else
                            {
                                WriteToPort("e");
                            }
                        }
                    }
                    g.Dispose();
                }
            }
        }
示例#5
0
        public void nesnebul(Bitmap goruntu)
        {
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinWidth     = 5;
            blobCounter.MinHeight    = 5;
            blobCounter.FilterBlobs  = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            BitmapData     objectsData     = goruntu.LockBits(new Rectangle(0, 0, goruntu.Width, goruntu.Height), ImageLockMode.ReadOnly, goruntu.PixelFormat);
            Grayscale      grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage       = grayscaleFilter.Apply(new UnmanagedImage(objectsData));

            goruntu.UnlockBits(objectsData);


            blobCounter.ProcessImage(goruntu);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Blob[]      blobs = blobCounter.GetObjectsInformation();
            pictureBox2.Image = goruntu;



            if (rdiobtnTekCisimTakibi.Checked)
            {
                //Tekli cisim Takibi Single Tracking--------

                foreach (Rectangle recs in rects)
                {
                    if (rects.Length > 0)
                    {
                        Rectangle nesnedikd = rects[0];
                        //Graphics g = Graphics.FromImage(goruntu);
                        Graphics g = pictureBox1.CreateGraphics();
                        using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                        {
                            g.DrawRectangle(pen, nesnedikd);
                        }
                        //Cizdirilen Dikdörtgenin Koordinatlari aliniyor.
                        int nesnex = nesnedikd.X + (nesnedikd.Width / 2);
                        int nesney = nesnedikd.Y + (nesnedikd.Height / 2);
                        //  g.DrawString(nesnex.ToString() + "X" + objectY.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));

                        g.Dispose();

                        if (nesnex <= 120 && nesney <= 80)
                        {
                            ardino.Write("1");
                        }
                        else if (nesnex > 120 && nesnex < 240 && nesney <= 80)
                        {
                            ardino.Write("2");
                        }
                        else if (nesnex > 240 && nesnex < 360 && nesney <= 80)
                        {
                            ardino.Write("3");
                        }
                        else if (nesnex <= 120 && nesney > 80 && nesney < 160)
                        {
                            ardino.Write("4");
                        }
                        else if (nesnex > 120 && nesnex < 240 && nesney > 80 && nesney < 160)

                        {
                            ardino.Write("5");
                        }

                        else if (nesnex > 240 && nesnex < 360 && nesney > 80 && nesney < 160)
                        {
                            ardino.Write("6");
                        }

                        else if (nesnex <= 120 && nesney > 160 && nesney < 240)
                        {
                            ardino.Write("7");
                        }
                        else if (nesnex > 120 && nesnex < 240 && nesney > 160 && nesney < 240)

                        {
                            ardino.Write("8");
                        }
                        else if (nesnex > 240 && nesnex < 360 && nesney > 160 && nesney < 240)
                        {
                            ardino.Write("9");
                        }
                    }
                }
            }
        }
示例#6
0
        public void findObjects(Bitmap image1, Bitmap image2) //find object(s)
        {
            BlobCounter blobCounter1 = new BlobCounter();

            blobCounter1.MinWidth     = 5;
            blobCounter1.MinHeight    = 5;
            blobCounter1.FilterBlobs  = true;
            blobCounter1.ObjectsOrder = ObjectsOrder.Size;

            //----------------------------------

            BlobCounter blobCounter2 = new BlobCounter();

            blobCounter2.MinWidth     = 5;
            blobCounter2.MinHeight    = 5;
            blobCounter2.FilterBlobs  = true;
            blobCounter2.ObjectsOrder = ObjectsOrder.Size;

            BitmapData objectsData1 = image1.LockBits(new Rectangle(0, 0, image1.Width, image1.Height), ImageLockMode.ReadOnly, image1.PixelFormat);
            // grayscaling
            Grayscale      grayscaleFilter1 = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage1       = grayscaleFilter1.Apply(new UnmanagedImage(objectsData1));

            // unlock image
            image1.UnlockBits(objectsData1);

            BitmapData objectsData2 = image1.LockBits(new Rectangle(0, 0, image1.Width, image1.Height), ImageLockMode.ReadOnly, image1.PixelFormat);
            // grayscaling
            Grayscale      grayscaleFilter2 = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage2       = grayscaleFilter2.Apply(new UnmanagedImage(objectsData2));

            // unlock image
            image1.UnlockBits(objectsData2);


            blobCounter1.ProcessImage(image1);
            Rectangle[] rects1 = blobCounter1.GetObjectsRectangles();
            Blob[]      blobs1 = blobCounter1.GetObjectsInformation();

            blobCounter2.ProcessImage(image2);
            Rectangle[] rects2 = blobCounter2.GetObjectsRectangles();
            Blob[]      blobs2 = blobCounter2.GetObjectsInformation();

            if (rdiobtnsingleobject.Checked)
            {
                //Single object Tracking--------
                Graphics g = pictureBox1.CreateGraphics();
                if (rects1.Length > 0)
                {
                    Rectangle objectRect1 = rects1[0];
                    using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                    {
                        g.DrawRectangle(pen, objectRect1);
                    }
                }
                if (rects2.Length > 0)
                {
                    Rectangle objectRect2 = rects2[0];
                    using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                    {
                        g.DrawRectangle(pen, objectRect2);
                    }
                }
                g.Dispose();
            }



            if (rdiobtnMultipleObjects.Checked)
            {
                //Multi tracking-------
                for (int i = 0; rects1.Length > i; i++)
                {
                    Rectangle objectRect = rects1[i];
                    Graphics  g          = pictureBox1.CreateGraphics();
                    using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                    {
                        g.DrawRectangle(pen, objectRect);
                        g.DrawString((i + 1).ToString(), new Font("Arial", 12), Brushes.Red, objectRect);
                    }
                    int objectX = objectRect.X + (objectRect.Width / 2);
                    int objectY = objectRect.Y + (objectRect.Height / 2);
                    g.Dispose();
                }
            }

            if (rdiobtnGeoShape.Checked)
            {
                SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

                int circles   = 0;
                int squares   = 0;
                int triangles = 0;

                Graphics g         = pictureBox1.CreateGraphics();
                Pen      yellowPen = new Pen(Color.Yellow, 2); // circles
                Pen      redPen    = new Pen(Color.Red, 2);    // quadrilateral
                Pen      brownPen  = new Pen(Color.Brown, 2);  // quadrilateral with known sub-type
                Pen      greenPen  = new Pen(Color.Green, 2);  // known triangle
                Pen      bluePen   = new Pen(Color.Blue, 2);   // triangle
                for (int i = 0, n = blobs1.Length; i < n; i++)
                {
                    List <IntPoint> edgePoints = blobCounter1.GetBlobsEdgePoints(blobs1[i]);
                    AForge.Point    center;
                    float           radius;

                    // is circle ?
                    if (shapeChecker.IsCircle(edgePoints, out center, out radius))
                    {
                        g.DrawEllipse(yellowPen,
                                      (float)(center.X - radius), (float)(center.Y - radius),
                                      (float)(radius * 2), (float)(radius * 2));
                        circles++;
                    }
                    else
                    {
                        List <IntPoint> corners;

                        // is triangle or quadrilateral
                        if (shapeChecker.IsConvexPolygon(edgePoints, out corners))
                        {
                            // get sub-type
                            PolygonSubType subType = shapeChecker.CheckPolygonSubType(corners);

                            Pen pen;

                            if (subType == PolygonSubType.Unknown)
                            {
                                if (corners.Count == 4)
                                {
                                    pen = redPen;
                                }
                                else
                                {
                                    pen = bluePen;
                                    triangles++;
                                }
                            }
                            else
                            {
                                if (corners.Count == 4)
                                {
                                    pen = brownPen;
                                    squares++;
                                }
                                else
                                {
                                    pen = greenPen;
                                    triangles++;
                                }
                            }

                            g.DrawPolygon(pen, ToPointsArray(corners));
                        }
                    }
                }
                g.DrawString("circles: " + circles.ToString() + " squares: " + squares.ToString() + " triangles: " + triangles.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(0, 0));
                triangles = 0;
                circles   = 0;
                squares   = 0;
                yellowPen.Dispose();
                redPen.Dispose();
                greenPen.Dispose();
                bluePen.Dispose();
                brownPen.Dispose();
                g.Dispose();
            }
        }
示例#7
0
        public void nesnebul(Bitmap image)
        {
            BlobCounter blobCounter = new BlobCounter();

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

            BitmapData objectsData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);

            Grayscale      grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage       = grayscaleFilter.Apply(new UnmanagedImage(objectsData));

            image.UnlockBits(objectsData);


            blobCounter.ProcessImage(image);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Blob[]      blobs = blobCounter.GetObjectsInformation();
            pictureBox2.Image = image;



            //Cisim Takibi

            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);
                    }
                    //Cizdirilen Dikdörtgenin Koordinatlari aliniyor.
                    int objectX = objectRect.X + (objectRect.Width / 2);
                    int objectY = objectRect.Y + (objectRect.Height / 2);

                    g.Dispose();

                    if (objectX > 0 && objectX < 106 && objectY < 80)
                    {
                        Console.WriteLine("nesne sol kösede kor:" + objectX + "," + objectY);

                        serialPort1.Write("1");
                    }
                    if (objectX > 106 && objectX < 212 && objectY < 80)
                    {
                        Console.WriteLine("nesne ortada kor:" + objectX + "," + objectY);
                        serialPort1.Write("2");
                    }
                    if (objectX > 212 && objectX < 320 && objectY < 80)
                    {
                        Console.WriteLine("nesne sagda kösede kor:" + objectX + "," + objectY);
                        serialPort1.Write("3");
                    }

                    if (objectX > 0 && objectX < 106 && objectY > 80 && objectY < 160)
                    {
                        Console.WriteLine("nesne sol ortada kor:" + objectX + "," + objectY);
                        serialPort1.Write("4");
                    }
                    if (objectX > 107 && objectX < 211 && objectY > 80 && objectY < 160)
                    {
                        Console.WriteLine("nesne ortada kor:" + objectX + "," + objectY);
                        serialPort1.Write(" 5 ");
                    }

                    if (objectX > 212 && objectX < 320 && objectY > 80 && objectY < 160)
                    {
                        Console.WriteLine("nesne sağ ortada kor:" + objectX + "," + objectY);
                        serialPort1.Write("6");
                    }

                    if (objectX > 0 && objectX < 106 && objectY > 160 && objectY < 240)
                    {
                        Console.WriteLine("nesne sol alt köşede kor:" + objectX + "," + objectY);
                        serialPort1.Write("7");
                    }
                    if (objectX > 106 && objectX < 212 && objectY > 160 && objectY < 240)
                    {
                        Console.WriteLine("nesne alt ortada kor:" + objectX + "," + objectY);
                        serialPort1.Write("8");
                    }
                    if (objectX > 212 && objectX < 320 && objectY > 160 && objectY < 240)
                    {
                        Console.WriteLine("nesne sağ altta kor:" + objectX + "," + objectY);
                        serialPort1.Write("9");
                    }



                    if (chkKoordinatiGoster.Checked)
                    {
                        this.Invoke((MethodInvoker) delegate
                        {
                            richTextBox1.Text = objectRect.Location.ToString() + "\n" + richTextBox1.Text + "\n";;
                        });
                    }
                }
            }
        }
示例#8
0
        private void hedef(Bitmap res)
        {
            BlobCounter blop = new BlobCounter();

            blop.MinWidth     = 20;
            blop.MinHeight    = 20;
            blop.FilterBlobs  = true;
            blop.ObjectsOrder = ObjectsOrder.Size;

            Grayscale grı    = new Grayscale(0.2125, 0.7154, 0.0721);
            Bitmap    grıres = grı.Apply(res);

            blop.ProcessImage(grıres);
            Rectangle[] rec = blop.GetObjectsRectangles();
            foreach (Rectangle recs in rec)
            {
                if (rec.Length > 0)
                {
                    Rectangle nesneRect = rec[0];
                    Graphics  b         = Graphics.FromImage(res);
                    using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                    {
                        b.DrawRectangle(pen, nesneRect);
                    }
                    int nesneX = nesneRect.X + (nesneRect.Width / 2);
                    int nesneY = nesneRect.Y + (nesneRect.Height / 2);
                    b.DrawString(nesneX.ToString() + "X" + nesneY.ToString(), new Font("Times New Roman", 50), Brushes.White, new System.Drawing.Point(0, 0));
                    b.Dispose();
                    if (nesneX > 0 && nesneX <= 213 && nesneY > 0 && nesneY <= 153)
                    {
                        ld = 2;
                    }
                    else if (nesneX > 213 && nesneX <= 426 && nesneY > 0 && nesneY <= 153)
                    {
                        ld = 3;
                    }
                    else if (nesneX > 426 && nesneX <= 640 && nesneY > 0 && nesneY <= 153)
                    {
                        ld = 4;
                    }
                    else if (nesneX > 0 && nesneX <= 213 && nesneY > 153 && nesneY <= 256)
                    {
                        ld = 5;
                    }
                    else if (nesneX > 213 && nesneX <= 426 && nesneY > 153 & nesneY <= 256)
                    {
                        ld = 6;
                    }
                    else if (nesneX > 426 && nesneX <= 640 && nesneY > 153 && nesneY <= 256)
                    {
                        ld = 7;
                    }
                    else if (nesneX > 0 && nesneX <= 213 && nesneY > 256 && nesneY <= 460)
                    {
                        ld = 8;
                    }
                    else if (nesneX > 213 && nesneX <= 426 && nesneY > 256 && nesneY <= 460)
                    {
                        ld = 9;
                    }
                    else if (nesneX > 426 && nesneX <= 640 && nesneY > 256 && nesneY <= 460)
                    {
                        ld = 10;
                    }
                    if (oncekı != ld)
                    {
                        oncekı = ld;
                        if (serialPort1.IsOpen)
                        {
                            serialPort1.Write(ld.ToString());
                        }
                    }
                }
            }
        }
示例#9
0
        private void cevreal(Bitmap image)// Algilanan rengi Çevrçevelemek veya hedeflemek için gerekli Method.
        {
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinWidth     = 20;
            blobCounter.MinHeight    = 20;
            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 nesneRect = rects[0];
                    //Graphics g = pictureBox2.CreateGraphics();
                    Graphics g = Graphics.FromImage(image);
                    using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                    {
                        g.DrawRectangle(pen, nesneRect);
                    }

                    int nesneX = nesneRect.X + (nesneRect.Width / 2);  //Dikdörtgenin Koordinatlari alınır.
                    int nesneY = nesneRect.Y + (nesneRect.Height / 2); //Dikdörtgenin Koordinatlari alınır.
                    g.DrawString(nesneX.ToString() + "X" + nesneY.ToString(), new Font("Arial", 50), Brushes.White, new System.Drawing.Point(0, 0));
                    g.Dispose();

                    if (nesneX > 0 && nesneX <= 426 && nesneY > 0 && nesneY <= 240)
                    {
                        led = 2;
                    }
                    else if (nesneX > 426 && nesneX <= 852 && nesneY > 0 && nesneY <= 240)
                    {
                        led = 3;
                    }
                    else if (nesneX > 852 && nesneX <= 1280 && nesneY > 0 && nesneY <= 240)
                    {
                        led = 4;
                    }
                    else if (nesneX > 0 && nesneX <= 426 && nesneY > 240 && nesneY <= 480)
                    {
                        led = 5;
                    }
                    else if (nesneX > 426 && nesneX <= 852 && nesneY > 240 && nesneY <= 480)
                    {
                        led = 6;
                    }
                    else if (nesneX > 852 && nesneX <= 1280 && nesneY > 240 && nesneY <= 480)
                    {
                        led = 7;
                    }
                    else if (nesneX > 0 && nesneX <= 426 && nesneY > 480 && nesneY <= 720)
                    {
                        led = 8;
                    }
                    else if (nesneX > 426 && nesneX <= 852 && nesneY > 480 && nesneY <= 720)
                    {
                        led = 9;
                    }
                    else if (nesneX > 852 && nesneX <= 1280 && nesneY > 480 && nesneY <= 720)
                    {
                        led = 10;
                    }
                    if (gecici != led)
                    {
                        gecici = led;
                        if (serialPort1.IsOpen)
                        {
                            serialPort1.Write(led.ToString());
                        }
                    }
                }
            }
        }
示例#10
0
        public void nesnebul(Bitmap image)
        {
            BlobCounter blobCounter = new BlobCounter();

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


            BitmapData objectsData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);

            Grayscale      grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage       = grayscaleFilter.Apply(new UnmanagedImage(objectsData));

            image.UnlockBits(objectsData);
            blobCounter.ProcessImage(image);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Blob[]      blobs = blobCounter.GetObjectsInformation();
            pictureBox2.Image = image;
            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);
                    }

                    int objectX = objectRect.X + (objectRect.Width / 2);
                    int objectY = objectRect.Y + (objectRect.Height / 2);

                    g.Dispose();


                    this.Invoke((MethodInvoker) delegate
                    {
                        richTextBox1.Text = objectRect.Location.ToString() + "\n" + richTextBox1.Text + "\n";;
                    });

                    if ((0 <= objectX && objectX < 105) && (0 <= objectY && objectY < 80))
                    {
                        serialPort2.Write("2");
                    }
                    if ((105 <= objectX && objectX < 210) && (0 < objectY && objectY < 80))
                    {
                        serialPort2.Write("3");
                    }
                    if ((210 <= objectX && objectX <= 320) && (0 < objectY && objectY < 80))
                    {
                        serialPort2.Write("4");
                    }


                    if ((0 <= objectX && objectX < 105) && (80 <= objectY && objectY < 160))
                    {
                        serialPort2.Write("5");
                    }
                    if ((105 <= objectX && objectX < 210) && (80 <= objectY && objectY < 160))
                    {
                        serialPort2.Write("6");
                    }
                    if ((210 <= objectX && objectX <= 320) && (80 <= objectY && objectY < 160))
                    {
                        serialPort2.Write("7");
                    }


                    if ((0 < objectX && objectX < 105) && (160 <= objectY && objectY <= 240))
                    {
                        serialPort2.Write("8");
                    }
                    if ((105 <= objectX && objectX < 210) && (160 <= objectY && objectY <= 240))
                    {
                        serialPort2.Write("9");
                    }
                    if ((210 < objectX && objectX < 320) && (160 < objectY && objectY < 240))
                    {
                        serialPort2.Write("1");
                        Console.WriteLine("text");
                    }
                }
            }
        }
示例#11
0
        public void nesnebul(Bitmap image)
        {
            BlobCounter blobCounter = new BlobCounter();

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

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

            image.UnlockBits(objectsData);


            blobCounter.ProcessImage(image);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Blob[]      blobs = blobCounter.GetObjectsInformation();
            pictureBox2.Image = image;



            if (rdiobtnTekCisimTakibi.Checked)
            {
                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);
                        }

                        int objectX = objectRect.X + (objectRect.Width / 2);
                        int objectY = objectRect.Y + (objectRect.Height / 2);

                        g.Dispose();


                        this.Invoke((MethodInvoker) delegate
                        {
                            if (objectX >= 0 && 110 > objectX)
                            {
                                serialPort1.Write("2");
                            }

                            else if (objectX >= 110 && objectX < 210)
                            {
                                serialPort1.Write("3");
                            }

                            else if (objectX >= 210 && objectX < 320)
                            {
                                serialPort1.Write("1");
                            }



                            richTextBox1.Text = objectRect.Location.ToString() + "\n" + richTextBox1.Text + "\n";;
                        });
                    }
                }
            }
        }
        public void nesnebul(Bitmap image)
        {
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinWidth     = 5;
            blobCounter.MinHeight    = 5;
            blobCounter.FilterBlobs  = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            //Grayscale griFiltre = new Grayscale(0.2125, 0.7154, 0.0721);
            //Grayscale griFiltre = new Grayscale(0.2, 0.2, 0.2);
            //Bitmap griImage = griFiltre.Apply(image);

            BitmapData objectsData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);
            // grayscaling
            Grayscale      grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage       = grayscaleFilter.Apply(new UnmanagedImage(objectsData));

            // unlock image
            image.UnlockBits(objectsData);


            blobCounter.ProcessImage(image);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Blob[]      blobs = blobCounter.GetObjectsInformation();
            pictureBox2.Image = image;



            if (rdiobtnTekCisimTakibi.Checked)
            {
                //Tekli cisim Takibi Single Tracking--------

                foreach (Rectangle recs in rects)
                {
                    if (rects.Length > 0)
                    {
                        Rectangle objectRect = rects[0];
                        //Graphics g = Graphics.FromImage(image);
                        Graphics g = pictureBox1.CreateGraphics();
                        using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                        {
                            g.DrawRectangle(pen, objectRect);
                        }
                        //Cizdirilen Dikdörtgenin Koordinatlari aliniyor.
                        int objectX = objectRect.X + (objectRect.Width / 2);
                        int objectY = objectRect.Y + (objectRect.Height / 2);
                        //  g.DrawString(objectX.ToString() + "X" + objectY.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));
                        g.Dispose();


                        this.Invoke((MethodInvoker) delegate
                        {
                            if (objectX < 105 && objectY < 80)
                            {
                                serialPort1.Write("a");
                            }
                            else if ((105 < objectX) && (objectX < 215) && (objectY < 80))
                            {
                                serialPort1.Write("b");
                            }
                            else if ((215 < objectX) && (objectX < 320) && (objectY < 80))
                            {
                                serialPort1.Write("c");
                            }

                            else if ((objectX < 105) && (80 < objectY) && (objectY < 160))
                            {
                                serialPort1.Write("d");
                            }
                            else if ((105 < objectX) && (objectX < 215) && (80 < objectY) && (objectY < 160))
                            {
                                serialPort1.Write("e");
                            }
                            else if ((215 < objectX) && (objectX < 320) && (80 < objectY) && (objectY < 160))
                            {
                                serialPort1.Write("f");
                            }
                            else if ((objectX < 105) && (160 < objectY) && (objectY < 240))
                            {
                                serialPort1.Write("g");
                            }
                            else if ((105 < objectX) && (objectX < 215) && (160 < objectY) && (objectY < 240))
                            {
                                serialPort1.Write("h");
                            }
                            else if ((215 < objectX) && (objectX < 320) && (160 < objectY) && (objectY < 240))
                            {
                                serialPort1.Write("i");
                            }



                            richTextBox1.Text = objectRect.Location.ToString() + "\n" + richTextBox1.Text + "\n";;
                        });
                    }
                }
            }
        }
示例#13
0
        private void videoSourcePlayer2_NewFrame_1(object sender, ref Bitmap image)
        {
            if (filtro == true)
            {
                //Threshold filter = new Threshold(5000);
                //filter.ApplyInPlace(image);
                //IterativeThreshold filter = new IterativeThreshold(2, 128);
                //Bitmap newImage = filter.Apply(image);
                //Bitmap grayImage = Grayscale.CommonAlgorithms.BT709.Apply(image);

                //Bitmap video = (Bitmap)eventArgs.Frame.Clone();
                //Bitmap video2 = (Bitmap)eventArgs.Frame.Clone();
                //Bitmap objectsImage = null;
                //EuclideanColorFiltering filter = new EuclideanColorFiltering();
                //filter.CenterColor = Color.FromArgb(5,5,5);
                // filter.Radius = 100;
                ColorFiltering filtrado = new ColorFiltering();
                filtrado.Red   = new AForge.IntRange(red, (int)numericUpDown1.Value);
                filtrado.Green = new AForge.IntRange(green, (int)numericUpDown2.Value);
                filtrado.Blue  = new AForge.IntRange(blue, (int)numericUpDown3.Value);
                filtrado.ApplyInPlace(image);
                // Creacion de la escala blanco y negro
                // BitmapData objectsData = image.LockBits (new Rectangle (0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);
                Grayscale grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
                //UnmanagedImage grayImage = grayscaleFilter.Apply (new UnmanagedImage (objectsData));
                // image.UnlockBits (objectsData);

                //GrayscaleBT709 grayscaleFilter = new GrayscaleBT709( ); OBSOLETO.
                // Aplico filtro blanco y negro al cuadro de la webcam
                Bitmap grayImage = grayscaleFilter.Apply(image);
                // BitmapData objectsData = objectsImage.LockBits(new Rectangle(0, 0, image.Width, image.Height),

                //  ImageLockMode.ReadOnly, image.PixelFormat);

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

                // contador blob
                BlobCounter blobCounter = new BlobCounter();
                //// configuración de los filtros del rectangulo
                blobCounter.MinWidth    = 10;
                blobCounter.MinHeight   = 10;
                blobCounter.FilterBlobs = true;
                // // Ordena por objeto mayor
                blobCounter.ObjectsOrder = ObjectsOrder.Size;

                //// blobs
                blobCounter.ProcessImage(grayImage);
                Rectangle[] rects = blobCounter.GetObjectsRectangles();

                //// Captura el objeto mayor
                if (rects.Length > 0)
                {
                    Rectangle objectRect = rects[0];
                    Graphics  g          = Graphics.FromImage(image);

                    using (Pen pen = new Pen(Color.FromArgb(160, 255, 160), 3))
                    {
                        //Creación de estadísticas X e Y como tambien estadísticas de tamaño.
                        //Dibujo del rectangulo
                        g.DrawRectangle(pen, objectRect);
                        PointF drawPoin = new PointF(objectRect.X, objectRect.Y);
                        //posición del rectánculo
                        int objectX = objectRect.X + objectRect.Width / 2 - image.Width / 2;
                        int objectY = image.Height / 2 - (objectRect.Y + objectRect.Height / 2);
                        //Estadísticas
                        String Blobinformation = "Eje X= " + objectX.ToString() + "\nEje Y= " + objectY.ToString() + "\nTamaño=" + objectRect.Size.ToString() + "\nLocalización=" + objectRect.Location.ToString();
                        g.DrawString(Blobinformation, new Font("Arial", 16), new SolidBrush(Color.Red), drawPoin);
                    }

                    g.Dispose();


                    //}
                    // else
                    //{

                    //     if(!showObjectsOnly)
                    //    {

                    //        objectsImage.Dispose();
                    //    }
                    //  grayImage.Dispose();

                    //}

                    //        }

                    //    }

                    //}


                    //Detección de objetos
                }
            }
        }
示例#14
0
        public void objebulma(Bitmap goruntu)
        {
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinWidth     = 5;
            blobCounter.MinHeight    = 5;
            blobCounter.FilterBlobs  = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            BitmapData     objectsData     = goruntu.LockBits(new Rectangle(0, 0, goruntu.Width, goruntu.Height), ImageLockMode.ReadOnly, goruntu.PixelFormat);
            Grayscale      grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage       = grayscaleFilter.Apply(new UnmanagedImage(objectsData));

            goruntu.UnlockBits(objectsData);


            blobCounter.ProcessImage(goruntu);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Blob[]      blobs = blobCounter.GetObjectsInformation();
            pictureBox2.Image = goruntu;

            if (rdiobtnTekCisimTakibi.Checked)
            {
                //Tekli cisim Takibi
                foreach (Rectangle recs in rects)
                {
                    if (rects.Length > 0)
                    {
                        Rectangle nesndikd = rects[0];

                        Graphics g = pictureBox1.CreateGraphics();
                        using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                        {
                            g.DrawRectangle(pen, nesndikd);
                        }
                        //Cizdirilen Dikdörtgenin Koordinatlari aliniyor.
                        int nesnex = nesndikd.X + (nesndikd.Width / 2);
                        int nesney = nesndikd.Y + (nesndikd.Height / 2);
                        g.Dispose();

                        if (nesnex > 100 && nesnex <= 200)
                        {
                            ardino.Write("c");
                        }
                        else if (nesnex <= 100)
                        {
                            ardino.Write("l");
                        }
                        else if (nesnex > 200)
                        {
                            ardino.Write("r");
                        }
                        if (nesney < 150)
                        {
                            ardino.Write("e");
                        }
                        else if (nesney > 300)
                        {
                            ardino.Write("f");
                        }

                        if (chkKoordinatiGoster.Checked)
                        {
                            this.Invoke((MethodInvoker) delegate
                            {
                                richTextBox1.Text = nesndikd.Location.ToString() + "\n" + richTextBox1.Text + "\n";;
                            });
                        }
                    }
                }
            }
        }
示例#15
0
        public void nesnebul(Bitmap image)
        {
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinWidth     = 5;
            blobCounter.MinHeight    = 5;
            blobCounter.FilterBlobs  = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            BitmapData     objectsData     = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);
            Grayscale      grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage       = grayscaleFilter.Apply(new UnmanagedImage(objectsData));

            image.UnlockBits(objectsData);


            blobCounter.ProcessImage(image);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Blob[]      blobs = blobCounter.GetObjectsInformation();
            pictureBox2.Image = image;



            if (rdiobtnTekCisimTakibi.Checked)
            {
                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);
                        }

                        int objectX = objectRect.X + (objectRect.Width / 2);
                        int objectY = objectRect.Y + (objectRect.Height / 2);

                        g.Dispose();

                        if (objectX >= 0 && objectX <= 80 && objectY <= 110)
                        {
                            ardino.Write("1");
                        }
                        else if (objectX > 80 && objectX <= 160 && objectY <= 110)
                        {
                            ardino.Write("2");
                        }
                        else if (objectX > 160 && objectX <= 240 && objectY <= 110)
                        {
                            ardino.Write("3");
                        }
                        else if (objectX >= 0 && objectX <= 80 && objectY > 110 && objectY < 200)
                        {
                            ardino.Write("4");
                        }
                        else if (objectX > 80 && objectX <= 160 && objectY > 110 && objectY < 200)
                        {
                            ardino.Write("5");
                        }
                        else if (objectX > 160 && objectX <= 240 && objectY > 110 && objectY < 200)
                        {
                            ardino.Write("6");
                        }
                        else if (objectX > 0 && objectX <= 80 && objectY >= 200 && objectY < 330)
                        {
                            ardino.Write("7");
                        }
                        else if (objectX > 80 && objectX <= 160 && objectY >= 200 && objectY < 330)
                        {
                            ardino.Write("8");
                        }
                        else if (objectX > 160 && objectX <= 240 && objectY >= 200 && objectY < 330)
                        {
                            ardino.Write("9");
                        }
                    }
                }
            }
        }
示例#16
0
        public void nesnebul(Bitmap image)
        {
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinWidth     = 10;
            blobCounter.MinHeight    = 10;
            blobCounter.FilterBlobs  = true; // Parazitleri atar
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            BitmapData     objectsData     = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);
            Grayscale      grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
            UnmanagedImage grayImage       = grayscaleFilter.Apply(new UnmanagedImage(objectsData));

            image.UnlockBits(objectsData);
            blobCounter.ProcessImage(image);
            Rectangle[] rects = blobCounter.GetObjectsRectangles();
            Blob[]      blobs = blobCounter.GetObjectsInformation();
            pictureBox2.Image = image;
            if (radioButton1.Checked)
            {
                for (int i = 0; rects.Length > i; i++)
                {
                    Rectangle objectRect = rects[i];
                    Graphics  g          = pictureBox1.CreateGraphics();
                    if (objectRect.Width * objectRect.Height < 6500 && objectRect.Width * objectRect.Height > 3250)
                    {
                        using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                        {
                            g.DrawRectangle(pen, objectRect);
                            g.DrawString((i + 1).ToString(), new Font("Arial", 12), Brushes.Red, objectRect);
                        }

                        int objectX = objectRect.X + (objectRect.Width / 2);
                        int objectY = objectRect.Y + (objectRect.Height / 2);

                        if (objectY < 100)
                        {
                            if (objectX < 250)
                            {
                                WriteToPort("a");
                            }
                            else
                            {
                                WriteToPort("d");
                            }
                        }
                        else if (objectY > 200)
                        {
                            if (objectX > 250)
                            {
                                WriteToPort("c");
                            }
                            else
                            {
                                WriteToPort("f");
                            }
                        }
                        else
                        {
                            if (objectX < 250)
                            {
                                WriteToPort("b");
                            }
                            else
                            {
                                WriteToPort("e");
                            }
                        }
                    }
                    g.Dispose();
                }
            }
        }
示例#17
0
        private void button11_Click(object sender, EventArgs e)
        {
            var gray = new Grayscale(.3, .59, .11);

            pictureBox1.Image = gray.Apply(picture.bitmap);
        }