Exemple #1
0
 /// <summary>
 /// Find ball location in frame in defined area
 /// </summary>
 /// <param name="image">Image to detect ball</param>
 /// <param name="timeStamp">Time Stamp of an image</param>
 /// <param name="detectionArea">Area to search ball in. If Selected:
 /// area will be defined based on last stored location and maximum possible speed.
 /// [Default is Full to search in all frame]
 /// </param>
 /// <returns>[True] if ball location found, [False] otherwise</returns>
 public abstract bool FindBallLocationInFrame(Image<Gray, byte> image, DateTime timeStamp, eDetectionArea detectionArea = eDetectionArea.Full);
Exemple #2
0
        /// <summary>
        /// Find ball location in frame in defined area
        /// </summary>
        /// <param name="image">Image to detect ball</param>
        /// <param name="timeStamp">Time Stamp of an image</param>
        /// <param name="detectionArea">Area to search ball in. If Selected:
        /// area will be defined based on last stored location and maximum possible speed.
        /// [Default is Full to search in all frame]
        /// </param>
        /// <returns>[True] if ball location found, [False] otherwise</returns>
        public override bool FindBallLocationInFrame(Image <Gray, byte> image, DateTime timeStamp, eDetectionArea detectionArea = eDetectionArea.Full)
        {
            using (image = image.Clone())
            {
                int additionalOffsetX = 0;
                int additionalOffsetY = 0;

                if (detectionArea.Equals(eDetectionArea.Selected))
                {
                    TimeSpan deltaT       = timeStamp - ImagingData.LastKnownBallLocation.Timestamp;
                    double   searchRadius = MAX_BALL_SPEED * deltaT.TotalSeconds;

                    int maxX = (Convert.ToInt32(ImagingData.LastKnownBallLocation.X + searchRadius) > image.Width) ?
                               image.Width : Convert.ToInt32(ImagingData.LastKnownBallLocation.X + searchRadius);
                    int maxY = (Convert.ToInt32(ImagingData.LastKnownBallLocation.Y + searchRadius) > image.Height) ?
                               image.Height : Convert.ToInt32(ImagingData.LastKnownBallLocation.Y + searchRadius);
                    additionalOffsetX = (Convert.ToInt32(ImagingData.LastKnownBallLocation.X - searchRadius) < 0) ?
                                        0 : Convert.ToInt32(ImagingData.LastKnownBallLocation.X - searchRadius);
                    additionalOffsetY = (Convert.ToInt32(ImagingData.LastKnownBallLocation.Y - searchRadius) < 0) ?
                                        0 : Convert.ToInt32(ImagingData.LastKnownBallLocation.Y - searchRadius);

                    List <System.Drawing.PointF> croppingPoints = new List <System.Drawing.PointF>()
                    {
                        new System.Drawing.PointF(maxX, maxY),
                        new System.Drawing.PointF(maxX, additionalOffsetY),
                        new System.Drawing.PointF(additionalOffsetX, maxY),
                        new System.Drawing.PointF(additionalOffsetX, additionalOffsetY)
                    };

                    image = Crop(image, croppingPoints);
                    ComputerVisionMonitors[eComputerVisionMonitor.MonitorB].ShowFrame(image);
                }

                CircleF[] pos = DetectCircles(image, ImagingData.BallRadius, ImagingData.BallRadiusError * 2, ImagingData.BallRadius * 5);
                if (pos.Length > 0)
                {
                    double xLocation = pos[0].Center.X + additionalOffsetX;
                    double yLocation = pos[0].Center.Y + additionalOffsetY;
                    UpdateCoordinates(xLocation, yLocation, timeStamp, Brushes.Red);
                    return(true);
                }
                Log.Print(String.Format("Ball not found in {0} area", detectionArea.ToString()), eCategory.Debug, LogTag.IMAGE);
                ImagingData.BallCoords = new BallCoordinates(timeStamp);
                return(false);
            }
        }
