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 (_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());
              }
            }
          }
        }
      }
       * */
    }
示例#3
0
 /// <summary>
 /// Initialize from pre-existing viewer
 /// </summary>
 /// <param name="v">viewer</param>
 public RenderLoop(Parsley.Draw3D.Viewer v) {
   _v = v;
   _fts = new FixedTimeStep();
   _bw = new BackgroundWorker();
   _bw.WorkerSupportsCancellation = true;
   _bw.DoWork += new DoWorkEventHandler(_bw_DoWork);
   _event_lock = new object();
   _stopped = new ManualResetEvent(false);
 }
 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);
   }
 }
    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);
      }
    }
 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
     }
 }
 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);
      }
    }
    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);
    }
示例#10
0
    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);
        }
      }
    }
示例#11
0
 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();
       }
     }));
   }
 }
示例#12
0
    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);
    }
 protected virtual void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte> img) { }
 void _interactor_InteractionCompleted(object sender, Parsley.UI.InteractionEventArgs e) {
   _last_detected_plane = null;
   _last_error = Double.MaxValue;
   _on_roi = true;
   _r = (Rectangle)e.InteractionResult;
 }
示例#15
0
 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) {
   if (_algorithm != null) {
     _algorithm.ProcessImage(img);
   }
   base.OnFrame(fp, img);
 }
示例#17
0
 void _current_InteractionCompleted(object sender, Parsley.UI.InteractionEventArgs e) {
   GridItem i = _pg_config.SelectedGridItem;
   i.PropertyDescriptor.SetValue(i.Parent.Value, e.InteractionResult);
   _pg_config.Invalidate();
   _pg_config.Refresh();
 }