/// <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(); }
private void btnReadSettings_Click(object sender, EventArgs e) { if (_colorSettingsRepo.IsPresent) { _detectorInput.Settings = _colorSettingsRepo.Read(); UpdateMomentSlidersFromSettings(); UpdateThresholdSlidersFromSettings(); NotifyStatus("Read settings from repository"); } else { Log.Info("Settings not found"); } }
protected override CameraPanTiltProcessOutput DoProcess(CameraProcessInput input) { var output = new CameraPanTiltProcessOutput(); ProcessingMode nextState = State; switch (State) { case ProcessingMode.Static: var staticHackOutput = new StaticTrackingPanTiltOutput(); nextState = _staticManager.AcceptOutput(staticHackOutput); break; case ProcessingMode.ColourTrackFromFileSettings: _colourDetectorInput.Settings = _colourSettingsRepository.Read(); _screen.WriteLine($"Read colour settings {_colourDetectorInput.Settings}"); nextState = ProcessingMode.ColourObjectTrack; break; case ProcessingMode.ColourObjectTrack: var colourOutput = ProcessColour(input); output = colourOutput; if (Ticks % (90 * 3) == 0) // provide some feedback on moment size but don't spam { _screen.WriteLine("colTrack:" + colourOutput); } nextState = _colourTrackManager.AcceptOutput(colourOutput); break; case ProcessingMode.FaceDetection: var faceTrackOutput = _faceTrackingController.Process(input); nextState = _faceTrackManager.AcceptOutput(faceTrackOutput); output = faceTrackOutput; break; //case ProcessingMode.CamshiftTrack: // var camshiftOutput = _camshiftTrackingController.Process(input); // if (camshiftOutput.Target == Point.Empty) // { // SetMode(ProcessingMode.Autonomous); // } // output = camshiftOutput; // break; case ProcessingMode.ColourObjectSelect: _screen.WriteLine($"Threshold training for {_thresholdSelector.RequiredMomentAreaInRoiPercent}% ROI coverage"); var thresholdSettings = _thresholdSelector.Select(input.Captured, _regionOfInterest); _screen.WriteLine($"Threshold tuning complete: {thresholdSettings}"); _colourDetectorInput.SetCapturedImage = true; _colourDetectorInput.Settings.MomentArea = new RangeF(50, 10000); _colourDetectorInput.Settings.Accept(thresholdSettings); //_isColourTrained = true; nextState = ProcessingMode.ColourObjectTrack; break; case ProcessingMode.Autonomous: nextState = _autonomousManager.AcceptInput(input); if (nextState == ProcessingMode.ColourObjectTrack) { } break; case ProcessingMode.CamshiftSelect: throw new NotImplementedException(); } if (output.CapturedImage == null) { output.CapturedImage = input.Captured.ToImage <Bgr, byte>(); } ProcessOutputPipeline(output); if (_forcedNextState != ProcessingMode.Unknown) { nextState = _forcedNextState; _forcedNextState = ProcessingMode.Unknown; } if (nextState != State) { _screen.WriteLine($"Changing {State} to {nextState}"); switch (nextState) { case ProcessingMode.Static: _staticManager.Reset(); break; case ProcessingMode.Autonomous: if (State == ProcessingMode.FaceDetection) // coming out of face detection { SoundService.PlayAsync("cant-see-you.wav"); } MoveAbsolute(50, 60); _autonomousManager.Reset(); // Reset the timers break; case ProcessingMode.ColourObjectTrack: _colourTrackManager.Reset(); _screen.WriteLine($"Color detector settings: {_colourDetectorInput.Settings}"); SoundService.PlayAsync("color-tracking.wav"); break; case ProcessingMode.FaceDetection: _faceTrackManager.Reset(); SoundService.PlayAsync("face-tracking.wav"); _screen.WriteLine(ClassifierParams.ToString()); break; } State = nextState; } return(output); }
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); }