/// <summary>
        /// sudo mono picamcv.con.exe -m=pantiltmultimode
        /// </summary>
        public MultimodePanTiltController(
            IPanTiltMechanism panTiltMech
            , CaptureConfig captureConfig
            , IScreen screen
            , IServerToCameraBus serverToCameraBus
            , params IOutputProcessor[] outputPipelines) : base(panTiltMech, captureConfig)
        {
            _screen            = screen;
            _serverToCameraBus = serverToCameraBus;
            _outputPipelines   = outputPipelines;

            _faceTrackingController     = new FaceTrackingPanTiltController(panTiltMech, captureConfig);
            _camshiftTrackingController = new CamshiftPanTiltController(panTiltMech, captureConfig);
            _colourTrackingController   = new ColourTrackingPanTiltController(panTiltMech, captureConfig);

            _thresholdSelector = new ThresholdSelector();
            _thresholdSelector.ColourCheckTick += thresholdSelector_ColourCheckTick;

            _colourDetectorInput = new ColourDetectorInput();
            _colourDetectorInput.SetCapturedImage    = true;
            _colourDetectorInput.Settings.MomentArea = new RangeF(50, 10000);

            _faceTrackManager   = new FaceTrackStateManager(screen);
            _colourTrackManager = new ColourTrackStateManager(screen);
            _autonomousManager  = new AutonomousTrackStateManager(this, screen);

            screen.Clear();
            SetMode(ProcessingMode.Autonomous);

            _autonomousManager.IsFaceFound       = i => _faceTrackingController.Process(i).IsDetected;
            _autonomousManager.IsColourFullFrame = IsColourFullFrame;

            InitController();
        }
        /// <summary>
        /// sudo mono picamcv.con.exe -m=pantiltmultimode
        /// </summary>
        public MultimodePanTiltController(
            IPanTiltMechanism panTiltMech
            , CaptureConfig captureConfig
            , IScreen screen
            , IServerToCameraBus serverToCameraBus
            , params IOutputProcessor[] outputPipelines) : base(panTiltMech, captureConfig)
        {
            _screen            = screen;
            _serverToCameraBus = serverToCameraBus;
            _outputPipelines   = outputPipelines;

            _colourSettingsRepository = new ColourSettingsRepository();

            _faceTrackingController     = new FaceTrackingPanTiltController(panTiltMech, captureConfig);
            _camshiftTrackingController = new CamshiftPanTiltController(panTiltMech, captureConfig);
            _colourTrackingController   = new ColourTrackingPanTiltController(panTiltMech, captureConfig);

            _thresholdSelector = new ThresholdSelector();
            _thresholdSelector.ColourCheckTick += thresholdSelector_ColourCheckTick;

            _colourDetectorInput = new ColourDetectorInput();
            _colourDetectorInput.SetCapturedImage = true;
            var repoSettings = _colourSettingsRepository.Read();

            if (repoSettings != null)
            {
                _colourDetectorInput.Settings = repoSettings;
            }

            _faceTrackManager   = new FaceTrackStateManager(screen);
            _colourTrackManager = new ColourTrackStateManager(screen);
            _staticManager      = new StaticStateManager(screen);
            _autonomousManager  = new AutonomousTrackStateManager(this, screen);

            SoundService = new SoundService();


            screen.Clear();
            ChangeMode(ProcessingMode.Autonomous);

            _autonomousManager.IsFaceFound       = i => _faceTrackingController.Process(i).IsDetected;
            _autonomousManager.IsColourFullFrame = IsColourFullFrame;

            _faceTrackingController.ClassifierParams.MinSize = new Size(20, 20);
            _faceTrackingController.ClassifierParams.MaxSize = new Size(50, 50);

            screen.WriteLine(_faceTrackingController.ClassifierParams.ToString());

            InitController();

            ServoSettleTimeChanged += (s, e) =>
            {
                _faceTrackingController.ServoSettleTime   = ServoSettleTime;
                _colourTrackingController.ServoSettleTime = ServoSettleTime;
            };

            _colourDetector = new ColourDetector();
        }
