예제 #1
0
 public Context(
   Core.BuildingBlocks.Setup setup,
   Core.BuildingBlocks.FrameGrabber fg,
   Core.BuildingBlocks.RenderLoop rl, 
   UI.Concrete.EmbeddableStream es) 
 {
   _es = es;
   _setup = setup;
   _fg = fg;
   _rl = rl;
 }
예제 #2
0
 public Context(
     Core.BuildingBlocks.Setup setup,
     Core.BuildingBlocks.FrameGrabber fg,
     Core.BuildingBlocks.RenderLoop rl,
     UI.Concrete.EmbeddableStream es)
 {
     _es    = es;
     _setup = setup;
     _fg    = fg;
     _rl    = rl;
 }
예제 #3
0
        private void _btn_load_configuration_Click(object sender, EventArgs e)
        {
            if (_open_dlg.ShowDialog(this) == DialogResult.OK)
            {
                int device_index = -1;
                try {
                    _context.FrameGrabber.Stop();
                    device_index = _context.Setup.Camera.DeviceIndex;
                    _context.Setup.Camera.Dispose(); // Throw old camera away

                    Core.BuildingBlocks.Setup s = Core.BuildingBlocks.Setup.LoadBinary(_open_dlg.FileName);
                    _context.FrameGrabber.Camera = s.Camera;
                    _context.Setup = s;
                    _logger.Info("Loading Parsley configuration succeeded.");
                } catch (Exception) {
                    _logger.Error("Loading Parsley configuration failed.");
                    _context.Setup.Camera        = new Parsley.Core.BuildingBlocks.Camera(device_index);
                    _context.FrameGrabber.Camera = _context.Setup.Camera;
                } finally {
                    _context.FrameGrabber.Start();
                }
            }
        }
예제 #4
0
    /// <summary>
    /// Process image
    /// </summary>
    /// <param name="s">Setup</param>
    /// <param name="image">Image</param>
    /// <param name="points">Found points</param>
    /// <param name="pixels">Corresponding pixels for each point</param>
    /// <returns>True if successful, false otherwise</returns>
    public bool Process(
      Setup s, Emgu.CV.Image<Bgr, byte> image, 
      out List<Vector> points, out List<System.Drawing.Point> pixels)
    {
      pixels = null;
      points = null;
      // 1. Update values needed by algorithms

      Bundle b = new Bundle();
      BundleBookmarks bb = new BundleBookmarks(b);

      bb.ROI = _roi;
      bb.ReferencePlanes = s.ReferenceBody.ReferencePlanes;
      
      bb.Image = image;
      bb.LaserColor = s.Laser.Color;
            
      // 2. Extract laser line
      if (!_line_algorithm.FindLaserLine(bb.Bundle)) return false;

      // 3. Filter laser points
      if (!_line_filter.FilterLaserLine(bb.Bundle)) return false;
      if (bb.LaserPixel.Count < 3) return false;

      // 4. Detect laser plane
      List<Ray> eye_rays = new List<Ray>(Core.Ray.EyeRays(s.Camera.Intrinsics, bb.LaserPixel.ToArray()));
      bb.EyeRays = eye_rays;
      if (!_plane_algorithm.FindLaserPlane(bb.Bundle)) return false;

      // 5. Filter laser plane
      if (!_plane_filter.FilterLaserPlane(bb.Bundle)) return false;

      // 6. Extract relevant points in ROI
      pixels = new List<System.Drawing.Point>();
      points = new List<Vector>();

      List<System.Drawing.PointF> laser_pixel = bb.LaserPixel;
      Plane laser_plane = bb.LaserPlane;
      IList<Plane> reference_planes = s.ReferenceBody.AllPlanes;

      for (int i = 0; i < laser_pixel.Count; ++i) {
        // Round to nearest pixel
        System.Drawing.Point p = laser_pixel[i].ToNearestPoint();

        double t;
        if (_roi.Contains(p)) {
          Core.Ray r = eye_rays[i];
          if (Core.Intersection.RayPlane(r, laser_plane, out t)) {

            if (this.PointInsideOfReferenceVolume(reference_planes, r, t))
            {
              System.Drawing.Point in_roi = Core.IndexHelper.MakeRelative(p, _roi);
              pixels.Add(p);
              _point_accum.Accumulate(in_roi, r, t);
              points.Add(_point_accum.Extract(in_roi));
            }
          }
        }
      }

      s.Positioner.TransformPoints(ref points);
      return points.Count > 0;
    }
