示例#1
0
        private void button3_Click(object sender, EventArgs e)
        {
            //tasklari tanimla
            //1. task kuyruga frame ekler
            Task take_frame = Task.Factory.StartNew(() =>
            {
                FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_Kuyruk);
            });

            //2.task otsu-gri
            Task otsu_gri = Task.Factory.StartNew(() =>
            {
                Bitmap reel;
                Bitmap otsu;

                while (true)
                {
                    if (!(ImageQueue.IsEmpty))
                    {
                        lock (_LOCK)
                        {
                            ImageQueue.TryDequeue(out reel);
                            otsu = (Bitmap)reel.Clone();
                            ImageQueue_reel.Enqueue(reel);
                            Otsu.otsu_uygulama(otsu);
                            ImageQueue_otsu.Enqueue(otsu);
                        }
                    }
                }
            });
            //3.task hand area
            Task handselect = Task.Factory.StartNew(() =>
            {
                Bitmap otsu;
                Bitmap otsu1;

                int[] koor = new int[4];

                while (true)
                {
                    if (!(ImageQueue_otsu.IsEmpty))
                    {
                        lock (_LOCK)
                        {
                            ImageQueue_otsu.TryDequeue(out otsu);
                            otsu1 = (Bitmap)otsu.Clone();
                            Mask  = new HandMask(otsu1);
                            Mask.HandSelect();



                            koor[0] = Mask.Koordinat[0]; //xmax
                            koor[1] = Mask.Koordinat[1]; //xmin
                            koor[2] = Mask.Koordinat[2]; //ymax
                            koor[3] = Mask.Koordinat[3]; //ymin


                            ImageQueue_hand.Enqueue(koor);



                            ImageQueue_otsu1.Enqueue(otsu1);
                        }
                    }
                }
            });

            ////4. task fingertrip
            Task finger_tip = Task.Factory.StartNew(() =>
            {
                Bitmap otsu;
                Bitmap otsu1;

                int[] koor_ = new int[4];


                while (true)
                {
                    if (!(ImageQueue_hand.IsEmpty) && !(ImageQueue_otsu1.IsEmpty))
                    {
                        lock (_LOCK)
                        {
                            ImageQueue_hand.TryDequeue(out koor_);



                            ImageQueue_otsu1.TryDequeue(out otsu);
                            otsu1 = (Bitmap)otsu.Clone();
                            Finger.finger_tip(otsu1, koor_[0], koor_[1], koor_[2], koor_[3]);
                            ImageQueue_finger.Enqueue(otsu1);
                            //  GC.Collect();
                            ImageQueue_hand1.Enqueue(koor_);
                        }
                    }
                }
            });


            Task fingertrip = Task.Factory.StartNew(() =>
            {
                Bitmap reel1;
                Bitmap reel2;
                //Bitmap reel3;
                Bitmap finger1;

                int[] koor_1 = new int[4];


                while (true)
                {
                    if (!(ImageQueue_hand1.IsEmpty) && !(ImageQueue_reel.IsEmpty) && !(ImageQueue_finger.IsEmpty))
                    {
                        lock (_LOCK)
                        {
                            ImageQueue_reel.TryDequeue(out reel1);
                            reel2 = (Bitmap)reel1.Clone();
                            ImageQueue_hand1.TryDequeue(out koor_1);


                            ImageQueue_finger.TryDequeue(out finger1);
                            finger1 = (Bitmap)finger1.Clone();

                            int[] parmak_xy = Finger.FingersFind(finger1, koor_1[0], koor_1[1], koor_1[2], koor_1[3]);

                            int[] parmak_x = new int[5];
                            int[] parmak_y = new int[5];
                            int[] parmaky1 = new int[5];
                            int[] parmakx1;
                            for (int k = 0; k < 5; k++)
                            {
                                parmak_y[k] = parmak_xy[k];
                            }
                            for (int k = 0; k < 5; k++)
                            {
                                parmak_x[k] = parmak_xy[k + 5];
                            }

                            parmakx1 = (int[])parmak_x.Clone();
                            int index;
                            Array.Sort(parmak_x);
                            for (int l = 0; l < 5; l++)
                            {
                                index       = parmakx1.ToList().IndexOf(parmak_x[l]);
                                parmaky1[l] = parmak_y[index];
                            }


                            parmak_y = parmaky1;

                            int boy  = koor_1[0] - koor_1[1];
                            int oran = boy / 5;



                            parmak_bolge1 = Finger.finger_degree(reel2, parmak_x, parmak_y, koor_1[0], koor_1[1], koor_1[2], koor_1[3]);



                            Graphics g            = Graphics.FromImage(reel2);
                            SolidBrush drawBrush  = new SolidBrush(Color.Red);
                            SolidBrush drawBrush1 = new SolidBrush(Color.Blue);
                            SolidBrush drawBrush2 = new SolidBrush(Color.Yellow);
                            SolidBrush drawBrush3 = new SolidBrush(Color.Orange);
                            SolidBrush drawBrush4 = new SolidBrush(Color.Green);

                            Pen mypen  = new Pen(Color.Red, 3);
                            Pen mypen1 = new Pen(Color.Blue, 3);
                            Pen mypen2 = new Pen(Color.Yellow, 3);
                            Pen mypen3 = new Pen(Color.Orange, 3);
                            Pen mypen4 = new Pen(Color.Green, 3);
                            Font font  = new Font("Arial", 24);
                            g.DrawRectangle(mypen, koor_1[1], koor_1[3], koor_1[0] - koor_1[1], koor_1[2] - koor_1[3]);


                            g.DrawEllipse(mypen, parmak_x[0], parmak_y[0], 2, 2);
                            g.DrawEllipse(mypen1, parmak_x[1], parmak_y[1], 2, 2);
                            g.DrawEllipse(mypen2, parmak_x[2], parmak_y[2], 2, 2);
                            g.DrawEllipse(mypen3, parmak_x[3], parmak_y[3], 2, 2);
                            g.DrawEllipse(mypen4, parmak_x[4], parmak_y[4], 2, 2);


                            g.DrawString(parmak_bolge1[0].ToString(), font, drawBrush, 2 * 1 * 10, 2);
                            g.DrawString(parmak_bolge1[1].ToString(), font, drawBrush1, 2 * 2 * 10, 2);
                            g.DrawString(parmak_bolge1[2].ToString(), font, drawBrush2, 2 * 3 * 10, 2);
                            g.DrawString(parmak_bolge1[3].ToString(), font, drawBrush3, 2 * 4 * 10, 2);
                            g.DrawString(parmak_bolge1[4].ToString(), font, drawBrush4, 2 * 5 * 10, 2);


                            gri_pcx.Image = reel2;
                        }
                    }
                }
            });
        }
