private ColourDetectorOutput LocateColour() { var output = new ColourDetectorOutput(); const int captureBufferBurn = 2; // first image is stale, need to capture the second one Image <Bgr, byte> capturedImage = null; for (int i = 0; i < captureBufferBurn; i++) { capturedImage = GetCameraCapture(); //DoStep("Captured {0} image", i); } using (var capturedMat = capturedImage.Mat) { var colourDetectorInput = new ColourDetectorInput(); colourDetectorInput.Captured = capturedMat; colourDetectorInput.SetCapturedImage = false; colourDetectorInput.Settings = Settings; output = _colourDetector.Process(colourDetectorInput); } if (ColourCaptured != null) { output.CapturedImage = capturedImage; ColourCaptured(this, output); } return(output); }
public override void ImageGrabbedHandler(object sender, EventArgs e) { using (var matCaptured = new Mat()) { var retrieveElapsed = Stopwatch.StartNew(); CameraCapture.Retrieve(matCaptured); retrieveElapsed.Stop(); if (_readyRectangle.IsEmpty) { _detectorInput.ErodeDilateIterations = (int)spinDilateIterations.Value; _detectorInput.Settings.Roi = GetRegionOfInterestFromControls(); _detectorInput.Captured = matCaptured; var output = _colorDetector.Process(_detectorInput); DrawReticle(output.CapturedImage, output.CentralPoint.ToPoint(), Color.Aqua); if (output.IsDetected) { var radius = 50; var circle = new CircleF(output.CentralPoint, radius); var color = new Bgr(Color.Yellow); output.CapturedImage.Draw(circle, color, 3); var ballTextLocation = output.CentralPoint.ToPoint(); ballTextLocation.X += radius; // output.CapturedImage.Draw("ball", ballTextLocation, FontFace.HersheyPlain, 3, color); } if (checkBoxRoi.Checked) { output.CapturedImage.Draw(_detectorInput.Settings.Roi, Color.Green.ToBgr(), 3); } if (!_imageBoxSelector.SeedingRectangle.IsEmpty) { output.CapturedImage.Draw(_imageBoxSelector.SeedingRectangle, new Bgr(Color.Chartreuse)); } imageBoxCaptured.Image = output.CapturedImage; imageBoxFiltered.Image = output.ThresholdImage; NotifyStatus( "Retrieved frame in {0}, {1}" , retrieveElapsed.Elapsed.ToHumanReadable(HumanReadableTimeSpanOptions.Abbreviated) , output); } else { DoAutoThresholding(matCaptured); } ResizeImageControls(); } }
private bool IsColourFullFrame(CameraProcessInput input) { var isFullFrameColour = false; // detect all black using (new TemporaryThresholdSettings(_colourDetectorInput, ThresholdSettings.Get(0, 0, 0, 180, 255, 40))) { _colourDetectorInput.Captured = input.Captured; var colourOutput = _colourDetector.Process(_colourDetectorInput); const int fullFrameMinimumPercent = 70; var fullFramePixelCount = colourOutput.CapturedImage.Width * colourOutput.CapturedImage.Height; var mimimumColourPixelCount = fullFramePixelCount * fullFrameMinimumPercent / 100; isFullFrameColour = colourOutput.MomentArea > mimimumColourPixelCount; } return(isFullFrameColour); }
public override void ImageGrabbedHandler(object sender, EventArgs e) { using (var matCaptured = new Mat()) { CameraCapture.Retrieve(matCaptured); var detector = new ColourDetector(); var input = new ColourDetectorInput { Captured = matCaptured , Settings = Settings , SetCapturedImage = false }; var result = detector.Process(input); if (result.IsDetected) { Log.Info(result); } } }
public override void ImageGrabbedHandler(object sender, EventArgs e) { using (var matCaptured = new Mat()) { CameraCapture.Retrieve(matCaptured); var detector = new ColourDetector(); var input = new ColourDetectorInput { Captured = matCaptured ,Settings= Settings ,SetCapturedImage = false }; var result = detector.Process(input); if (result.IsDetected) { Log.Info(result); } } }
protected override ColourTrackingPanTiltOutput DoProcess(CameraProcessInput input) { var colourDetectorInput = new ColourDetectorInput(); colourDetectorInput.Captured = input.Captured; colourDetectorInput.SetCapturedImage = input.SetCapturedImage; colourDetectorInput.Settings = Settings; var colourDetectorOutput = _colourDetector.Process(colourDetectorInput); var targetPoint = CentrePoint; if (colourDetectorOutput.IsDetected) { targetPoint = colourDetectorOutput.CentralPoint.ToPoint(); } var output = ReactToTarget(targetPoint); output.Absorb(colourDetectorOutput); return(output); }
public override void ImageGrabbedHandler(object sender, EventArgs e) { using (var matCaptured = new Mat()) { CameraCapture.Retrieve(matCaptured); var input = new ColourDetectorInput { Captured = matCaptured , Settings = Settings , SetCapturedImage = false }; var result = _detector.Process(input); if (result.IsDetected) { if (!_objectCurrentlyDetected) { _debounceWatch.Start(); _objectCurrentlyDetected = true; } SweeperToRed(); Log.Info(m => m("Red detected! {0}", result)); } else { var isInDebouncePeriod = _debounceWatch.IsRunning && _debounceWatch.ElapsedMilliseconds < 800; if (_objectCurrentlyDetected && !isInDebouncePeriod) { _debounceWatch.Reset(); Log.Info(m => m("Red gone")); SweeperToGreen(); _objectCurrentlyDetected = false; } } } }
public override void ImageGrabbedHandler(object sender, EventArgs e) { using (var matCaptured = new Mat()) { var retrieveElapsed = Stopwatch.StartNew(); CameraCapture.Retrieve(matCaptured); retrieveElapsed.Stop(); ResizeImageControls(matCaptured); _detectorInput.Settings.Roi = GetRegionOfInterestFromControls(); _detectorInput.Captured = matCaptured; var output = _colorDetector.Process(_detectorInput); if (output.IsDetected) { var radius = 50; var circle = new CircleF(output.CentralPoint, radius); var color = new Bgr(Color.Yellow); output.CapturedImage.Draw(circle, color, 3); var ballTextLocation = output.CentralPoint.ToPoint(); ballTextLocation.X += radius; // output.CapturedImage.Draw("ball", ballTextLocation, FontFace.HersheyPlain, 3, color); } if (checkBoxRoi.Checked) { output.CapturedImage.Draw(_detectorInput.Settings.Roi, Color.Green.ToBgr()); } //#region circle detection //var watch = Stopwatch.StartNew(); //double cannyThreshold = 180.0; //double circleAccumulatorThreshold = 120; //CircleF[] circles = CvInvoke.HoughCircles( // thresholdImage // , HoughType.Gradient // , 2.0 // , 20.0 // , cannyThreshold // , circleAccumulatorThreshold // , 5); //watch.Stop(); //NotifyStatus("Hough circles - {0} ms; ", watch.ElapsedMilliseconds); //#endregion //#region draw circles //var circleImage = matCaptured.ToImage<Bgr, byte>(); //foreach (CircleF circle in circles) //{ // circleImage.Draw(circle, new Bgr(Color.Brown), 2); //} //#endregion imageBoxCaptured.Image = output.CapturedImage; imageBoxFiltered.Image = output.ThresholdImage; NotifyStatus( "Retrieved frame in {0}, {1}" , retrieveElapsed.Elapsed.ToHumanReadable(HumanReadableTimeSpanOptions.Abbreviated) , output); } }