protected override void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { /* * if (_take_ref_image) { * _ref_image = img.Copy(); * _take_ref_image = false; * } * * // 1. Extract laser-line * Context.Setup.World.Laser.FindLaserLine(img); * PointF[] laser_points = Context.Setup.World.Laser.ValidLaserPoints.ToArray(); * * if (_acc != null) { * img.Draw(_acc.ROI, new Bgr(Color.Green), 1); * } * * if (laser_points.Length < 3 || _ref_image == null || _acc == null) { * return; * } * * Core.Ray[] eye_rays = Core.Ray.EyeRays(Context.Setup.World.Camera.Intrinsics, laser_points); * Core.Plane laser_plane; * if (Context.Setup.World.Laser.LaserPlaneAlgorithm.FindLaserPlane( * eye_rays, * Context.Setup.World.ReferencePlanes, out laser_plane)) * { * Vector z = Vector.Create(new double[] { 0, 0, 1 }); * if (Math.Abs(laser_plane.Normal.ScalarMultiply(z)) < 0.3) { * Console.WriteLine(laser_plane.Normal); * return; * } * * lock (Context.Viewer) { * for (int i = 0; i < laser_points.Length; ++i) { * Point lp = new Point((int)laser_points[i].X, (int)laser_points[i].Y); * * if (_acc.ROI.Contains(lp)) { * * double t; * Core.Intersection.RayPlane(eye_rays[i], laser_plane, out t); * * img[lp.Y, lp.X] = new Bgr(Color.Red); * Bgr bgr = _ref_image[lp.Y, lp.X]; * Vector color = new Vector(new double[] { bgr.Red / 255.0, bgr.Green / 255.0, bgr.Blue / 255.0, 1.0 }); * * //_pointcloud.AddPoint(final.ToInterop(), color.ToInterop()); * Point p_in_roi = _acc.MakeRelativeToROI(lp); * bool first; * _acc.Accumulate(p_in_roi, eye_rays[i], t, out first); * if (first) { * _acc.SetId(p_in_roi, _pointcloud.AddPoint(_acc.Extract(p_in_roi).ToInterop(), color.ToInterop())); * } else { * _pointcloud.UpdatePoint(_acc.GetId(p_in_roi), _acc.Extract(p_in_roi).ToInterop(), color.ToInterop()); * } * } * } * } * } * */ }
protected override void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { Parsley.Core.ExtrinsicCalibration ec; ExtrinsicCameraParameters ecp; bool pattern_found = false; Core.CalibrationPattern p = _pattern; if (p != null) { Image <Gray, Byte> gray = img.Convert <Gray, Byte>(); pattern_found = p.FindPattern(gray); p.DrawPattern(img, p.ImagePoints, p.PatternFound); // if pattern has been found ==> find extrinsics and draw the corresponding coordinate frame if (pattern_found == true && Context.Setup.Camera.Intrinsics != null) { ec = new Parsley.Core.ExtrinsicCalibration(p.ObjectPoints, Context.Setup.Camera.Intrinsics); ecp = ec.Calibrate(p.ImagePoints); if (ecp != null) { Core.Drawing.DrawCoordinateFrame(img, ecp, Context.Setup.Camera.Intrinsics); } } } base.OnFrame(fp, img); }
void _grabber_OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fg, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { // Note: This method is called from the frame-grabber's thread loop. // The framegrabber holds a Breath on the camera to ensure that the camera object remains // alive during this callback. The camera object is a SharedResource, meaning that any // invocation to Dispose will block until all Breaths on the camera are released. Suppose // The thread that owns the picture box has called dispose and blocks. The callback here is called // and invoke is used. Invoke executes the delegate on thread that owns this control, which is the one // that is already blocked. This leads to a deadlock. That is why we use BeginInvoke, which executes // the delegate on the GUI thread associated with this control. if (_can_invoke) { Rectangle client = this.ClientRectangle; Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img_copy = img.Resize(client.Width, client.Height, _interpolation); this.BeginInvoke(new MethodInvoker(delegate { // Update image Emgu.CV.IImage prev = _picture_box.Image; _picture_box.Image = img_copy; if (prev != null) { prev.Dispose(); } })); } }
override protected void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { if (Context.ROIHandler.Last != Rectangle.Empty) { img.Draw(Context.ROIHandler.Last, new Emgu.CV.Structure.Bgr(Color.Green), 1); } }
protected override void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { // Constraint checking if (!Context.Setup.Camera.HasIntrinsics) { _on_roi = false; return; } if (_interactor.State == Parsley.UI.InteractionState.Interacting) { _interactor.DrawIndicator(_interactor.Current, img); } else { _interactor.DrawIndicator(_r, img); } if (_on_roi && _pattern != null) { Image <Gray, Byte> gray = img.Convert <Gray, Byte>(); _pattern.IntrinsicParameters = Context.Setup.Camera.Intrinsics; try { _pattern.FindPattern(gray, _r); if (_pattern.PatternFound) { Parsley.Core.ExtrinsicCalibration ec = new Parsley.Core.ExtrinsicCalibration(_pattern.ObjectPoints, Context.Setup.Camera.Intrinsics); ExtrinsicCameraParameters ecp = ec.Calibrate(_pattern.ImagePoints); double[] deviations; Vector[] points; Core.ExtrinsicCalibration.CalibrationError(ecp, Context.Setup.Camera.Intrinsics, _pattern.ImagePoints, _pattern.ObjectPoints, out deviations, out points); double max_error = deviations.Max(); if (max_error < _last_error) { _last_detected_plane = ecp; _last_error = max_error; this.Logger.Info(String.Format("Extrinsics successfully calculated. Maximum error {0:F3}", _last_error)); } } else if (!_pattern.PatternFound & _last_detected_plane == null) { this.Logger.Warn("Pattern not found."); } } catch (System.Exception e) { this.Logger.Warn(String.Format("Failed to determine extrinsic calibration: {0}", e.Message)); } } if (_last_detected_plane != null) { Core.Drawing.DrawCoordinateFrame(img, _last_detected_plane, Context.Setup.Camera.Intrinsics); } }
protected override void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { if (_algorithm != null) { _algorithm.ProcessImage(img); } base.OnFrame(fp, img); }
protected override void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { Core.CalibrationPattern pattern = _pattern; if (pattern != null) { Image <Gray, Byte> gray = img.Convert <Gray, Byte>(); pattern.FindPattern(gray); this.UpdateStatusDisplay(pattern.PatternFound); this.HandleCalibrateRequest(); this.HandleTakeImageRequest(); this.DrawCoordinateFrame(img); pattern.DrawPattern(img, pattern.ImagePoints, pattern.PatternFound); } }
protected override void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { Core.CalibrationPattern pattern = _pattern; if (pattern != null) { //cari pola kalibrasi jika marker kalibrasi tersedia Image <Gray, Byte> gray = img.Convert <Gray, Byte>(); //convert image to grayscale pattern.FindPattern(gray); //cari pola kalibrasi this.UpdateStatusDisplay(pattern.PatternFound); this.HandleCalibrateRequest(); this.HandleTakeImageRequest(); this.DrawCoordinateFrame(img); pattern.DrawPattern(img, pattern.ImagePoints, pattern.PatternFound); //gambar AR pada marker jika pattern ditemukan } }
protected override void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { if (_take_texture_image) { _take_texture_image = false; _texture_image = img.Copy(); lock (Context.Viewer) { UpdateAllColors(); } } if (_clear_points) { _clear_points = false; _pixel_point_ids.Reset(); Context.Setup.ScanWorkflow.Reset(); _pointcloud.ClearPoints(); } // Update the transformation between positioner coordinate system and camera coordinate system if (_update_positioner_transformation) { _update_positioner_transformation = false; Context.Setup.Positioner.UpdateTransformation(Context.Setup.Camera); _pixel_point_ids.Reset(); Context.Setup.ScanWorkflow.Reset(); } if (Context.Setup.Camera.FrameSize != _pixel_point_ids.Size) { _pixel_point_ids.Size = Context.Setup.Camera.FrameSize; } List <Vector> points; List <System.Drawing.Point> pixels; if (Context.Setup.ScanWorkflow.Process(Context.Setup, img, out points, out pixels)) { lock (Context.Viewer) { UpdatePoints(points, pixels); } foreach (System.Drawing.Point p in pixels) { img[p.Y, p.X] = new Bgr(Color.Green); } } }
override protected void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { Emgu.CV.Image <Emgu.CV.Structure.Bgr, Byte> my_ref = _reference; int my_channel = _channel; if (my_ref != null) { _lle.FindLaserLine(img[my_channel].Sub(my_ref[my_channel])); } else { _lle.FindLaserLine(img[my_channel]); } foreach (System.Drawing.PointF p in _lle.ValidLaserPoints) { img[(int)p.Y, (int)p.X] = new Emgu.CV.Structure.Bgr(255, 0, 0); } }
override protected void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { Core.CalibrationPattern pattern = this.Context.CalibrationPattern; Emgu.CV.Image <Gray, Byte> gray = img.Convert <Gray, Byte>(); gray._EqualizeHist(); pattern.FindPattern(gray); if (pattern.PatternFound) { Emgu.CV.ExtrinsicCameraParameters ecp = _ex.Calibrate(pattern.ImagePoints); lock (Context.Viewer) { Matrix m = Matrix.Identity(4, 4); m.SetMatrix(0, 2, 0, 3, ecp.ExtrinsicMatrix.ToParsley()); _board_transform.Matrix = m.ToInterop(); } } pattern.DrawPattern(img, pattern.ImagePoints, pattern.PatternFound); }
void FrameGrabber_OnFramePrepend(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { UI.I2DInteractor i = _current; if (i != null) { if (i.State == Parsley.UI.InteractionState.Interacting) { _current.DrawIndicator(i.Current, img); } else { GridItem e = _pg_config.SelectedGridItem; GridItem p = e.Parent; if (p != null) { _current.DrawIndicator(e.PropertyDescriptor.GetValue(p.Value), img); } } } }
protected override void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { Core.Bundle b = new Parsley.Core.Bundle(); Core.BundleBookmarks bb = new Parsley.Core.BundleBookmarks(b); bb.Image = img; bb.LaserColor = Context.Setup.Laser.Color; if (!Context.Setup.ScanWorkflow.LaserLineAlgorithm.FindLaserLine(bb.Bundle)) { return; } if (!Context.Setup.ScanWorkflow.LaserLineFilterAlgorithm.FilterLaserLine(bb.Bundle)) { return; } SaveLaserData(bb.LaserPixel); foreach (System.Drawing.PointF p in bb.LaserPixel) { img[p.ToNearestPoint()] = new Emgu.CV.Structure.Bgr(System.Drawing.Color.Green); } }
protected virtual void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { }
protected override void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img) { #region take texture if (_take_texture_image) //even handler jika mengambil texture image { _take_texture_image = false; _texture_image = img.Copy(); lock (Context.Viewer) { UpdateAllColors(); } } #endregion #region clear point if (_clear_points) { //even handler jika menghapus point 3d yg sdh ada _clear_points = false; _pixel_point_ids.Reset(); Context.Setup.ScanWorkflow.Reset(); _pointcloud.ClearPoints(); } #endregion #region update positioner // Update the transformation between positioner coordinate system and camera coordinate system if (_update_positioner_transformation) { _update_positioner_transformation = false; Context.Setup.Positioner.UpdateTransformation(Context.Setup.Camera); _pixel_point_ids.Reset(); Context.Setup.ScanWorkflow.Reset(); } #endregion #region penyesuaian proporsi pixel dengan frame size if (Context.Setup.Camera.FrameSize != _pixel_point_ids.Size) { _pixel_point_ids.Size = Context.Setup.Camera.FrameSize; } #endregion List <Vector> points; //array penyimpan koordinat //sepertinya ini yang out of range List <System.Drawing.Point> pixels; #region start scanning if (_start_scanning) { //Console.Write(Context.Setup.ScanWorkflow.Process(Context.Setup, img, out points, out pixels)); if (Context.Setup.ScanWorkflow.Process(Context.Setup, img, out points, out pixels)) //Jika syarat2 dalam scanworkflow.process terpenuhi maka akan ditambahkan pointcloudnya. { Console.WriteLine(pixels.Count); lock (Context.Viewer) { UpdatePoints(points, pixels); //memanggil fungsi UpdatePoints untuk update model 3d setiap waktu, tanpa perduli terdeteksi ada nilai baru atau tidak } foreach (System.Drawing.Point p in pixels) { img[p.Y, p.X] = new Bgr(Color.Green); } } } #endregion }
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; }
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; }