예제 #5
0
        public Main()
        {
            // Addin
            Core.Addins.AddinStore.Discover();
            Core.Addins.AddinStore.Discover(Environment.CurrentDirectory);
            //Core.Addins.AddinStore.Discover(Path.Combine(Environment.CurrentDirectory, "plugins"));

            InitializeComponent();

            log4net.Appender.IAppender app =
                LogManager.GetRepository().GetAppenders().FirstOrDefault(x => x is Logging.StatusStripAppender);
            if (app != null)
            {
                Logging.StatusStripAppender ssa = app as Logging.StatusStripAppender;
                ssa.StatusStrip          = _status_strip;
                ssa.ToolStripStatusLabel = _status_label;
            }


            Core.BuildingBlocks.Setup setup = null;
            try //check konfigurasi parsley, jika tidak ada gunakan konfigurasi default
            {
                if (File.Exists(@"CurrentParsley.cfg"))
                {
                    setup = Core.BuildingBlocks.Setup.LoadBinary(@"CurrentParsley.cfg");
                    //_logger.Info("Last Parsley configuration successfully loaded.");
                    _logger.Info("Last Parsley configuration successfully loaded.");
                    _logger.Debug("Last Parsley configuration successfully loaded.");
                }
                else
                {
                    setup = new Parsley.Core.BuildingBlocks.Setup();
                }
            }
            catch (System.Exception)
            {
                setup = new Parsley.Core.BuildingBlocks.Setup();
                _logger.Info("Last Parsley configuration failed to load properly. Using default one.");
            }

            //setting streaming camera
            Core.BuildingBlocks.FrameGrabber fg = new Parsley.Core.BuildingBlocks.FrameGrabber(setup.Camera);

            _live_feed = new Parsley.UI.Concrete.StreamViewer();
            _live_feed.Interpolation    = Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR;
            _live_feed.FunctionalMode   = Emgu.CV.UI.ImageBox.FunctionalModeOption.RightClickMenu;
            _live_feed.FrameGrabber     = fg;
            _live_feed.FrameGrabber.FPS = 30;
            _live_feed.FormClosing     += new FormClosingEventHandler(_live_feed_FormClosing);
            this.AddOwnedForm(_live_feed);
            _live_feed.Show();
            fg.Start();

            //setting rendering 3d
            _3d_viewer                          = new Parsley.UI.Concrete.Draw3DViewer();
            _3d_viewer.FormClosing             += new FormClosingEventHandler(_3d_viewer_FormClosing);
            _3d_viewer.RenderLoop.FPS           = 30;
            _3d_viewer.AspectRatio              = setup.Camera.FrameAspectRatio;
            _3d_viewer.IsMaintainingAspectRatio = true;
            _3d_viewer.RenderLoop.Start();
            this.AddOwnedForm(_3d_viewer);
            _3d_viewer.Show();

            _context = new Context(setup, fg, _3d_viewer.RenderLoop, _live_feed.EmbeddableStream);

            _settings              = new Settings(_context);
            _settings.FormClosing += new FormClosingEventHandler(_settings_FormClosing);
            _settings.PropertyGrid.PropertyValueChanged += new PropertyValueChangedEventHandler(PropertyGrid_PropertyValueChanged);
            this.AddOwnedForm(_settings);



            _slide_welcome              = new WelcomeSlide();
            _slide_intrinsic_calib      = new IntrinsicCalibrationSlide(_context);
            _slide_extrinsic_calib      = new ExtrinsicCalibrationSlide(_context);
            _slide_laser_setup          = new LaserSetupSlide(_context);
            _slide_scanning             = new ScanningSlide(_context);
            _slide_image_algorithm_test = new ImageAlgorithmTestSlide(_context);
            _slide_pattern_designer     = new PatternDesignerSlide(_context);


            _slide_control.AddSlide(_slide_welcome);
            _slide_control.AddSlide(_slide_scanning);
            _slide_control.AddSlide(_slide_intrinsic_calib);
            _slide_control.AddSlide(_slide_extrinsic_calib);
            _slide_control.AddSlide(_slide_laser_setup);
            _slide_control.AddSlide(_slide_image_algorithm_test);
            _slide_control.AddSlide(_slide_pattern_designer);

            _slide_control.SlideChanged += new EventHandler <SlickInterface.SlideChangedArgs>(_slide_control_SlideChanged);
            _slide_control.Selected      = _slide_welcome;
        }