示例#2
0
        private void button3_Click(object sender, EventArgs e)
        {
            //tasklari tanimla
            //1. task kuyruga frame ekler
            Task take_frame = Task.Factory.StartNew(() =>
            {
                FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_Kuyruk);

            });

            //2.task otsu-gri
            Task otsu_gri = Task.Factory.StartNew(() =>
            {
                Bitmap reel;
                Bitmap otsu;

                while (true)
                {
                    if (!(ImageQueue.IsEmpty))
                    {

                        lock (_LOCK)
                        {
                            ImageQueue.TryDequeue(out reel);
                            otsu = (Bitmap)reel.Clone();
                            ImageQueue_reel.Enqueue(reel);
                            Otsu.otsu_uygulama(otsu);
                            ImageQueue_otsu.Enqueue(otsu);
                        }

                    }
                }
            });
            //3.task hand area
            Task handselect = Task.Factory.StartNew(() =>
            {
                Bitmap otsu;
                Bitmap otsu1;

                int[] koor = new int[4];

                while (true)
                {
                    if (!(ImageQueue_otsu.IsEmpty) )
                    {

                        lock (_LOCK)
                        {
                            ImageQueue_otsu.TryDequeue(out otsu);
                            otsu1 = (Bitmap)otsu.Clone();
                            Mask = new HandMask(otsu1);
                            Mask.HandSelect();

                            koor[0] = Mask.Koordinat[0];//xmax
                            koor[1] = Mask.Koordinat[1];//xmin
                            koor[2] = Mask.Koordinat[2];//ymax
                            koor[3] = Mask.Koordinat[3];//ymin

                           ImageQueue_hand.Enqueue(koor);

                          ImageQueue_otsu1.Enqueue(otsu1);

                        }

                    }
                }
            });

            ////4. task fingertrip
            Task finger_tip = Task.Factory.StartNew(() =>
            {
                Bitmap otsu;
                Bitmap otsu1;

                int[] koor_ = new int[4];

                while (true)
                {
                    if (!(ImageQueue_hand.IsEmpty) && !(ImageQueue_otsu1.IsEmpty))
                    {

                        lock (_LOCK)
                        {
                            ImageQueue_hand.TryDequeue(out koor_);

                            ImageQueue_otsu1.TryDequeue(out otsu);
                            otsu1 = (Bitmap)otsu.Clone();
                            Finger.finger_tip(otsu1, koor_[0], koor_[1], koor_[2], koor_[3]);
                            ImageQueue_finger.Enqueue(otsu1);
                            //  GC.Collect();
                            ImageQueue_hand1.Enqueue(koor_);

                        }

                    }
                }
            });

            Task fingertrip = Task.Factory.StartNew(() =>
            {

                Bitmap reel1;
                Bitmap reel2;
                //Bitmap reel3;
                Bitmap finger1;

                int[] koor_1 = new int[4];

                while (true)
                {
                    if (!(ImageQueue_hand1.IsEmpty) && !(ImageQueue_reel.IsEmpty) && !(ImageQueue_finger.IsEmpty))
                    {

                        lock (_LOCK)
                        {
                            ImageQueue_reel.TryDequeue(out reel1);
                            reel2 = (Bitmap)reel1.Clone();
                            ImageQueue_hand1.TryDequeue(out koor_1);

                            ImageQueue_finger.TryDequeue(out finger1);
                            finger1 = (Bitmap)finger1.Clone();

                            int[] parmak_xy = Finger.FingersFind(finger1, koor_1[0], koor_1[1], koor_1[2], koor_1[3]);

                            int[] parmak_x = new int[5];
                            int[] parmak_y = new int[5];
                            int[] parmaky1 = new int[5];
                            int[] parmakx1;
                            for (int k = 0; k < 5; k++)
                            {
                                parmak_y[k] = parmak_xy[k];
                            }
                            for (int k = 0; k < 5; k++)
                            {
                                parmak_x[k] = parmak_xy[k + 5];
                            }

                            parmakx1 = (int[])parmak_x.Clone();
                            int index;
                            Array.Sort(parmak_x);
                            for (int l = 0; l < 5; l++)
                            {

                                index = parmakx1.ToList().IndexOf(parmak_x[l]);
                                parmaky1[l] = parmak_y[index];
                            }

                            parmak_y = parmaky1;

                            int boy = koor_1[0] - koor_1[1];
                            int oran = boy / 5;

                            parmak_bolge1 = Finger.finger_degree(reel2, parmak_x, parmak_y, koor_1[0], koor_1[1], koor_1[2], koor_1[3]);

                            Graphics g = Graphics.FromImage(reel2);
                            SolidBrush drawBrush = new SolidBrush(Color.Red);
                            SolidBrush drawBrush1 = new SolidBrush(Color.Blue);
                            SolidBrush drawBrush2 = new SolidBrush(Color.Yellow);
                            SolidBrush drawBrush3 = new SolidBrush(Color.Orange);
                            SolidBrush drawBrush4 = new SolidBrush(Color.Green);

                            Pen mypen = new Pen(Color.Red, 3);
                            Pen mypen1 = new Pen(Color.Blue, 3);
                            Pen mypen2= new Pen(Color.Yellow, 3);
                            Pen mypen3 = new Pen(Color.Orange, 3);
                            Pen mypen4 = new Pen(Color.Green, 3);
                            Font font = new Font("Arial", 24);
                            g.DrawRectangle(mypen, koor_1[1], koor_1[3], koor_1[0] - koor_1[1], koor_1[2] - koor_1[3]);

                            g.DrawEllipse(mypen, parmak_x[0], parmak_y[0], 2, 2);
                            g.DrawEllipse(mypen1, parmak_x[1], parmak_y[1], 2, 2);
                            g.DrawEllipse(mypen2, parmak_x[2], parmak_y[2], 2, 2);
                            g.DrawEllipse(mypen3, parmak_x[3], parmak_y[3], 2, 2);
                            g.DrawEllipse(mypen4, parmak_x[4], parmak_y[4], 2, 2);

                            g.DrawString(parmak_bolge1[0].ToString(), font, drawBrush, 2 * 1 * 10, 2);
                            g.DrawString(parmak_bolge1[1].ToString(), font, drawBrush1, 2 * 2 * 10, 2);
                            g.DrawString(parmak_bolge1[2].ToString(), font, drawBrush2, 2 * 3 * 10, 2);
                            g.DrawString(parmak_bolge1[3].ToString(), font, drawBrush3, 2 * 4 * 10, 2);
                            g.DrawString(parmak_bolge1[4].ToString(), font, drawBrush4, 2 * 5 * 10, 2);

                            gri_pcx.Image = reel2;

                        }
                    }
                }

            });
        }