Exemple #3
0
        /// <summary>
        /// Find ball location in frame in defined area
        /// </summary>
        /// <param name="image">Image to detect ball</param>
        /// <param name="timeStamp">Time Stamp of an image</param>
        /// <param name="detectionArea">Area to search ball in. If Selected:
        /// area will be defined based on last stored location and maximum possible speed.
        /// [Default is Full to search in all frame]
        /// </param>
        /// <returns>[True] if ball location found, [False] otherwise</returns>
        public override bool FindBallLocationInFrame(Image<Gray, byte> image, DateTime timeStamp, eDetectionArea detectionArea = eDetectionArea.Full)
        {
            using (image = image.Clone())
            {
                int additionalOffsetX = 0;
                int additionalOffsetY = 0;

                if (detectionArea.Equals(eDetectionArea.Selected))
                {
                    TimeSpan deltaT = timeStamp - ImagingData.LastKnownBallLocation.Timestamp;
                    double searchRadius = MAX_BALL_SPEED * deltaT.TotalSeconds;

                    int maxX = (Convert.ToInt32(ImagingData.LastKnownBallLocation.X + searchRadius) > image.Width) ?
                        image.Width : Convert.ToInt32(ImagingData.LastKnownBallLocation.X + searchRadius);
                    int maxY = (Convert.ToInt32(ImagingData.LastKnownBallLocation.Y + searchRadius) > image.Height) ?
                        image.Height : Convert.ToInt32(ImagingData.LastKnownBallLocation.Y + searchRadius);
                    additionalOffsetX = (Convert.ToInt32(ImagingData.LastKnownBallLocation.X - searchRadius) < 0) ?
                        0 : Convert.ToInt32(ImagingData.LastKnownBallLocation.X - searchRadius);
                    additionalOffsetY = (Convert.ToInt32(ImagingData.LastKnownBallLocation.Y - searchRadius) < 0) ?
                        0 : Convert.ToInt32(ImagingData.LastKnownBallLocation.Y - searchRadius);

                    List<System.Drawing.PointF> croppingPoints = new List<System.Drawing.PointF>()
                    {
                        new System.Drawing.PointF(maxX, maxY),
                        new System.Drawing.PointF(maxX, additionalOffsetY),
                        new System.Drawing.PointF(additionalOffsetX, maxY),
                        new System.Drawing.PointF(additionalOffsetX, additionalOffsetY)
                    };
                    
                    image = Crop(image, croppingPoints);
                    ComputerVisionMonitors[eComputerVisionMonitor.MonitorB].ShowFrame(image);
                }

                CircleF[] pos = DetectCircles(image, ImagingData.BallRadius, ImagingData.BallRadiusError * 2, ImagingData.BallRadius * 5);
                if (pos.Length > 0)
                {
                    double xLocation = pos[0].Center.X + additionalOffsetX;
                    double yLocation = pos[0].Center.Y + additionalOffsetY;
                    UpdateCoordinates(xLocation, yLocation, timeStamp, Brushes.Red);
                    return true;
                }
                Log.Print(String.Format("Ball not found in {0} area", detectionArea.ToString()), eCategory.Debug, LogTag.IMAGE);
                ImagingData.BallCoords = new BallCoordinates(timeStamp);
                return false;
            }
        }
Exemple #4
0
 /// <summary>
 /// Find ball location in frame in defined area
 /// </summary>
 /// <param name="image">Image to detect ball</param>
 /// <param name="timeStamp">Time Stamp of an image</param>
 /// <param name="detectionArea">Area to search ball in. If Selected:
 /// area will be defined based on last stored location and maximum possible speed.
 /// [Default is Full to search in all frame]
 /// </param>
 /// <returns>[True] if ball location found, [False] otherwise</returns>
 public abstract bool FindBallLocationInFrame(Image <Gray, byte> image, DateTime timeStamp, eDetectionArea detectionArea = eDetectionArea.Full);