Пример #3
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;

            CapturePi.DoMatMagic("CreateCapture");

            var noCaptureGrabs = new[] { Mode.simple, Mode.pantiltjoy };
            var i2cRequired = new[] { Mode.pantiltface, Mode.pantiltjoy ,Mode.pantiltcolour };
            CaptureConfig captureConfig = null;
            if (!noCaptureGrabs.Contains(options.Mode))
            {
                var request = new CaptureRequest { Device = CaptureDevice.Usb };
                if (EnvironmentService.IsUnix)
                {
                    request.Device = CaptureDevice.Pi;
                }

                request.Config = new CaptureConfig { Resolution = new Resolution(160,120), Framerate = 10, Monochrome = false };

                capture = CaptureFactory.GetCapture(request);
                captureConfig = capture.GetCaptureProperties();
                Log.Info(m => m("Capture properties read: {0}", captureConfig));

                SafetyCheckRoi(options, captureConfig);
            }

            IPanTiltMechanism panTiltMech = null;
            IScreen screen = null;
            if (i2cRequired.Contains(options.Mode))
            {
                var pwmDeviceFactory = new Pca9685DeviceFactory();
                var pwmDevice = pwmDeviceFactory.GetDevice(options.UseFakeDevice);
                panTiltMech = new PanTiltMechanism(pwmDevice);
                screen = new ConsoleScreen();
                screen.Clear();
            }

            IRunner runner;
            Log.Info(options);
            switch (options.Mode)
            {
                case Mode.noop: runner = new NoopRunner(capture);
                    break;

                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;

                case Mode.pantiltjoy:
                    var joyController = new JoystickPanTiltController(panTiltMech);
                    runner = new TimerRunner(joyController, screen);
                    break;

                case Mode.pantiltface:
                    var controllerF = new FaceTrackingPanTiltController(panTiltMech, captureConfig);
                    runner = new CameraBasedPanTiltRunner(panTiltMech, capture, controllerF, screen);
                    break;

                case Mode.pantiltcolour:
                    var controllerC = new ColourTrackingPanTiltController(panTiltMech, captureConfig);
                    if (options.HasColourSettings)
                    {
                        controllerC.Settings = options.ColourSettings;
                    }
                    else
                    {
                        throw KrakenException.Create("Colour settings not found");
                    }
                    runner = new CameraBasedPanTiltRunner(panTiltMech, capture, controllerC, screen);
                    break;

                default:
                    throw KrakenException.Create("Option mode {0} needs wiring up", options.Mode);
            }

            runner.Run();
        }
Пример #4
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();
        }
Пример #5
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();
                    if (!_consoleOptions.DisableTransmit)
                    {
                        cameraHubProxy.Connect();
                    }
                    var remoteScreen = new RemoteConsoleScreen(cameraHubProxy);
                    //var imageTransmitter = new BsonPostImageTransmitter();
                    var imageTransmitter = new BsonPostJpegTransmitter();
                    var periodicImageSender = new RemoteImageSender(imageTransmitter, cameraHubProxy);

                    remoteScreen.Enabled = !_consoleOptions.DisableTransmit;
                    periodicImageSender.Enabled = !_consoleOptions.DisableTransmit;

                    cameraHubProxy.SettingsChanged += (sender, s) =>
                    {
                        remoteScreen.Enabled = s.EnableConsoleTransmit;
                        periodicImageSender.Enabled = s.EnableImageTransmit;
                    };

                    var controllerMultimode = new MultimodePanTiltController(
                                                    panTiltMech
                                                    , capture.RequestedConfig
                                                    , remoteScreen
                                                    , cameraHubProxy
                                                    , periodicImageSender);

                    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();
        }
Пример #6
0
        protected override void OnSubscribe()
        {
            base.OnSubscribe();

            _captureConfig = CameraCapture.GetCaptureProperties();
            _centre = _captureConfig.Resolution.GetCenter();

            txtReticleX.Text = _centre.X.ToString();
            txtReticleY.Text = _centre.Y.ToString();

            var screen = new TextboxScreen(txtScreen);

            //var imageTransmitter = new BsonPostImageTransmitter();
            var imageTransmitter = new BsonPostJpegTransmitter();
            var colorSettings = _colourSettingsRepo.Read();
            var motionSettings = _motionSettingsRepo.Read();

            // these should be disposed if not null

            _faceTrackingController = new FaceTrackingPanTiltController(PanTiltMechanism, _captureConfig);
            _colourTrackingController = new ColourTrackingPanTiltController(PanTiltMechanism, _captureConfig);
            _motionTrackingController = new MotionTrackingPanTiltController(PanTiltMechanism, _captureConfig, screen);

            // if haven't subscribed first time yet
            if (_multimodePanTiltController == null)
            {
                _remoteScreen = new RemoteTextboxScreen(CameraHubProxy, txtScreen);
                _remoteImageSender = new RemoteImageSender(imageTransmitter, CameraHubProxy);

                CameraHubProxy.SettingsChanged += (o, s) =>
                {
                    _remoteScreen.WriteLine($"Camera received new settings: {s}");
                    _remoteImageSender.SendEveryPeriod = s.TransmitImagePeriod;
                    _remoteImageSender.Enabled = s.EnableImageTransmit;
                    _remoteScreen.Enabled = s.EnableConsoleTransmit;
                };
            }
            else
            {
                // don't resubscribe and get duplicate events on cameraHubProxy
                _multimodePanTiltController.Unsubscribe();
            }

            _multimodePanTiltController = new MultimodePanTiltController(
                PanTiltMechanism
                , _captureConfig
                , _remoteScreen
                , CameraHubProxy
                , _remoteImageSender);

            _calibratingPanTiltController = new CalibratingPanTiltController(PanTiltMechanism, new CalibrationReadingsRepository(), screen);
            _colourTrackingController.Settings = colorSettings;
            _calibratingPanTiltController.Settings = colorSettings;
            _motionTrackingController.Settings = motionSettings;

            _calibratingPanTiltController.GetCameraCapture = PullImage;
            _calibratingPanTiltController.WaitStep = CalibrationWaitStep;
            _calibratingPanTiltController.ColourCaptured += _calibratingPanTiltController_ColourCaptured;

            // default check states
            chkBoxColourTracking.Checked = false;
            chkBoxFaceTracker.Checked = false;
            chkBoxMotionTracking.Checked = false;
            chkMultimode.Checked = false;

            Log.InfoFormat("MotionSettings: {0}", motionSettings);
        }
