예제 #1
0
        private bool PointInsideOfReferenceVolume(IList <Plane> referencePlanes, Core.Ray r, double t)
        {
            Vector my3DPoint = r.At(t);

            for (int i = 0; i < referencePlanes.Count; i++)
            {
                if (referencePlanes[i].SignedDistanceTo(my3DPoint) >= _minimumDistanceToReferencePlane)
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #2
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);
        }