示例#1
0
 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);
 }
示例#2
0
        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;
        }
示例#3
0
 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;
     }
 }
示例#4
0
 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;
     }
 }
示例#5
0
        /*
         *
         * 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);
        }
示例#6
0
        /// <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();
            }
        }
示例#7
0
        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
        }
示例#8
0
        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;
        }
示例#10
0
        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();
        }
示例#11
0
        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();
        }
示例#13
0
 public ColorDetectRunner(ICaptureGrab capture, ColourDetectSettings settings)
     : base(capture)
 {
     Settings = settings;
 }
示例#14
0
        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();
        }
示例#15
0
        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;
            }
        }
示例#16
0
 public NoopRunner(ICaptureGrab capture) : base(capture)
 {
 }
示例#17
0
 private void SetupFramerateTracking(ICaptureGrab capture)
 {
     capture.ImageGrabbed += _fpsTracker.NotifyImageGrabbed;
     _fpsTracker.ReportFrames = s => InvokeUI(() => { toolStripLabelFrames.Text = s; });
 }
示例#18
0
 public ColorDetectRunner(ICaptureGrab capture, ColourDetectSettings settings)
     : base(capture)
 {
     Settings = 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();
            }
        }
示例#20
0
        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);
        }
示例#21
0
 public CascadeRunner(ICaptureGrab capture, string casacdeXmlContent)
     : base(capture)
 {
     _detector = new CascadeDetector(casacdeXmlContent);
 }
示例#22
0
 public NoopRunner(ICaptureGrab capture)
     : base(capture)
 {
 }
示例#23
0
 public static void SetCaptureProperties(this ICaptureGrab capture, CaptureProperties properties)
 {
     capture.SetCaptureProperty(CapProp.FrameHeight, properties.FrameHeight);
     capture.SetCaptureProperty(CapProp.FrameWidth, properties.FrameWidth);
 }
示例#24
0
        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();
        }
示例#25
0
 private void SetupFramerateTracking(ICaptureGrab capture)
 {
     capture.ImageGrabbed    += _fpsTracker.NotifyImageGrabbed;
     _fpsTracker.ReportFrames = s => Invoke((MethodInvoker) delegate { labelFrameRate.Text = s; });
 }
示例#26
0
 private void SetupFramerateTracking(ICaptureGrab capture)
 {
     capture.ImageGrabbed    += _fpsTracker.NotifyImageGrabbed;
     _fpsTracker.ReportFrames = s => InvokeUI(() => { toolStripLabelFrames.Text = s; });
 }
示例#27
0
 public CascadeRunner(ICaptureGrab capture, string casacdeXmlContent)
     : base(capture)
 {
     _detector = new CascadeDetector(casacdeXmlContent);
 }