void sensor_DepthFrameReady(AllFramesReadyEventArgs e)
        {
            using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
            {
                if (depthFrame == null)
                {
                    return;
                }

                //turn raw data into an array of distances;
                var depthArray = depthFrame.ToDepthArray();

                MidPointDistanceViaGetDistanceText.Text = depthFrame.GetDistance(depthFrame.Width / 2, depthFrame.Height / 2).ToString();

                //image
                DepthImageWithMinDistance.Source = depthArray.ToBitmapSource(depthFrame.Width, depthFrame.Height,
                                                                             _minDistance, Colors.Red);

                //image
                DepthImage.Source = depthFrame.ToBitmapSource();

                if (_saveDepthFrame)
                {
                    _saveDepthFrame = false;
                    depthFrame.ToBitmapSource().Save(DateTime.Now.ToString("yyyyMMddHHmmss") + "_depth.jpg", ImageFormat.Jpeg);
                }
            }
        }
Beispiel #2
0
        void RuntimeDepthFrameReady(AllFramesReadyEventArgs e)
        {
            using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
            {
                if (depthFrame == null)
                {
                    return;
                }

                //turn raw data into array of distances
                var depthArray = depthFrame.ToDepthArray();

                //get image
                DepthImage.Image = depthFrame.ToBitmap();

                //get midpoint
                MidPointDistanceViaGetDistanceText.Text = depthFrame.GetDistance(depthFrame.Width / 2, depthFrame.Height / 2).ToString();

                //image
                DepthImageWithMinDistance.Image = depthArray.ToBitmap(depthFrame.Width, depthFrame.Height, _minDistance, Color.FromArgb(255, 255, 0, 0));

                if (_saveDepthFrame)
                {
                    _saveDepthFrame = false;
                    depthFrame.ToBitmap().Save(DateTime.Now.ToString("yyyyMMddHHmmss") + "_depth.jpg", ImageFormat.Jpeg);
                }
            }
        }
Beispiel #3
0
        public void take1(object sender, EventArgs e)
        {
            if (running)
            {
                gray_image = My_Image.Convert <Gray, byte>();
                //imageBox1.Image = gray_image;
                //label2.Text = gray_image[100, 100].ToString();
                //cImage = capture.QueryFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);//capture immage
                //gray_image1 = cImage.Convert<Gray, byte>();//convert yo gray
                HaarCascade HaarCascadeXML = new HaarCascade("haarcascade_frontalface_alt2.xml");
                //var faces = HaarCascadeXML.Detect(gray_image1);
                MCvAvgComp[][] faces = (gray_image.DetectHaarCascade(
                                            HaarCascadeXML,
                                            1.3,
                                            5,
                                            Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                                            new Size(20, 20)));
                int     cnt   = 0;
                int     dist  = 0;
                int     distA = 0;
                int     dist1 = 0;
                int     i     = 0;
                Boolean fc    = false;
                if (disT)
                {
                    foreach (MCvAvgComp face in faces[0])
                    {
                        dist = imageFrame.GetDistance((face.rect.X + (face.rect.Width / 2)) / 2, (face.rect.Y + (face.rect.Height / 2)) / 2);
                        if (i == 0)
                        {
                            dist1 = dist;
                            cnt   = i;
                        }
                        else
                        {
                            if (dist1 > dist)
                            {
                                dist1 = dist;
                                cnt   = i;
                            }
                        }
                        i++;
                    }
                }
                i = 0;
                foreach (MCvAvgComp face in faces[0])
                {
                    fc = true;

                    if (disT && cnt == i)
                    {
                        PointF center = new PointF((face.rect.X + (face.rect.Width / 2)), face.rect.Y + (face.rect.Height / 2));
                        posY        = (face.rect.Y + (face.rect.Height / 2));
                        distA       = imageFrame.GetDistance((face.rect.X + (face.rect.Width / 2)) / 2, (face.rect.Y + (face.rect.Height / 2)) / 2);
                        label1.Text = distA.ToString();
                        CircleF circle = new CircleF(center, 5);
                        My_Image.Draw(circle, new Bgr(255, double.MaxValue, 0), 1);
                        My_Image.Draw(face.rect, new Bgr(0, double.MaxValue, 255), 3);
                        PosX = (face.rect.X + (face.rect.Width / 2));
                        //label2.Text = PosX.ToString();
                    }
                    else
                    {
                        My_Image.Draw(face.rect, new Bgr(0, double.MaxValue, 0), 3);
                    }

                    i++;
                }
                if (fc == false)
                {
                    posY = 160;
                    PosX = 320;
                    if (connectSp)
                    {
                        sp.WriteLine("s");
                        label2.Text = "s";
                    }
                    if (sensor.ElevationAngle != 0)
                    {
                        try
                        {
                            sensor.ElevationAngle = 0;
                        }
                        catch (System.Exception ex)
                        {
                            MessageBox.Show("faild to initiate");
                        }
                    }
                }
                else
                {
                    if (sensor.ElevationAngle <= 25 && posY <= 130)
                    {
                        try
                        {
                            sensor.ElevationAngle += 2;
                        }
                        catch (System.Exception ex)
                        {
                            MessageBox.Show("faild to UP");
                        }
                    }

                    else if (sensor.ElevationAngle >= (-25) && posY >= 190)
                    {
                        try
                        {
                            sensor.ElevationAngle -= 2;
                        }
                        catch (System.Exception ex)
                        {
                            MessageBox.Show("faild to DOWN");
                        }
                    }

                    else
                    {
                        if (connectSp && PosX >= 360)
                        {
                            sp.WriteLine("l");
                            label2.Text = "L";
                        }

                        else if (connectSp && PosX <= 280)
                        {
                            sp.WriteLine("r");
                            label2.Text = "R";
                        }
                        else if (connectSp && PosX < 360 && PosX > 280)
                        {
                            if (distA > 0)
                            {
                                sp.WriteLine("f");
                                label2.Text = "F";
                            }
                            else
                            {
                                sp.WriteLine("s");
                                label2.Text = "S";
                            }
                        }
                    }
                }
                i = 0;
                // label1.Text = imageFrame.GetDistance(imageFrame.Width / 2, imageFrame.Height / 2).ToString();
                imageBox1.Image = My_Image;

                // imageBox2.Image = cImage;
            }
        }