Пример #7
0
        protected override void OnSubscribe()
        {
            _captureConfig = CameraCapture.GetCaptureProperties();
            _centre = _captureConfig.Resolution.GetCenter();

            txtReticleX.Text = _centre.X.ToString();
            txtReticleY.Text = _centre.Y.ToString();

            InitI2C();

            var screen = new TextboxScreen(txtScreen);

            var colorSettings = _colourSettingsRepo.Read();
            var motionSettings = _motionSettingsRepo.Read();

            // these should be disposed if not null

            _faceTrackingController = new FaceTrackingPanTiltController(PanTiltMechanism, _captureConfig);
            _colourTrackingController = new ColourTrackingPanTiltController(PanTiltMechanism, _captureConfig);
            _motionTrackingController = new MotionTrackingPanTiltController(PanTiltMechanism, _captureConfig, screen);

            _calibratingPanTiltController = new CalibratingPanTiltController(PanTiltMechanism, new CalibrationReadingsRepository(), screen);
            _colourTrackingController.Settings = colorSettings;
            _calibratingPanTiltController.Settings = colorSettings;
            _motionTrackingController.Settings = motionSettings;

            _calibratingPanTiltController.GetCameraCapture = PullImage;
            _calibratingPanTiltController.WaitStep = CalibrationWaitStep;
            _calibratingPanTiltController.ColourCaptured += _calibratingPanTiltController_ColourCaptured;

            Log.InfoFormat("MotionSettings: {0}", motionSettings);
        }
Пример #8
0
        protected override void OnSubscribe()
        {
            base.OnSubscribe();

            _captureConfig = CameraCapture.GetCaptureProperties();
            _centre        = _captureConfig.Resolution.GetCenter();

            txtReticleX.Text = _centre.X.ToString();
            txtReticleY.Text = _centre.Y.ToString();

            var screen = new TextboxScreen(txtScreen);

            //var imageTransmitter = new BsonPostImageTransmitter();
            var imageTransmitter = new BsonPostJpegTransmitter();
            var colorSettings    = _colourSettingsRepo.Read();
            var motionSettings   = _motionSettingsRepo.Read();

            // these should be disposed if not null

            _faceTrackingController   = new FaceTrackingPanTiltController(PanTiltMechanism, _captureConfig);
            _colourTrackingController = new ColourTrackingPanTiltController(PanTiltMechanism, _captureConfig);
            _motionTrackingController = new MotionTrackingPanTiltController(PanTiltMechanism, _captureConfig, screen);

            // if haven't subscribed first time yet
            if (_multimodePanTiltController == null)
            {
                _remoteScreen      = new RemoteTextboxScreen(CameraHubProxy, txtScreen);
                _remoteImageSender = new RemoteImageSender(imageTransmitter, CameraHubProxy);

                CameraHubProxy.SettingsChanged += (o, s) =>
                {
                    _remoteScreen.WriteLine($"Camera received new settings: {s}");
                    _remoteImageSender.SendEveryPeriod = s.TransmitImagePeriod;
                    _remoteImageSender.Enabled         = s.EnableImageTransmit;
                    _remoteScreen.Enabled = s.EnableConsoleTransmit;
                };
            }
            else
            {
                // don't resubscribe and get duplicate events on cameraHubProxy
                _multimodePanTiltController.Unsubscribe();
            }

            _multimodePanTiltController = new MultimodePanTiltController(
                PanTiltMechanism
                , _captureConfig
                , _remoteScreen
                , CameraHubProxy
                , _remoteImageSender);


            _calibratingPanTiltController          = new CalibratingPanTiltController(PanTiltMechanism, new CalibrationReadingsRepository(), screen);
            _colourTrackingController.Settings     = colorSettings;
            _calibratingPanTiltController.Settings = colorSettings;
            _motionTrackingController.Settings     = motionSettings;

            _calibratingPanTiltController.GetCameraCapture = PullImage;
            _calibratingPanTiltController.WaitStep         = CalibrationWaitStep;
            _calibratingPanTiltController.ColourCaptured  += _calibratingPanTiltController_ColourCaptured;

            // default check states
            chkBoxColourTracking.Checked = false;
            chkBoxFaceTracker.Checked    = false;
            chkBoxMotionTracking.Checked = false;
            chkMultimode.Checked         = false;

            Log.InfoFormat("MotionSettings: {0}", motionSettings);
        }