Example #1
0
 public DetectedBall(TennisBall ball, Double gpsDistance, long timestampMillis)
 {
     this.ball            = ball;
     this.gpsDistance     = gpsDistance;
     this.cameraDistance  = this.ball.DistanceToCenter;
     this.timestampMillis = timestampMillis;
 }
Example #2
0
        private void ProcessFrame(Mat frame)
        {
            // Convert to Image type
            Image <Bgr, byte> frameImage = frame.ToImage <Bgr, byte>();

            // Apply Gaussian Blur and Perform HSV masking
            Image <Bgr, byte>  blur = frameImage.SmoothGaussian(GAUSSIAN_KERNELSIZE);
            Image <Gray, byte> mask = blur.Convert <Hsv, byte>().InRange(minHSV, maxHSV);

            // Erode and Dilate
            mask = mask.Erode(2).Dilate(2);

            // Produce a Colored mask and Grayscaled mask
            Image <Bgr, byte>  coloredMask = mask.Convert <Bgr, byte>() & frameImage;
            Image <Gray, byte> grayMask    = mask & frameImage.Convert <Gray, byte>();
            //Image<Gray, byte> grayMask = coloredMask.Convert<Gray, byte>();

            // Find the tennis ball
            CircleF candidateBall  = new CircleF();
            bool    isBallDetected = FindTennisBall(grayMask, ref candidateBall);

            lock (ballLock)
            {
                this.tennisBall = isBallDetected ? new TennisBall(candidateBall) : null;
            }
            if (isBallDetected)
            {
                ballTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            }
        }
Example #3
0
        // For use with webcams that use a device ID
        public Camera(int cameraDeviceId)
        {
            StartCamera(cameraDeviceId);

            this.tennisBall = null;
            this.ballLock   = new Object();
            this.frameStack = new ConcurrentStack <Mat>();
        }
Example #4
0
        // For use with IP cameras that use a URL
        public Camera(String cameraUrl)
        {
            StartCamera(cameraUrl);

            this.tennisBall = null;
            this.ballLock   = new Object();
            this.frameStack = new ConcurrentStack <Mat>();
        }
Example #5
0
 public TennisBall(TennisBall ball)
 {
     if (ball != null)
     {
         this.centerPoint      = new Coordinate(ball.CenterPoint);
         this.radius           = ball.Radius;
         this.distanceToCenter = ball.DistanceToCenter;
         this.angle            = ball.Angle;
     }
 }
Example #6
0
        public TennisBall GetBallCopy()
        {
            TennisBall ball = null;

            lock (ballLock)
            {
                if (this.tennisBall != null)
                {
                    ball = new TennisBall(this.tennisBall);
                }
            }

            return(ball);
        }