コード例 #1
0
        private void inputImage_MouseUp(object sender, MouseButtonEventArgs e)
        {
            inputImageCanvas.Children.Clear();
            isSelecting = false;
            endPos      = new Point(Math.Min(e.GetPosition(inputImage).X, inputImage.Width),
                                    Math.Min(e.GetPosition(inputImage).Y, inputImage.Height));
            Console.WriteLine("UP!" + endPos);

            int xRate = (int)(inputImage.Source.Width / inputImage.Width);
            int yRate = (int)(inputImage.Source.Height / inputImage.Height);

            selectingWindow = new System.Drawing.Rectangle(
                (int)startPos.X * xRate, (int)startPos.Y * yRate,
                (int)(endPos.X - startPos.X) * xRate, (int)(endPos.Y - startPos.Y) * yRate);

            trackStart  = true;
            objTracking = null;
        }
コード例 #2
0
        private void updateCamWorker(object sender, DoWorkEventArgs e)
        {
            using (Image <Bgr, Byte> frame = webcam.QueryFrame().Flip(Emgu.CV.CvEnum.FLIP.HORIZONTAL))
            {
                if (trackStart)
                {
                    if (objTracking == null)
                    {
                        objTracking = new ObjectTracking(frame, selectingWindow);
                    }
                    else
                    {
                        System.Drawing.Rectangle result = objTracking.Tracking(frame);

                        frame.Draw(result, new Bgr(0, 255, 0), 3);

                        Dispatcher.Invoke(DispatcherPriority.Normal,
                                          new Action(
                                              delegate()
                        {
                            if (objTracking != null)
                            {
                                inputImage.Source       = frame.ToBitmapSource();
                                hueImage.Source         = objTracking.hue.ToBitmapSource();
                                backprojectImage.Source = objTracking.backproject.ToBitmapSource();
                                maskImage.Source        = objTracking.mask.ToBitmapSource();
                            }
                        }
                                              ));
                    }
                }
                else
                {
                    Dispatcher.Invoke(DispatcherPriority.Normal,
                                      new Action(
                                          delegate()
                    {
                        inputImage.Source = frame.ToBitmapSource();
                    }
                                          ));
                }
            }
        }
コード例 #3
0
 private void Track_Click(object sender, RoutedEventArgs e)
 {
     trackStart      = true;
     objTracking     = null;
     flag_faceDected = true;
 }
コード例 #4
0
        private void updateCamWorker(object sender, DoWorkEventArgs e)
        {
            Image <Bgr, Byte> frame_1 = new Image <Bgr, Byte>(showVideo());

            using (Image <Bgr, Byte> frame = frame_1.Flip(Emgu.CV.CvEnum.FLIP.HORIZONTAL))
            //using (Image<Bgr, Byte> frame = webcam.QueryFrame().Flip(Emgu.CV.CvEnum.FLIP.HORIZONTAL))
            {
                // 人脸检测

                if (flag_faceDected)
                {
                    /*
                     * Image<Gray, Byte> gray = frame.Convert<Gray, Byte>(); //Convert it to Grayscale
                     * gray._EqualizeHist();//均衡化
                     * HaarCascade ccr = new HaarCascade(haarXmlPath);
                     * MCvAvgComp[] rects = ccr.Detect(gray, 1.1, 2, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,new System.Drawing.Size(20,20),System.Drawing.Size.Empty);
                     * //MCvAvgComp[] rects = ccr.Detect(gray, 1.3, 3, new System.Drawing.Size(20, 20), System.Drawing.Size.Empty);
                     * foreach (MCvAvgComp r in rects)
                     * {
                     *  //This will focus in on the face from the haar results its not perfect but it will remove a majoriy
                     *  //of the background noise
                     *  System.Drawing.Rectangle facesDetected = r.rect;
                     *
                     *  frame.Draw(facesDetected, new Bgr(System.Drawing.Color.Red), 3);//绘制检测框
                     *  Console.WriteLine("faceDected " + "(" + facesDetected.X + "," + facesDetected.Y + ")" + facesDetected.Width + " " + facesDetected.Height);
                     *
                     *  selectingWindow = facesDetected;
                     * }
                     */
                    frame.Save("0.jpg");
                    Process p = new Process();
                    p.StartInfo.FileName    = "HumanDection.exe";
                    p.StartInfo.Arguments   = "0.jpg seeta_fd_frontal_v1.0.bin";
                    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    p.Start();
                    p.WaitForExit();//关键,等待外部程序退出后才能往下执行

                    FileStream   fs = new FileStream("face.txt", FileMode.Open, FileAccess.Read);
                    StreamReader sr = new StreamReader(fs);
                    string       s  = sr.ReadLine();
                    fs.Close();
                    string[] strs = s.Split(' ');
                    selectingWindow.X      = int.Parse(strs[0]);
                    selectingWindow.Y      = int.Parse(strs[1]);
                    selectingWindow.Width  = int.Parse(strs[2]);
                    selectingWindow.Height = int.Parse(strs[3]);
                    frame.Draw(selectingWindow, new Bgr(System.Drawing.Color.Red), 3);//绘制检测框

                    flag_faceDected = false;
                }
                if (trackStart)
                {
                    if (objTracking == null)
                    {
                        objTracking = new ObjectTracking(frame, selectingWindow);
                    }
                    else
                    {
                        System.Drawing.Rectangle result = objTracking.Tracking(frame, this);

                        frame.Draw(result, new Bgr(0, 255, 0), 3);

                        // 进行小车控制逻辑的编写
                        int imageWidth  = frame.Width;
                        int imageHeight = frame.Height;

                        if (headImages >= 10)
                        {
                            ControlCar(result);
                        }
                        if (headImages++ >= 100000)
                        {
                            headImages = 100000;
                        }

                        Dispatcher.Invoke(DispatcherPriority.Normal,
                                          new Action(
                                              delegate()
                        {
                            if (objTracking != null)
                            {
                                inputImage.Source       = frame.ToBitmapSource();
                                hueImage.Source         = objTracking.hue.ToBitmapSource();
                                backprojectImage.Source = objTracking.backproject.ToBitmapSource();
                                maskImage.Source        = objTracking.mask.ToBitmapSource();
                            }
                        }
                                              ));
                    }
                }
                else
                {
                    Dispatcher.Invoke(DispatcherPriority.Normal,
                                      new Action(
                                          delegate()
                    {
                        inputImage.Source = frame.ToBitmapSource();
                    }
                                          ));
                }
            }
        }