예제 #6
0
        /// <summary>
        /// Process image
        /// </summary>
        /// <param name="s">Setup</param>
        /// <param name="image">Image</param>
        /// <param name="points">Found points</param>
        /// <param name="pixels">Corresponding pixels for each point</param>
        /// <returns>True if successful, false otherwise</returns>
        public bool Process(
            Setup s, Emgu.CV.Image <Bgr, byte> image,
            out List <Vector> points, out List <System.Drawing.Point> pixels)
        {
            pixels = null;
            points = null;
            // 1. Update values needed by algorithms

            Bundle          b  = new Bundle();
            BundleBookmarks bb = new BundleBookmarks(b);

            bb.ROI             = _roi;
            bb.ReferencePlanes = s.ReferenceBody.ReferencePlanes;

            bb.Image      = image;
            bb.LaserColor = s.Laser.Color;

            // 2. Extract laser line
            if (!_line_algorithm.FindLaserLine(bb.Bundle))
            {
                return(false);
            }

            // 3. Filter laser points
            if (!_line_filter.FilterLaserLine(bb.Bundle))
            {
                return(false);
            }
            if (bb.LaserPixel.Count < 3)
            {
                return(false);
            }

            // 4. Detect laser plane
            List <Ray> eye_rays = new List <Ray>(Core.Ray.EyeRays(s.Camera.Intrinsics, bb.LaserPixel.ToArray()));

            bb.EyeRays = eye_rays;
            if (!_plane_algorithm.FindLaserPlane(bb.Bundle))
            {
                return(false);
            }

            // 5. Filter laser plane
            if (!_plane_filter.FilterLaserPlane(bb.Bundle))
            {
                return(false);
            }

            // 6. Extract relevant points in ROI
            pixels = new List <System.Drawing.Point>();
            points = new List <Vector>();

            List <System.Drawing.PointF> laser_pixel = bb.LaserPixel;
            Plane         laser_plane      = bb.LaserPlane;
            IList <Plane> reference_planes = s.ReferenceBody.AllPlanes;

            for (int i = 0; i < laser_pixel.Count; ++i)
            {
                // Round to nearest pixel
                System.Drawing.Point p = laser_pixel[i].ToNearestPoint();

                double t;
                if (_roi.Contains(p))
                {
                    Core.Ray r = eye_rays[i];
                    if (Core.Intersection.RayPlane(r, laser_plane, out t))
                    {
                        if (this.PointInsideOfReferenceVolume(reference_planes, r, t))
                        {
                            System.Drawing.Point in_roi = Core.IndexHelper.MakeRelative(p, _roi);
                            pixels.Add(p);
                            _point_accum.Accumulate(in_roi, r, t);
                            points.Add(_point_accum.Extract(in_roi));
                        }
                    }
                }
            }

            s.Positioner.TransformPoints(ref points);
            return(points.Count > 0);
        }
예제 #7
0
 /// <summary>
 /// Save setup to file
 /// </summary>
 /// <param name="path"></param>
 /// <param name="s"></param>
 public static void SaveBinary(string path, Setup setup) {
   using (Stream s = File.OpenWrite(path)) {
     if (s != null) {
       IFormatter formatter = new BinaryFormatter();
       formatter.Serialize(s, setup);
       s.Close();
     }
   }
 }