Exemplo n.º 1
0
        public void OnUpdate(Dictionary<string, object> bundle)
        {
            Image<Bgr, byte> image = bundle.GetImage("source");
              Image<Bgr, byte> smoothed = image.SmoothGaussian(3);
              _detector.Update(smoothed);

              Image<Gray, Byte> fg_mask = _detector.ForgroundMask;
              Image<Gray, Byte> fg_mask_morph = fg_mask.Erode(1).Dilate(1);

              // Fetch the interactor from the bundle
              IDataInteractor idi = bundle.GetInteractor();
              idi.Show("forground", fg_mask_morph);

              // Find contours
              _blobs.Clear();
              for (Contour<Point> c = fg_mask_morph.FindContours(); c != null; c = c.HNext) {
            Rectangle r = c.BoundingRectangle;
            int area = r.Width * r.Height;
            if (area > 20) {
              _blobs.Add(r);
            }
              }

              while (MergeTwoRectangles()) {
            ;
              }
        }
Exemplo n.º 2
0
        public void Execute(Dictionary<string, object> bundle)
        {
            Image<Bgr, byte> image = bundle.GetImage("source");
              image.Draw(new Rectangle(Point.Empty, image.Size), new Bgr(_color), _thickness);

              IDataInteractor idi = bundle.GetInteractor();
              idi.Show("camera input", image);
              idi.ExecutePendingEvents(this, bundle);
        }
Exemplo n.º 3
0
        public void OnSaveImage(Dictionary<string, object> bundle)
        {
            IDataInteractor idi = bundle.GetInteractor();

              FilePathInfo fni = new FilePathInfo();
              if (idi.Query("Choose the filename", fni)) {
            string path = System.IO.Path.Combine(fni.Directory, fni.Filename);
            bundle.GetImage("source").Save(path);
            idi.Show("Last Image Saved", path);
              }
        }
Exemplo n.º 4
0
        public void Execute(Dictionary<string, object> b)
        {
            IDataInteractor idi = b.GetInteractor();
              // Process all pending events, supplying them with the current bundle information
              idi.ExecutePendingEvents(this, b);

              Image<Bgr, byte> image = b.GetImage("source");
              foreach (Rectangle r in _blobs) {
            image.Draw(r, new Bgr(Color.Green), 2);
              }
        }
Exemplo n.º 5
0
        public void Execute(Dictionary<string, object> b)
        {
            while (_hc == null) {
            bool query_result = b.GetInteractor().Query("Please specify a correct cascade file", this);
            bool should_cancel = b.GetRuntime().StopRequested;

            if (!query_result || should_cancel) {
              b.GetRuntime().RequestStop();
              return;
            }
              }

              Image<Bgr, byte> i = b.GetImage("source");
              Image<Gray, byte> gray = i.Convert<Gray, byte>();

              foreach(MCvAvgComp comp in gray.DetectHaarCascade(_hc)[0]) {
            i.Draw(comp.rect, new Bgr(Color.Red), 4);
              }
        }
Exemplo n.º 6
0
        public void Execute(Dictionary<string, object> bundle)
        {
            // For illustration purposes, we detect the chessboard in each frame
              Image<Gray, byte> image = bundle.GetImage("source").Convert<Gray, byte>();
              PointF[] corners = null;

              bool found = CameraCalibration.FindChessboardCorners(
            image, _nr_corners,
            Emgu.CV.CvEnum.CALIB_CB_TYPE.ADAPTIVE_THRESH |
            Emgu.CV.CvEnum.CALIB_CB_TYPE.FILTER_QUADS |
            Emgu.CV.CvEnum.CALIB_CB_TYPE.NORMALIZE_IMAGE,
            out corners
              );
              if (found) {
            image.FindCornerSubPix(
              new System.Drawing.PointF[][] { corners },
              new System.Drawing.Size(5, 5),
              new System.Drawing.Size(-1, -1),
              new MCvTermCriteria(0.001));
              }

              bundle["pattern_found"] = found;
              bundle["pattern_corners"] = corners;

              bundle.GetInteractor().ExecutePendingEvents(this, bundle);

              QCV.Toolbox.Draw.OrderedPointList(bundle.GetImage("source"), corners, found ? Color.Green : Color.Red);
              if (found && bundle.ContainsKey("intrinsics")) {
            IntrinsicCameraParameters icp = bundle.Get<IntrinsicCameraParameters>("intrinsics");

            ExtrinsicCameraParameters ecp = CameraCalibration.FindExtrinsicCameraParams2(
              GenerateObjectCorners(),
              corners,
              icp);

            QCV.Toolbox.Draw.DrawExtrinsicFrame(bundle.GetImage("source"), ecp, icp);
              }
        }
Exemplo n.º 7
0
        public void OnCalibrate(Dictionary<string, object> bundle)
        {
            if (_image_points.Count >= 3) {
            IntrinsicCameraParameters icp = new IntrinsicCameraParameters();
            ExtrinsicCameraParameters[] ecp;

            Emgu.CV.CameraCalibration.CalibrateCamera(
              _object_points.ToArray(),
              _image_points.ToArray(),
              bundle.GetImage("source").Size,
              icp,
              Emgu.CV.CvEnum.CALIB_TYPE.DEFAULT,
              out ecp);

            bundle["intrinsics"] = icp;
              }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Execute the filter.
        /// </summary>
        /// <param name="b">Bundle of information</param>
        public void Execute(Dictionary<string, object> b)
        {
            if (_vw == null) {
            _vw = new VideoWriter(_path, _fps, _frame_width, _frame_height, true);
              }

              Image<Bgr, byte> i = b.GetImage(_bag_name);
              Size s = i.Size;
              if (s.Width != _frame_width || s.Height != _frame_height) {
            i = i.Resize(_frame_width, _frame_height, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
              }

              _vw.WriteFrame(i);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Execute the filter.
 /// </summary>
 /// <param name="b">Bundle of information</param>
 public void Execute(Dictionary<string, object> b)
 {
     Image<Bgr, byte> i = b.GetImage(_bundle_name);
       Base.IDataInteractor ii = b.GetInteractor();
       ii.Show(_show_name, i);
 }
Exemplo n.º 10
0
 public void Execute(Dictionary<string, object> bundle)
 {
     bundle.GetInteractor().Show("video", bundle.GetImage("source"));
 }