public DetectedBall(TennisBall ball, Double gpsDistance, long timestampMillis) { this.ball = ball; this.gpsDistance = gpsDistance; this.cameraDistance = this.ball.DistanceToCenter; this.timestampMillis = timestampMillis; }
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(); } }
// 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>(); }
// 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>(); }
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; } }
public TennisBall GetBallCopy() { TennisBall ball = null; lock (ballLock) { if (this.tennisBall != null) { ball = new TennisBall(this.tennisBall); } } return(ball); }