Esempio n. 1
0
        private void LatestImageAvailable(object state, Image<Bgr, byte> image)
        {
            m_PreviousTableUsage = m_TableUsage;
            m_DebugImage = image.Clone();
            if (m_Previousimage != null)
            {
                // Use an exponential-moving average concept to smooth data
                double tableBusyProb = ImageProcessing.TableBusyProbability(image, m_Previousimage, m_DebugImage);
                m_SEMA = (m_SEMA * (1f - RATE)) + (tableBusyProb * RATE);

                if (m_SEMA > 0.5) m_TableUsage = TableUsage.Busy;
                else m_TableUsage = TableUsage.Free;
            }
            m_Previousimage = image.Clone();

            if (m_TableUsage == TableUsage.Busy && m_PreviousTableUsage != TableUsage.Busy) TableNowBusy(this, null);
            if (m_TableUsage == TableUsage.Free && m_PreviousTableUsage != TableUsage.Free) TableNowFree(this, null);
        }
        internal static Image Transform(Image source, RotationType rotationType, FlippingType flippingType)
        {
            Image target;

            switch (rotationType)
            {
                case RotationType.None:
                    {
                        byte[] targetPixels = source.Pixels;
                        byte[] sourcePixels = new byte[targetPixels.Length];

                        Array.Copy(targetPixels, sourcePixels, targetPixels.Length);

                        target = new Image(source.Width, source.Height, sourcePixels);
                    }
                    break;
                case RotationType.Rotate90:
                    {
                        target = Rotate90(source);
                    }
                    break;
                case RotationType.Rotate180:
                    {
                        target = Rotate180(source);
                    }
                    break;
                case RotationType.Rotate270:
                    {
                        target = Rotate270(source);
                    }
                    break;
                default:
                    {
                        target = source.Clone();
                    }
                    break;
            }

            switch (flippingType)
            {
                case FlippingType.Vertical:
                    FlipX(target);
                    break;
                case FlippingType.Horizontal:
                    FlipY(target);
                    break;
            }

            return target;
        }
        public Image<Bgr, byte> ProcessImage(Image<Bgr, byte> img)
        {
            _current = img.Clone();

            if(_background != null)
            {
                var grayScale = img.Convert<Bgr, byte>();
                var sub = grayScale - _background;
                return sub.Convert<Bgr, byte>();
            }
            else
            {
                return _current;
            }
        }
Esempio n. 4
0
        public Image<Gray, byte> Process(Image<Gray, byte> src)
        {
            var dst = src.Clone();

            Connectivity.Connect8 = this.Connect8;
            var cl = src.connectLevel(1, 8, 0);
            foreach (var dm in cl.Domains) {
                if (dm.Area < Threshold) {
                    foreach (var p in dm.Points) {
                        dst[p] = new Gray(0);
                    }
                }
            }

            return dst;
        }
Esempio n. 5
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;
            }
        }
Esempio n. 6
0
 public Image<Gray, byte> Process(Image<Gray, byte> src)
 {
     if (shouldInvert(src)) return src.Not();
     else return src.Clone();
 }