public ColorDetectRunner(ICaptureGrab capture) : base(capture) { Settings = new ColourDetectSettings(); // useful defaults - red under lights Settings.LowThreshold = new MCvScalar(140, 57, 25); Settings.HighThreshold = new MCvScalar(187, 153, 82); Settings.MomentArea = new RangeF(200,400); }
protected CameraConsumerRunner(ICaptureGrab captureGrabber) { _fpsTracker = new FpsTracker(); _fpsTracker.ReportEveryNthFrame = 50; _fpsTracker.ReportFrames= s => Log.Info(m=>m(s)); CameraCapture = captureGrabber; CameraCapture.ImageGrabbed += ImageGrabbedHandler; CameraCapture.ImageGrabbed += _fpsTracker.NotifyImageGrabbed; }
private void AssignCaptureToConsumers(ICaptureGrab capture) { foreach (var consumer in _consumers) { consumer.CameraCapture = capture; var tabPage = _tabPageLinks.Find(kvp => kvp.Value == consumer).Key; tabPage.Controls.Add(consumer); consumer.Dock = DockStyle.Fill; consumer.StatusUpdated += consumer_StatusUpdated; } }
/* * * CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds. * CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next. * CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file * CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream. * CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream. * CV_CAP_PROP_FPS Frame rate. * CV_CAP_PROP_FOURCC 4-character code of codec. * CV_CAP_PROP_FRAME_COUNT Number of frames in the video file. * CV_CAP_PROP_FORMAT Format of the Mat objects returned by retrieve() . * CV_CAP_PROP_MODE Backend-specific value indicating the current capture mode. * CV_CAP_PROP_BRIGHTNESS Brightness of the image (only for cameras). * CV_CAP_PROP_CONTRAST Contrast of the image (only for cameras). * CV_CAP_PROP_SATURATION Saturation of the image (only for cameras). * CV_CAP_PROP_HUE Hue of the image (only for cameras). * CV_CAP_PROP_GAIN Gain of the image (only for cameras). * CV_CAP_PROP_EXPOSURE Exposure (only for cameras). * CV_CAP_PROP_CONVERT_RGB Boolean flags indicating whether images should be converted to RGB. * CV_CAP_PROP_WHITE_BALANCE Currently unsupported * CV_CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently) * */ public static CaptureConfig GetCaptureProperties(this ICaptureGrab capture) { if (capture == null) { return(null); } var settings = new CaptureConfig(); settings.Resolution.Height = Convert.ToInt32(capture.GetCaptureProperty(CapProp.FrameHeight)); settings.Resolution.Width = Convert.ToInt32(capture.GetCaptureProperty(CapProp.FrameWidth)); settings.Framerate = Convert.ToInt32(capture.GetCaptureProperty(CapProp.Fps)); settings.Monochrome = Convert.ToBoolean(capture.GetCaptureProperty(CapProp.Monochrome)); return(settings); }
/// <summary> /// So we can replace with a new framerate /// </summary> public void UpdateCaptureGrabber(ICaptureGrab captureGrabber) { if (CameraCapture != null) { CameraCapture.ImageGrabbed -= InternalImageGrabbedHandler; CameraCapture.Stop(); } CameraCapture = captureGrabber; CameraCapture.ImageGrabbed += InternalImageGrabbedHandler; if (Started) { CameraCapture.Start(); } }
private void MainForm_Load(object sender, EventArgs e) { var captureDevice = CaptureDevice.Usb; //var captureDevice = CaptureDevice.Pi; if (Environment.OSVersion.Platform == PlatformID.Unix) { captureDevice = CaptureDevice.Pi; } _capture = CaptureFactory.GetCapture(captureDevice); //_capture = new CaptureFile(@"D:\Data\Documents\Pictures\2014\20140531_SwimmingLessons\MVI_8742.MOV"); SetupCameraConsumers(_capture); SetupFramerateTracking(_capture); // SetCaptureProperties(); //access violation with logitech }
public CameraBasedPanTiltRunner( IPanTiltMechanism panTiltMech , ICaptureGrab captureGrabber , IController <CameraPanTiltProcessOutput> controller , IScreen screen) : base(panTiltMech) { _controller = controller; Screen = screen; FpsTracker = new FpsTracker(); FpsTracker.ReportEveryNthFrame = 2; FpsTracker.ReportFrames = s => Screen.WriteLine(s); UpdateCaptureGrabber(captureGrabber); _keyHandler = controller as IKeyHandler; }
public CameraBasedPanTiltRunner( IPanTiltMechanism panTiltMech , ICaptureGrab captureGrabber , IController<CameraPanTiltProcessOutput> controller , IScreen screen) : base(panTiltMech) { _controller = controller; Screen = screen; FpsTracker = new FpsTracker(); FpsTracker.ReportEveryNthFrame = 2; FpsTracker.ReportFrames = s => Screen.WriteLine(s); UpdateCaptureGrabber(captureGrabber); _keyHandler = controller as IKeyHandler; }
public ServoSorter( ICaptureGrab capture ,ConsoleOptions options) : base(capture) { _servoPosition = 70; Settings = options.ColourSettings; _debounceWatch = new Stopwatch(); var deviceFactory = new Pca9685DeviceFactory(); var device = deviceFactory.GetDevice(options.UseFakeDevice); SetLogLevel(device); _pwmControl = new ServoSortPwmControl(device); _pwmControl.Init(); _detector = new ColourDetector(); }
public ServoSorter( ICaptureGrab capture , ConsoleOptions options) : base(capture) { _servoPosition = 70; Settings = options.ColourSettings; _debounceWatch = new Stopwatch(); var deviceFactory = new Pca9685DeviceFactory(); var device = deviceFactory.GetDevice(options.UseFakeDevice); SetLogLevel(device); _pwmControl = new ServoSortPwmControl(device); _pwmControl.Init(); _detector = new ColourDetector(); }
public CameraBasedPanTiltRunner( IPanTiltMechanism panTiltMech , ICaptureGrab captureGrabber , IController<CameraPanTiltProcessOutput> controller , IScreen screen) : base(panTiltMech) { _controller = controller; Screen = screen; FpsTracker = new FpsTracker(); FpsTracker.ReportEveryNthFrame = 2; FpsTracker.ReportFrames = s => Screen.WriteLine(s); CameraCapture = captureGrabber; CameraCapture.ImageGrabbed += InternalImageGrabbedHandler; CaptureConfig = captureGrabber.GetCaptureProperties(); }
public ColorDetectRunner(ICaptureGrab capture, ColourDetectSettings settings) : base(capture) { Settings = settings; }
static void Main(string[] args) { var appData = ExecutionEnvironment.GetApplicationMetadata(); Log.Info(appData); var options = new ConsoleOptions(args); if (options.ShowHelp) { Console.WriteLine("Options:"); options.OptionSet.WriteOptionDescriptions(Console.Out); return; } ICaptureGrab capture = null; if (options.Mode != Mode.simple) { var captureDevice = CaptureDevice.Usb; if (Environment.OSVersion.Platform == PlatformID.Unix) { captureDevice = CaptureDevice.Pi; } capture = CaptureFactory.GetCapture(captureDevice); var captureProperties = capture.GetCaptureProperties(); Log.Info(m => m("Capture properties: {0}", captureProperties)); SafetyCheckRoi(options, captureProperties); } IRunner runner; Log.Info(options); switch (options.Mode) { case Mode.simple: runner = new SimpleCv(); break; case Mode.colourdetect: var colorDetector = new ColorDetectRunner(capture); if (options.HasColourSettings) { colorDetector.Settings = options.ColourSettings; } runner = colorDetector; break; case Mode.haar: var relativePath = string.Format(@"haarcascades{0}haarcascade_frontalface_default.xml", Path.DirectorySeparatorChar); var cascadeFilename = Path.Combine(appData.ExeFolder, relativePath); var cascadeContent = File.ReadAllText(cascadeFilename); runner = new CascadeRunner(capture, cascadeContent); break; case Mode.servosort: runner = new ServoSorter(capture, options); break; default: throw KrakenException.Create("Option mode {0} needs wiring up", options.Mode); } runner.Run(); }
private void btnStartStop_Click(object sender, EventArgs e) { if (_capture == null) { SetupCapture(); } if (_capture != null) { if (CameraCaptureInProgress) { //stop the capture btnStartStop.Text = "Start Capture"; _capture.Dispose(); _capture = null; } else { btnStartStop.Text = "Stop"; _capture.Start(); toolStripLabelSettings.Text = _capture.GetCaptureProperties().ToString(); } CameraCaptureInProgress = !CameraCaptureInProgress; } }
public NoopRunner(ICaptureGrab capture) : base(capture) { }
private void SetupFramerateTracking(ICaptureGrab capture) { capture.ImageGrabbed += _fpsTracker.NotifyImageGrabbed; _fpsTracker.ReportFrames = s => InvokeUI(() => { toolStripLabelFrames.Text = s; }); }
private void SetupCapture() { if (_capture != null) { _capture.Dispose(); } var request = new CaptureRequest { Device = CaptureDevice.Usb ,CameraIndex = (int) spinEditCameraIndex.Value }; request.Config = HarvestFormCaptureConfig(); if (radFile.Checked) { request.File = _videoFileSource; } //var captureDevice = CaptureDevice.Pi; if (EnvironmentService.IsUnix) { request.Device = CaptureDevice.Pi; } CapturePi.DoMatMagic("CreateCapture"); _capture = CaptureFactory.GetCapture(request); AssignCaptureToConsumers(_capture); SetupFramerateTracking(_capture); tabControlMain_SelectedIndexChanged(null, null); }
public CascadeRunner(ICaptureGrab capture, string casacdeXmlContent) : base(capture) { _detector = new CascadeDetector(casacdeXmlContent); }
public static void SetCaptureProperties(this ICaptureGrab capture, CaptureProperties properties) { capture.SetCaptureProperty(CapProp.FrameHeight, properties.FrameHeight); capture.SetCaptureProperty(CapProp.FrameWidth, properties.FrameWidth); }
static void Main(string[] args) { var appData = ExecutionEnvironment.GetApplicationMetadata(); Log.Info(appData); _consoleOptions = new ConsoleOptions(args); if (_consoleOptions.ShowHelp) { Console.WriteLine("Options:"); _consoleOptions.OptionSet.WriteOptionDescriptions(Console.Out); return; } CapturePi.DoMatMagic("CreateCapture"); var noCaptureGrabs = new[] { Mode.simple, Mode.pantiltjoy, Mode.ipReport }; var i2cRequired = new[] { Mode.pantiltface, Mode.pantiltjoy, Mode.pantiltcolour, Mode.pantiltmultimode }; ICaptureGrab capture = null; if (!noCaptureGrabs.Contains(_consoleOptions.Mode)) { var config = CaptureConfig.Parse(_consoleOptions.CaptureConfig); capture = BuildCaptureGrabber(config); Log.Info($"Requested capture {capture.RequestedConfig}"); } IPanTiltMechanism panTiltMech = null; IScreen screen = null; if (i2cRequired.Contains(_consoleOptions.Mode)) { var pwmDeviceFactory = new Pca9685DeviceFactory(); var pwmDevice = pwmDeviceFactory.GetDevice(_consoleOptions.UseFakeDevice); panTiltMech = new PanTiltMechanism(pwmDevice); screen = new ConsoleScreen(); screen.Clear(); } else { Log.Info("Pan Tilt is not required"); } IRunner runner; Log.Info(_consoleOptions); switch (_consoleOptions.Mode) { case Mode.noop: var noopRunner = new NoopRunner(capture); noopRunner.ReportFramesPerSecond = true; runner = noopRunner; break; case Mode.simple: runner = new SimpleCv(); break; case Mode.colourdetect: var colorDetector = new ColorDetectRunner(capture); if (_consoleOptions.HasColourSettings) { colorDetector.Settings = _consoleOptions.ColourSettings; } runner = colorDetector; break; case Mode.haar: var relativePath = $@"haarcascades{Path.DirectorySeparatorChar}haarcascade_frontalface_default.xml"; var cascadeFilename = Path.Combine(appData.ExeFolder, relativePath); var cascadeContent = File.ReadAllText(cascadeFilename); runner = new CascadeRunner(capture, cascadeContent); break; case Mode.servosort: runner = new ServoSorter(capture, _consoleOptions); break; case Mode.pantiltjoy: var joyController = new JoystickPanTiltController(panTiltMech); runner = new TimerRunner(joyController, screen); break; case Mode.pantiltface: var controllerF = new FaceTrackingPanTiltController(panTiltMech, capture.RequestedConfig); runner = new CameraBasedPanTiltRunner(panTiltMech, capture, controllerF, screen); break; case Mode.pantiltmultimode: var cameraHubProxy = new CameraHubProxy(); cameraHubProxy.Connect(); var remoteScreen = new RemoteConsoleScreen(cameraHubProxy); var piServerClient = new BsonPostImageTransmitter(); var imageTransmitter = new RemoteImageSender(piServerClient, cameraHubProxy); cameraHubProxy.SettingsChanged += (sender, s) => { remoteScreen.Enabled = s.EnableConsoleTransmit; imageTransmitter.Enabled = s.EnableImageTransmit; }; var controllerMultimode = new MultimodePanTiltController(panTiltMech, capture.RequestedConfig, remoteScreen, cameraHubProxy, imageTransmitter); var cameraBasedRunner = new CameraBasedPanTiltRunner(panTiltMech, capture, controllerMultimode, screen); runner = cameraBasedRunner; cameraHubProxy.UpdateCapture += (s, e) => { remoteScreen.WriteLine($"Changing capture settings to {e}"); var newGrabber = BuildCaptureGrabber(e); cameraBasedRunner.UpdateCaptureGrabber(newGrabber); }; break; case Mode.pantiltcolour: var controllerC = new ColourTrackingPanTiltController(panTiltMech, capture.RequestedConfig); if (_consoleOptions.HasColourSettings) { controllerC.Settings = _consoleOptions.ColourSettings; } else { throw KrakenException.Create("Colour settings not found"); } runner = new CameraBasedPanTiltRunner(panTiltMech, capture, controllerC, screen); break; case Mode.ipReport: var hub = new CameraHubProxy(); runner = new IpReporter(hub); break; default: throw KrakenException.Create("Option mode {0} needs wiring up", _consoleOptions.Mode); } runner.Run(); }
private void SetupFramerateTracking(ICaptureGrab capture) { capture.ImageGrabbed += _fpsTracker.NotifyImageGrabbed; _fpsTracker.ReportFrames = s => Invoke((MethodInvoker) delegate { labelFrameRate.Text = s; }); }